Skip to content

Instantly share code, notes, and snippets.

View azarboon's full-sized avatar

Mahdi Azarboon azarboon

View GitHub Profile
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::your-bucket/*"
],
"Action": [
"s3:PutObject"
# Do not change version. This is the version of aws buildspec, not the version of your buldspec file.
version: 0.2
phases:
install:
commands:
- npm install -g yarn
- yarn
build:
commands:
{
"Statement": [
{
"Action": [
"apigateway:*",
"codedeploy:*",
"lambda:*",
"cloudformation:CreateChangeSet",
"iam:GetRole",
"iam:CreateRole",
#to install npm dependencies
yarn
aws cloudformation package --template-file template.yaml --output-template-file cf-
output.yaml --s3-bucket your-s3-bucket
aws cloudformation deploy --template-file cf-template.yaml --stack-name lambda-unit-test --capabilities CAPABILITY_IAM
'use strict';
const AWS_MOCK = require('aws-sdk-mock');
const AWS = require('aws-sdk');
const test = require('ava');
AWS_MOCK.setSDKInstance(AWS);
const App = require('../../app.js');
let event, context;
const AWS = require('aws-sdk');
const test = require('ava');
const sinon = require('sinon');
const App = require('../../app.js');
const lib = require('../../lib.js');
const dynamoDb = new AWS.DynamoDB.DocumentClient();
const sandbox = sinon.createSandbox();
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Lambda unit testing
Globals:
Function:
Timeout: 30
Runtime: nodejs8.10
Environment:
Variables:
function responseFactory(code, message) {
return {
'statusCode': code,
'body': JSON.stringify({
message: message
})
}
}
module.exports.responseFactory = responseFactory;
const AWS = require('aws-sdk');
const App = require('./app.js');
const dynamoDb = new AWS.DynamoDB.DocumentClient({
apiVersion: '2012-08-10'
});
const app = new App(dynamoDb);
@azarboon
azarboon / app.js
Created July 6, 2019 08:25
Figure 2: App.js contains the business logic. It gets invoked by handler and returns the result back
const AWS = require('aws-sdk')
const lib = require('./lib.js');
const responseFactory = lib.responseFactory;
const TABLE = (process.env.NODE_ENV === 'test') ? 'devopssec-table' : process.env.MY_TABLE;
AWS.config.update({
region: 'eu-central-1'
});
class App {