This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Resource": [ | |
"arn:aws:s3:::your-bucket/*" | |
], | |
"Action": [ | |
"s3:PutObject" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Statement": [ | |
{ | |
"Action": [ | |
"apigateway:*", | |
"codedeploy:*", | |
"lambda:*", | |
"cloudformation:CreateChangeSet", | |
"iam:GetRole", | |
"iam:CreateRole", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: AWS::Serverless-2016-10-31 | |
Description: Lambda unit testing | |
Globals: | |
Function: | |
Timeout: 30 | |
Runtime: nodejs8.10 | |
Environment: | |
Variables: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function responseFactory(code, message) { | |
return { | |
'statusCode': code, | |
'body': JSON.stringify({ | |
message: message | |
}) | |
} | |
} | |
module.exports.responseFactory = responseFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |