Workshop
https://github.com/jpizarrom/event-driven-code-with-nodejs-aws-lambda-workshop
@jpizarrom
deploy
cd collector/download_detail && npm install && cd ../..
./node_modules/.bin/serverless function deploy collector-download_detail
run
./node_modules/.bin/serverless function run collector-download_detail
events
./node_modules/.bin/serverless event deploy
{
"name": "collector-download_detail",
"runtime": "nodejs",
"description": "Serverless Lambda function for project: serverless-mp",
"customName": false,
"customRole": false,
"handler": "handler.handler",
"timeout": 120,
"memorySize": 128,
"authorizer": {},
"custom": {
"excludePatterns": []
},
"endpoints": [],
"events": [
{
"name": "detailsTable",
"type": "kinesisStream",
"config": {
"streamArn": "${detailStreamARN}",
"startingPosition": "LATEST",
"batchSize": 1,
"enabled": true
}
}
],
"environment": {
"SERVERLESS_PROJECT": "${project}",
"SERVERLESS_STAGE": "${stage}",
"SERVERLESS_REGION": "${region}",
"DETAILS_TABLE": "$${detailsTable}",
"MERCADOPUBLICO_TICKET": "${mercadopublicoTicket}"
},
"vpc": {
"securityGroupIds": [],
"subnetIds": []
}
}
var dynamodb = new AWS.DynamoDB();
Promise.promisifyAll(Object.getPrototypeOf(dynamodb));
var validateInput = function(data) {
return new Promise(function(resolve, reject) {
resolve(data);
});
}
var createList = function(data) {
return new Promise(function(resolve, reject) {
var user = {
id: data.code,
created: moment().unix().toString(),
updated: moment().unix().toString(),
info: data.info,
}
resolve(user);
});
}
var storeList = function(user) {
debug('Saving ' + JSON.stringify(user));
return dynamodb.putItemAsync({
TableName: process.env.DETAILS_TABLE,
Item: {
id: { S: user.id },
created: { S: user.created },
updated: { S: user.updated },
info: { S: user.info },
},
// ConditionExpression: 'attribute_not_exists (id)'
});
}
build:
ci:
- npm install serverless@0.5.2
on_success:
- |
cat << EOF > admin.env
SERVERLESS_ADMIN_AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
SERVERLESS_ADMIN_AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
EOF
- cat admin.env
- mkdir .aws
- touch .aws/credentials
- mkdir -p _meta/variables/
- |
cat << EOF > _meta/variables/s-variables-common_.json
{
"project": "$PROJECT"
}
EOF
- |
cat << EOF > _meta/variables/s-variables-$BRANCH.json
{
"stage": "$BRANCH"
}
EOF
- |
cat << EOF > _meta/variables/s-variables-$BRANCH-`echo $AWS_DEFAULT_REGION | sed -e 's/-//g'`.json
{
"region": "$AWS_DEFAULT_REGION",
"resourcesStackName": "$RESOURCES_STACK_NAME",
"iamRoleArnLambda": "$IAM_ROLE_ARN_LAMBDA"
}
EOF
- cd collector/download_list && npm install && cd ../..
- HOME=$PWD ./node_modules/.bin/serverless function deploy collector-download_list -s $BRANCH -r $AWS_DEFAULT_REGION --debug
- cd collector/download_detail && npm install && cd ../..
- HOME=$PWD ./node_modules/.bin/serverless function deploy collector-download_detail -s $BRANCH -r $AWS_DEFAULT_REGION --debug
- cd collector/list_stream_processor && npm install && cd ../..
- HOME=$PWD ./node_modules/.bin/serverless function deploy collector-list_stream_processor -s $BRANCH -r $AWS_DEFAULT_REGION --debug
- cd detector/detector && npm install && cd ../..
- HOME=$PWD ./node_modules/.bin/serverless function deploy detector-detector -s $BRANCH -r $AWS_DEFAULT_REGION --debug
- cd detector/detail_stream_processor && npm install && cd ../..
- HOME=$PWD ./node_modules/.bin/serverless function deploy detector-detail_stream_processor -s $BRANCH -r $AWS_DEFAULT_REGION --debug
- cd notificator/notificator && npm install && cd ../..
- HOME=$PWD ./node_modules/.bin/serverless function deploy notificator-notificator -s $BRANCH -r $AWS_DEFAULT_REGION --debug
- cd elastic/elastic && npm install && cd ../..
- HOME=$PWD ./node_modules/.bin/serverless function deploy elastic-elastic -s $BRANCH -r $AWS_DEFAULT_REGION --debug