├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── javascript ├── alexa-skills-kit-color-expert │ ├── index.js │ ├── package.json │ ├── question.js │ ├── template.yaml │ └── testEvent.json ├── alexa-smart-home-skill-adapter │ ├── index.js │ ├── package.json │ ├── recipes.js │ ├── template.yaml │ └── testEvent.json ├── algorithmia │ ├── index.js │ ├── package.json │ └── template.yaml ├── api-gateway-authorizer-nodejs │ ├── index.js │ ├── package.json │ ├── template.yaml │ └── testEvent.json ├── api-gateway-multiple-origin-cors │ ├── README.md │ ├── cors-config.json │ ├── cors-util.js │ ├── cors-util.test.js │ ├── package-lock.json │ ├── package.json │ ├── routes │ │ ├── root.js │ │ └── test.js │ ├── template.yaml │ └── testEvent.json ├── cfn-look-up-ami-ids │ ├── index.js │ ├── package.json │ ├── template.yaml │ └── testEvent.json ├── cfn-stack-outputs │ ├── index.js │ ├── package.json │ ├── template.yaml │ └── testEvent.json ├── cloudfront-ab-test │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── cloudfront-access-request-in-response │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── cloudfront-http-redirect │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── cloudfront-modify-querystring │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── cloudfront-modify-response-header │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── cloudfront-multiple-remote-calls-aggregate-response │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── cloudfront-redirect-on-viewer-country │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── cloudfront-redirect-unauthenticated-users │ ├── index.js │ ├── package.json │ ├── template.yaml │ └── testEvent.json ├── cloudfront-response-generation │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── cloudfront-simple-remote-call │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── cloudwatch-alarm-to-slack │ ├── index.js │ ├── package.json │ └── template.yaml ├── cloudwatch-logs-process-data │ ├── index.js │ ├── package.json │ ├── template.yaml │ └── testEvent.json ├── cloudwatch-logs-to-loggly │ ├── index.js │ ├── package.json │ └── template.yaml ├── cognito-sync-trigger │ ├── index.js │ ├── package.json │ ├── template.yaml │ └── testEvent.json ├── config-rule-change-triggered │ ├── index.js │ └── template.yaml ├── config-rule-periodic │ ├── index.js │ └── template.yaml ├── dynamodb-process-stream │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── hello-world │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── https-request │ ├── index.js │ ├── license.txt │ ├── readme │ └── template.yaml ├── image-processing-service │ ├── index.js │ ├── license.txt │ ├── readme │ └── template.yaml ├── inbound-ses-spam-filter │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── inspector-scheduled-run │ ├── index.js │ ├── license.txt │ ├── readme │ └── template.yaml ├── kinesis-analytics-process-compressed-record │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── kinesis-analytics-process-record │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── kinesis-firehose-apachelog-to-csv │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── kinesis-firehose-apachelog-to-json │ ├── index.js │ ├── license.txt │ ├── template.yaml │ └── testEvent.json ├── kinesis-firehose-cloudwatch-logs-processor │ ├── index.js │ ├── lib │ │ └── mysplunklogger.js │ ├── template.yaml │ └── testEvent.json ├── kinesis-firehose-process-record-streams-as-source │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── kinesis-firehose-process-record │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── kinesis-firehose-syslog-to-csv │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── kinesis-firehose-syslog-to-json │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── kinesis-process-record │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── lambda-test-harness │ ├── index.js │ ├── license.txt │ ├── readme │ └── template.yaml ├── lex-book-trip │ ├── index.js │ ├── license.txt │ ├── readme │ ├── requirements.txt │ ├── template.yaml │ └── testEvent.json ├── lex-make-appointment │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── lex-order-flowers │ ├── index.js │ ├── license.txt │ ├── readme │ ├── template.yaml │ └── testEvent.json ├── microservice-http-endpoint │ ├── index.js │ ├── package.json │ └── template.yaml ├── node-exec │ ├── index.js │ ├── response │ │ └── detect-faces-response.json │ ├── template.yaml │ └── testEvent.json ├── s3-get-object │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── ses-notification-nodejs │ ├── index.js │ └── template.yaml ├── simple-mobile-backend │ ├── index.js │ └── template.yaml ├── slack-echo-command │ ├── index.js │ └── template.yaml ├── sns-message │ ├── index.js │ ├── template.yaml │ └── testEvent.json ├── sqs-poller │ ├── index.js │ └── template.yaml ├── step-functions-error │ ├── index.js │ └── template.yaml ├── sumologic-process-logs │ ├── index.js │ └── template.yaml ├── twilio-conference │ ├── index.js │ └── template.yaml ├── twilio-forward │ ├── index.js │ └── template.yaml ├── twilio-menu │ ├── index.js │ └── template.yaml └── twilio-simple-blueprint │ ├── index.js │ └── template.yaml └── python ├── alexa-skills-kit-color-expert-python ├── lambda_function.py ├── package.json ├── template.yaml └── testEvent.json ├── api-gateway-authorizer-python ├── lambda_function.py └── template.yaml ├── cloudwatch-alarm-to-slack-python ├── lambda_function.py ├── package.json └── template.yaml ├── cloudwatch-alarm-to-slack-python3 ├── lambda_function.py ├── package.json └── template.yaml ├── datadog-process-rds-metrics ├── lambda_function.py └── template.yaml ├── dynamodb-process-stream-python ├── lambda_function.py └── template.yaml ├── dynamodb-process-stream-python3 ├── lambda_function.py ├── template.yaml └── testEvent.json ├── hello-world-python ├── lambda_function.py ├── license.txt ├── readme └── template.yaml ├── hello-world-python3 ├── lambda_function.py ├── license.txt ├── readme └── template.yaml ├── inbound-ses-spam-filter-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── kinesis-analytics-process-kpl-record ├── aws_kinesis_agg │ ├── __init__.py │ ├── deaggregator.py │ └── kpl_pb2.py ├── lambda_function.py ├── requirements.txt └── template.yaml ├── kinesis-analytics-process-record-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── kinesis-firehose-apachelog-to-csv-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── kinesis-firehose-apachelog-to-json-python ├── lambda_function.py ├── license.txt ├── requirements.txt └── template.yaml ├── kinesis-firehose-process-record-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── kinesis-firehose-process-record-streams-as-source-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── kinesis-firehose-syslog-to-csv-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── kinesis-firehose-syslog-to-json-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── kinesis-process-record-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── lambda-canary-python3 ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── lambda-canary ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── lex-book-trip-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── lex-make-appointment-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── lex-order-flowers-python ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── logicmonitor-send-cloudwatch-events ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── logicmonitor-send-eventbridge-events ├── lambda_function.py ├── license.txt ├── readme ├── requirements.txt └── template.yaml ├── microservice-http-endpoint-python ├── lambda_function.py └── template.yaml ├── microservice-http-endpoint-python3 ├── lambda_function.py ├── template.yaml ├── test-output.log ├── test-payload.json └── test.sh ├── rekognition-python ├── lambda_function.py ├── response │ └── detect-faces-response.json └── template.yaml ├── s3-get-object-python ├── lambda_function.py └── template.yaml ├── s3-get-object-python3 ├── lambda_function.py └── template.yaml ├── ses-notification-python ├── lambda_function.py └── template.yaml ├── slack-echo-command-python ├── lambda_function.py └── template.yaml ├── sns-message-python ├── lambda_function.py └── template.yaml ├── step-functions-error-python ├── lambda_function.py └── template.yaml ├── step-functions-send-to-sns ├── lambda_function.py └── template.yaml └── vpn-conn-monitor ├── monitor_vpn_lambda.py └── template.yaml /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## AWS Serverless Application Repository Examples 2 | 3 | This project provides source code of example applications for people to get started using AWS Serverless Application Repository. 4 | 5 | ## License 6 | 7 | This project is licensed under the Apache-2.0 License. 8 | 9 | -------------------------------------------------------------------------------- /javascript/alexa-skills-kit-color-expert/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alexa-skill-kit-sdk-triviaskill", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "alexa-sdk": "^1.0.10" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/alexa-skills-kit-color-expert/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Demonstrates a basic skill built with the Amazon Alexa Skills Kit. 4 | Parameters: 5 | TopicNameParameter: 6 | Type: String 7 | Resources: 8 | alexaskillskitcolorexpert: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: Demonstrates a basic skill built with the Amazon Alexa Skills Kit. 15 | MemorySize: 128 16 | Timeout: 3 17 | Policies: 18 | - SNSPublishMessagePolicy: 19 | TopicName: !Ref TopicNameParameter 20 | Events: 21 | AlexaSkillEvent: 22 | Type: AlexaSkill 23 | -------------------------------------------------------------------------------- /javascript/alexa-skills-kit-color-expert/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "session": { 4 | "new": false, 5 | "sessionId": "amzn1.echo-api.session.123456789012", 6 | "application": { 7 | "applicationId": "amzn1.ask.skill.987654321" 8 | }, 9 | "attributes": {}, 10 | "user": { 11 | "userId": "amzn1.ask.account.testUser" 12 | } 13 | }, 14 | "context": { 15 | "AudioPlayer": { 16 | "playerActivity": "IDLE" 17 | }, 18 | "System": { 19 | "application": { 20 | "applicationId": "amzn1.ask.skill.987654321" 21 | }, 22 | "user": { 23 | "userId": "amzn1.ask.account.testUser" 24 | }, 25 | "device": { 26 | "supportedInterfaces": { 27 | "AudioPlayer": {} 28 | } 29 | } 30 | } 31 | }, 32 | "request": { 33 | "type": "IntentRequest", 34 | "requestId": "amzn1.echo-api.request.1234", 35 | "timestamp": "2016-10-27T21:06:28Z", 36 | "locale": "en-US", 37 | "intent": { 38 | "name": "MyColorIsIntent", 39 | "slots": { 40 | "Color": { 41 | "name": "Color", 42 | "value": "blue" 43 | } 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /javascript/alexa-smart-home-skill-adapter/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alexa-skill-kit-sdk-howtoskill", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "alexa-sdk": "^1.0.10" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/alexa-smart-home-skill-adapter/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Provides the basic framework for a skill adapter for a smart home skill. 4 | Parameters: 5 | TopicNameParameter: 6 | Type: String 7 | Resources: 8 | alexasmarthomeskilladapter: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: Provides the basic framework for a skill adapter for a smart home skill. 15 | MemorySize: 128 16 | Timeout: 7 17 | Policies: 18 | - SNSPublishMessagePolicy: 19 | TopicName: !Ref TopicNameParameter -------------------------------------------------------------------------------- /javascript/alexa-smart-home-skill-adapter/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "header": { 3 | "messageId": "F8752B11-69BB-4246-B923-3BFB27C06C7D", 4 | "name": "DiscoverAppliancesRequest", 5 | "namespace": "Alexa.ConnectedHome.Discovery", 6 | "payloadVersion": "2" 7 | }, 8 | "payload": { 9 | "accessToken": "1" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /javascript/algorithmia/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/algorithmia/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Run any algorithm in the Algorithmia marketplace. 4 | Parameters: 5 | TopicNameParameter: 6 | Type: String 7 | Resources: 8 | algorithmia: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: Run any algorithm in the Algorithmia marketplace. 15 | MemorySize: 256 16 | Timeout: 60 17 | Policies: 18 | - SNSPublishMessagePolicy: 19 | TopicName: !Ref TopicNameParameter 20 | Events: 21 | BucketEvent1: 22 | Type: S3 23 | Properties: 24 | Bucket: 25 | Ref: Bucket1 26 | Events: 27 | - 's3:ObjectCreated:*' 28 | Bucket1: 29 | Type: 'AWS::S3::Bucket' 30 | -------------------------------------------------------------------------------- /javascript/api-gateway-authorizer-nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/api-gateway-authorizer-nodejs/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: 'Blueprint for API Gateway custom authorizers, implemented in NodeJS.' 4 | Parameters: 5 | TopicNameParameter: 6 | Type: String 7 | Resources: 8 | apigatewayauthorizernodejs: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: 'Blueprint for API Gateway custom authorizers, implemented in NodeJS.' 15 | MemorySize: 256 16 | Timeout: 5 17 | Policies: 18 | - SNSPublishMessagePolicy: 19 | TopicName: !Ref TopicNameParameter -------------------------------------------------------------------------------- /javascript/api-gateway-authorizer-nodejs/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "TOKEN", 3 | "authorizationToken": "incoming-client-token", 4 | "methodArn": "arn:aws:execute-api:us-east-1:123456789012:/prod/POST/{proxy+}" 5 | } 6 | -------------------------------------------------------------------------------- /javascript/api-gateway-multiple-origin-cors/README.md: -------------------------------------------------------------------------------- 1 | # cors-multiple-origin 2 | 3 | *Example of Multiple-Origin CORS using API Gateway and Lambda* 4 | 5 | [Cross-Origin Resource Sharing (CORS) - MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) 6 | 7 | ### Local development 8 | 9 | First, [set up the SAM CLI](https://github.com/awslabs/aws-sam-cli#installation). 10 | 11 | Now, test the application locally using: 12 | 13 | `sam local start-api` 14 | 15 | Note that there was an [issue](https://github.com/awslabs/aws-sam-cli/issues/400) that prevented OPTIONS requests from being handled when running with the SAM CLI version 0.3.0. This does not occur when the application is deployed. 16 | 17 | Run the tests: 18 | 19 | `npm install` 20 | 21 | `npm test` 22 | 23 | ### Deploying 24 | 25 | ```bash 26 | sam package \ 27 | --template-file template.yaml \ 28 | --output-template-file packaged.yaml \ 29 | --s3-bucket $YOUR_BUCKET_NAME 30 | ``` 31 | 32 | ```bash 33 | sam deploy \ 34 | --template-file packaged.yaml \ 35 | --stack-name cors-multiple-origin \ 36 | --capabilities CAPABILITY_IAM 37 | ``` 38 | 39 | ### Getting the URL of the deployed instance 40 | 41 | ```bash 42 | aws cloudformation describe-stacks \ 43 | --stack-name cors-multiple-origin \ 44 | --query 'Stacks[].Outputs' 45 | ``` -------------------------------------------------------------------------------- /javascript/api-gateway-multiple-origin-cors/cors-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "allowedOrigins": [ 3 | "http://127.0.0.1", 4 | "https://*.example.com", 5 | "https://*.amazon.com" 6 | ] 7 | } -------------------------------------------------------------------------------- /javascript/api-gateway-multiple-origin-cors/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cors-multiple-origin", 3 | "version": "0.0.1", 4 | "description": "Example of Multiple-Origin CORS using API Gateway and Lambda", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "author": "", 10 | "devDependencies": { 11 | "jest": "^26.0.1", 12 | "lodash": ">=4.17.13", 13 | "merge": ">=1.2.1" 14 | }, 15 | "jest": { 16 | "testPathIgnorePatterns": [ 17 | "/node_modules/", 18 | "/routes/test\\.js" 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /javascript/api-gateway-multiple-origin-cors/routes/root.js: -------------------------------------------------------------------------------- 1 | const cors = require("../cors-util"); 2 | const config = require("../cors-config.json"); 3 | 4 | /** 5 | * Demonstrates a simple endpoint that accepts GET requests. 6 | * 7 | * In most cases, browsers do not perform CORS preflight requests when using 8 | * the GET method, so we do not have to handle OPTIONS requests. 9 | * Any desired additional CORS headers should be included in the GET response. 10 | */ 11 | exports.handler = async (event, context) => { 12 | const origin = cors.getOriginFromEvent(event); 13 | 14 | // return an empty response, with CORS origin 15 | return { 16 | headers: cors.createOriginHeader(origin, config.allowedOrigins), 17 | statusCode: 204 18 | }; 19 | }; 20 | -------------------------------------------------------------------------------- /javascript/api-gateway-multiple-origin-cors/routes/test.js: -------------------------------------------------------------------------------- 1 | const cors = require("../cors-util"); 2 | const config = require("../cors-config.json"); 3 | 4 | /** 5 | * Demonstrates an endpoint that accepts DELETE requests. 6 | * 7 | * In this case, the browser will perform a CORS preflight request, so we must 8 | * handle OPTIONS requests and provide the CORS headers. 9 | * When the browser makes the DELETE request, we only need to provide the origin. 10 | */ 11 | exports.handler = async (event, context) => { 12 | const origin = cors.getOriginFromEvent(event); 13 | const allowedMethods = ["OPTIONS", "DELETE"]; 14 | 15 | if (event.httpMethod === "OPTIONS") { 16 | return cors.createPreflightResponse(origin, config.allowedOrigins, allowedMethods); 17 | } else if (event.httpMethod === "DELETE") { 18 | // return an empty response, with CORS origin 19 | return { 20 | headers: cors.createOriginHeader(origin, config.allowedOrigins), 21 | statusCode: 204 22 | }; 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /javascript/cfn-look-up-ami-ids/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/cfn-look-up-ami-ids/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Looks up the latest AMI ID for a given region and architecture. 4 | Resources: 5 | cfnlookupamiids: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: index.handler 9 | Runtime: nodejs12.x 10 | CodeUri: . 11 | Description: Looks up the latest AMI ID for a given region and architecture. 12 | MemorySize: 128 13 | Timeout: 3 14 | Policies: 15 | - AMIDescribePolicy: {} -------------------------------------------------------------------------------- /javascript/cfn-look-up-ami-ids/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "RequestType": "Create", 3 | "ResponseURL": "http://pre-signed-S3-url-for-response", 4 | "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/MyStack/guid", 5 | "RequestId": "unique id for this create request", 6 | "ResourceType": "Custom::TestResource", 7 | "LogicalResourceId": "MyTestResource", 8 | "ResourceProperties": { 9 | "StackName": "MyStack", 10 | "List": [ 11 | "1", 12 | "2", 13 | "3" 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /javascript/cfn-stack-outputs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/cfn-stack-outputs/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Takes an AWS CloudFormation stack name and returns the outputs from that 5 | stack. 6 | Resources: 7 | cfnstackoutputs: 8 | Type: 'AWS::Serverless::Function' 9 | Properties: 10 | Handler: index.handler 11 | Runtime: nodejs12.x 12 | CodeUri: . 13 | Description: >- 14 | Takes an AWS CloudFormation stack name and returns the outputs from that 15 | stack. 16 | MemorySize: 128 17 | Timeout: 3 18 | Policies: 19 | - CloudFormationDescribeStacksPolicy: {} -------------------------------------------------------------------------------- /javascript/cfn-stack-outputs/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "RequestType": "Create", 3 | "ResponseURL": "http://pre-signed-S3-url-for-response", 4 | "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/MyStack/guid", 5 | "RequestId": "unique id for this create request", 6 | "ResourceType": "Custom::TestResource", 7 | "LogicalResourceId": "MyTestResource", 8 | "ResourceProperties": { 9 | "StackName": "MyStack", 10 | "List": [ 11 | "1", 12 | "2", 13 | "3" 14 | ] 15 | } 16 | } -------------------------------------------------------------------------------- /javascript/cloudfront-ab-test/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: 'Blueprint for CloudFront ab testing, implemented in NodeJS.' 4 | Parameters: 5 | KeyIdParameter: 6 | Type: String 7 | Resources: 8 | cloudfrontabtest: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: 'Blueprint for CloudFront ab testing, implemented in NodeJS.' 15 | MemorySize: 128 16 | Timeout: 1 17 | Policies: 18 | - KMSDecryptPolicy: 19 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudfront-ab-test/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "cf": { 5 | "config": { 6 | "distributionId": "EXAMPLE" 7 | }, 8 | "request": { 9 | "uri": "/experiment-pixel.jpg", 10 | "method": "GET", 11 | "clientIp": "2001:cdba::3257:9652", 12 | "headers": { 13 | "user-agent": [ 14 | { 15 | "key": "User-Agent", 16 | "value": "Test Agent" 17 | } 18 | ], 19 | "host": [ 20 | { 21 | "key": "Host", 22 | "value": "d123.cf.net" 23 | } 24 | ], 25 | "cookie": [ 26 | { 27 | "key": "Cookie", 28 | "value": "SomeCookie=1; AnotherOne=A;" 29 | } 30 | ] 31 | } 32 | } 33 | } 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /javascript/cloudfront-access-request-in-response/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.handler = (event, context, callback) => { 4 | const request = event.Records[0].cf.request; 5 | const response = event.Records[0].cf.response; 6 | 7 | /* 8 | * Set the Content-Disposition Header based on the user-name request header 9 | */ 10 | if (request.headers['user-name']) { 11 | response.headers['content-disposition'] = [{ 12 | key: 'Content-Disposition', 13 | value: `attachment; filename=${request.headers['user-name'][0].value}`, 14 | }]; 15 | console.log(`Add content disposition response header "${response.headers['content-disposition'][0].value}"`); 16 | } 17 | callback(null, response); 18 | }; 19 | -------------------------------------------------------------------------------- /javascript/cloudfront-access-request-in-response/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Blueprint for setting CloudFront response header based on value in the request header implemented in NodeJS. 5 | Parameters: 6 | KeyIdParameter: 7 | Type: String 8 | Resources: 9 | cloudfrontaccessrequestinresponse: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | Blueprint for setting CloudFront response header based on value in the request header implemented in NodeJS. 17 | MemorySize: 128 18 | Timeout: 1 19 | Policies: 20 | - KMSDecryptPolicy: 21 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudfront-access-request-in-response/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "cf": { 5 | "config": { 6 | "distributionId": "EXAMPLE" 7 | }, 8 | "request": { 9 | "headers": { 10 | "host": [ 11 | { 12 | "key": "Host", 13 | "value": "d123.cf.net" 14 | } 15 | ], 16 | "user-name": [ 17 | { 18 | "key": "User-Name", 19 | "value": "CloudFront" 20 | } 21 | ] 22 | }, 23 | "clientIp": "2001:cdba::3257:9652", 24 | "uri": "/test", 25 | "method": "GET" 26 | }, 27 | "response": { 28 | "status": "200", 29 | "statusDescription": "OK", 30 | "headers": { 31 | "x-cache": [ 32 | { 33 | "key": "X-Cache", 34 | "value": "Hello from Cloudfront" 35 | } 36 | ] 37 | } 38 | } 39 | } 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /javascript/cloudfront-http-redirect/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.handler = (event, context, callback) => { 4 | 5 | var response = { 6 | "statusCode": 302, 7 | "headers": { 8 | "Location": "http://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html" 9 | }, 10 | "body": "{}", 11 | "isBase64Encoded": false 12 | }; 13 | callback(null, response); 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /javascript/cloudfront-http-redirect/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Blueprint for returning HTTP redirect implemented in NodeJS. 4 | Parameters: 5 | KeyIdParameter: 6 | Type: String 7 | Resources: 8 | cloudfronthttpredirect: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: Blueprint for returning HTTP redirect implemented in NodeJS. 15 | MemorySize: 128 16 | Timeout: 1 17 | Policies: 18 | - KMSDecryptPolicy: 19 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudfront-http-redirect/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "cf": { 5 | "config": { 6 | "distributionId": "EXAMPLE" 7 | }, 8 | "request": { 9 | "uri": "/test", 10 | "method": "GET", 11 | "clientIp": "2001:cdba::3257:9652", 12 | "headers": { 13 | "user-agent": [ 14 | { 15 | "key": "User-Agent", 16 | "value": "test-agent" 17 | } 18 | ], 19 | "host": [ 20 | { 21 | "key": "Host", 22 | "value": "d123.cf.net" 23 | } 24 | ] 25 | } 26 | } 27 | } 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /javascript/cloudfront-modify-querystring/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const querystring = require('querystring'); 4 | 5 | exports.handler = (event, context, callback) => { 6 | const request = event.Records[0].cf.request; 7 | 8 | /* When a request contains a query string key-value pair but the origin server 9 | * expects the value in a header, you can use this Lambda function to 10 | * convert the key-value pair to a header. Here's what the function does: 11 | * 1. Parses the query string and gets the key-value pair. 12 | * 2. Adds a header to the request using the key-value pair that the function got in step 1. 13 | */ 14 | 15 | /* Parse request querystring to get javascript object */ 16 | const params = querystring.parse(request.querystring); 17 | 18 | /* Move auth param from querystring to headers */ 19 | const headerName = 'Auth-Header'; 20 | request.headers[headerName.toLowerCase()] = [{ key: headerName, value: params.auth }]; 21 | delete params.auth; 22 | 23 | /* Update request querystring */ 24 | request.querystring = querystring.stringify(params); 25 | 26 | callback(null, request); 27 | }; 28 | -------------------------------------------------------------------------------- /javascript/cloudfront-modify-querystring/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Blueprint to add a header based on the values in a key-value pair in a querynstring. 5 | Parameters: 6 | KeyIdParameter: 7 | Type: String 8 | Resources: 9 | cloudfrontmodifyquerystring: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | Blueprint to add a header based on the values in a key-value pair in a query string. 17 | MemorySize: 128 18 | Timeout: 3 19 | Policies: 20 | - KMSDecryptPolicy: 21 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudfront-modify-querystring/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "cf": { 5 | "config": { 6 | "distributionId": "EXAMPLE" 7 | }, 8 | "request": { 9 | "uri": "/test", 10 | "querystring": "auth=test&foo=bar", 11 | "method": "GET", 12 | "clientIp": "2001:cdba::3257:9652", 13 | "headers": { 14 | "host": [ 15 | { 16 | "key": "Host", 17 | "value": "d123.cf.net" 18 | } 19 | ], 20 | "user-agent": [ 21 | { 22 | "key": "User-Agent", 23 | "value": "Test Agent" 24 | } 25 | ], 26 | "user-name": [ 27 | { 28 | "key": "User-Name", 29 | "value": "aws-cloudfront" 30 | } 31 | ] 32 | } 33 | } 34 | } 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /javascript/cloudfront-modify-response-header/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.handler = (event, context, callback) => { 4 | const response = event.Records[0].cf.response; 5 | const headers = response.headers; 6 | 7 | const headerNameSrc = 'X-Amz-Meta-Last-Modified'; 8 | const headerNameDst = 'Last-Modified'; 9 | 10 | if (headers[headerNameSrc.toLowerCase()]) { 11 | headers[headerNameDst.toLowerCase()] = [{ 12 | key: headerNameDst, 13 | value: headers[headerNameSrc.toLowerCase()][0].value, 14 | }]; 15 | console.log(`Response header "${headerNameDst}" was set to ` + 16 | `"${headers[headerNameDst.toLowerCase()][0].value}"`); 17 | } 18 | 19 | callback(null, response); 20 | }; 21 | -------------------------------------------------------------------------------- /javascript/cloudfront-modify-response-header/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Blueprint for modifying CloudFront response header implemented in NodeJS. 4 | Parameters: 5 | KeyIdParameter: 6 | Type: String 7 | Resources: 8 | cloudfrontmodifyresponseheader: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: >- 15 | Blueprint for modifying CloudFront response header implemented in NodeJS. 16 | MemorySize: 128 17 | Timeout: 1 18 | Policies: 19 | - KMSDecryptPolicy: 20 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudfront-modify-response-header/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "cf": { 5 | "config": { 6 | "distributionId": "EXAMPLE" 7 | }, 8 | "response": { 9 | "status": "200", 10 | "statusDescription": "OK", 11 | "headers": { 12 | "vary": [ 13 | { 14 | "key": "Vary", 15 | "value": "*" 16 | } 17 | ], 18 | "last-modified": [ 19 | { 20 | "key": "Last-Modified", 21 | "value": "2016-11-25" 22 | } 23 | ], 24 | "x-amz-meta-last-modified": [ 25 | { 26 | "key": "X-Amz-Meta-Last-Modified", 27 | "value": "2016-01-01" 28 | } 29 | ] 30 | } 31 | } 32 | } 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /javascript/cloudfront-multiple-remote-calls-aggregate-response/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Blueprint for generating aggregated response from multiple remote calls on origin-request trigger implemented in NodeJS. 5 | Parameters: 6 | KeyIdParameter: 7 | Type: String 8 | Resources: 9 | cloudfrontmultipleremotecallsaggregateresponse: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | Blueprint for generating aggregated response from multiple remote calls on origin-request trigger implemented in NodeJS. 17 | MemorySize: 128 18 | Timeout: 1 19 | Policies: 20 | - KMSDecryptPolicy: 21 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudfront-multiple-remote-calls-aggregate-response/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "cf": { 5 | "config": { 6 | "distributionId": "EXAMPLE" 7 | }, 8 | "request": { 9 | "uri": "/forecast/Seattle:NewYork:Chicago:SanFrancisco", 10 | "method": "GET", 11 | "clientIp": "2001:cdba::3257:9652", 12 | "headers": { 13 | "host": [ 14 | { 15 | "key": "Host", 16 | "value": "d123.cf.net" 17 | } 18 | ], 19 | "user-agent": [ 20 | { 21 | "key": "User-Agent", 22 | "value": "Test Agent" 23 | } 24 | ] 25 | } 26 | } 27 | } 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /javascript/cloudfront-redirect-on-viewer-country/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* This is an origin request function */ 4 | exports.handler = (event, context, callback) => { 5 | const request = event.Records[0].cf.request; 6 | const headers = request.headers; 7 | 8 | /* 9 | * Based on the value of the CloudFront-Viewer-Country header, generate an 10 | * HTTP status code 302 (Redirect) response, and return a country-specific 11 | * URL in the Location header. 12 | * NOTE: 1. You must configure your distribution to cache based on the 13 | * CloudFront-Viewer-Country header. For more information, see 14 | * http://docs.aws.amazon.com/console/cloudfront/cache-on-selected-headers 15 | * 2. CloudFront adds the CloudFront-Viewer-Country header after the viewer 16 | * request event. To use this example, you must create a trigger for the 17 | * origin request event. 18 | */ 19 | let url = 'https://example.com/'; 20 | if (headers['cloudfront-viewer-country']) { 21 | const countryCode = headers['cloudfront-viewer-country'][0].value; 22 | if (countryCode === 'TW') { 23 | url = 'https://tw.example.com/'; 24 | } else if (countryCode === 'US') { 25 | url = 'https://us.example.com/'; 26 | } 27 | } 28 | 29 | const response = { 30 | status: '302', 31 | statusDescription: 'Found', 32 | headers: { 33 | location: [{ 34 | key: 'Location', 35 | value: url, 36 | }], 37 | }, 38 | }; 39 | callback(null, response); 40 | }; 41 | -------------------------------------------------------------------------------- /javascript/cloudfront-redirect-on-viewer-country/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Blueprint for generating a redirect response based on the viewer country. Triggered by an origin-request. Implemented in NodeJS. 5 | Parameters: 6 | KeyIdParameter: 7 | Type: String 8 | Resources: 9 | cloudfrontredirectonviewercountry: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | Blueprint for generating a redirect response based on the viewer country. Triggered by an origin-request. Implemented in NodeJS. 17 | MemorySize: 128 18 | Timeout: 1 19 | Policies: 20 | - KMSDecryptPolicy: 21 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudfront-redirect-on-viewer-country/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "cf": { 5 | "config": { 6 | "distributionId": "EXAMPLE" 7 | }, 8 | "request": { 9 | "uri": "/test", 10 | "method": "GET", 11 | "clientIp": "2001:cdba::3257:9652", 12 | "headers": { 13 | "host": [ 14 | { 15 | "key": "Host", 16 | "value": "d123.cf.net" 17 | } 18 | ], 19 | "cloudfront-viewer-country": [ 20 | { 21 | "key": "CloudFront-Viewer-Country", 22 | "value": "TW" 23 | } 24 | ] 25 | } 26 | } 27 | } 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /javascript/cloudfront-redirect-unauthenticated-users/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/cloudfront-redirect-unauthenticated-users/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Blueprint for redirecting unauthenticated users to sign-in page; triggered by CloudFront viewer-request event. 5 | Parameters: 6 | KeyIdParameter: 7 | Type: String 8 | Resources: 9 | cloudfrontredirectunauthenticatedusers: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | Blueprint for redirecting unauthenticated users to sign-in page; triggered by CloudFront viewer-request event. 17 | MemorySize: 128 18 | Timeout: 1 19 | Policies: 20 | - KMSDecryptPolicy: 21 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudfront-redirect-unauthenticated-users/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "cf": { 5 | "config": { 6 | "distributionId": "EXAMPLE" 7 | }, 8 | "request": { 9 | "uri": "/test", 10 | "method": "GET", 11 | "querystring": "foo=bar", 12 | "headers": { 13 | "host": [ 14 | { 15 | "key": "Host", 16 | "value": "d123.cf.net" 17 | } 18 | ] 19 | } 20 | } 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /javascript/cloudfront-response-generation/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.handler = (event, context, callback) => { 4 | /* 5 | * Generate HTTP response using 200 status code with a simple body. 6 | */ 7 | const response = { 8 | status: '200', 9 | statusDescription: 'OK', 10 | headers: { 11 | vary: [{ 12 | key: 'Vary', 13 | value: '*', 14 | }], 15 | 'last-modified': [{ 16 | key: 'Last-Modified', 17 | value: '2017-01-13', 18 | }], 19 | }, 20 | body: 'Example body generated by Lambda@Edge function.', 21 | }; 22 | 23 | callback(null, response); 24 | }; 25 | -------------------------------------------------------------------------------- /javascript/cloudfront-response-generation/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Blueprint for generating a response from viewer-request trigger implemented in NodeJS. 5 | Parameters: 6 | KeyIdParameter: 7 | Type: String 8 | Resources: 9 | cloudfrontresponsegeneration: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | Blueprint for generating a response from viewer-request trigger implemented in NodeJS. 17 | MemorySize: 128 18 | Timeout: 1 19 | Policies: 20 | - KMSDecryptPolicy: 21 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudfront-response-generation/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "cf": { 5 | "config": { 6 | "distributionId": "EXAMPLE" 7 | }, 8 | "request": { 9 | "uri": "/test", 10 | "method": "GET", 11 | "clientIp": "2001:cdba::3257:9652", 12 | "headers": { 13 | "host": [ 14 | { 15 | "key": "Host", 16 | "value": "d123.cf.net" 17 | } 18 | ] 19 | } 20 | } 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /javascript/cloudfront-simple-remote-call/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Blueprint for generating a response from origin-request trigger implemented in NodeJS. 5 | Parameters: 6 | KeyIdParameter: 7 | Type: String 8 | Resources: 9 | cloudfrontsimpleremotecall: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | Blueprint for generating a response from origin-request trigger 17 | implemented in NodeJS. 18 | MemorySize: 128 19 | Timeout: 3 20 | Policies: 21 | - KMSDecryptPolicy: 22 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudfront-simple-remote-call/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "cf": { 5 | "config": { 6 | "distributionId": "EXAMPLE" 7 | }, 8 | "request": { 9 | "uri": "/test", 10 | "method": "GET", 11 | "clientIp": "2001:cdba::3257:9652", 12 | "headers": { 13 | "host": [ 14 | { 15 | "key": "Host", 16 | "value": "d123.cf.net" 17 | } 18 | ], 19 | "user-agent": [ 20 | { 21 | "key": "User-Agent", 22 | "value": "Test Agent" 23 | } 24 | ], 25 | "user-name": [ 26 | { 27 | "key": "User-Name", 28 | "value": "aws-cloudfront" 29 | } 30 | ] 31 | } 32 | } 33 | } 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /javascript/cloudwatch-alarm-to-slack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/cloudwatch-alarm-to-slack/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon SNS trigger that sends CloudWatch alarm notifications to Slack. 4 | Parameters: 5 | KeyIdParameter: 6 | Type: String 7 | slackChannelParameter: 8 | Type: String 9 | kmsEncryptedHookUrlParameter: 10 | Type: String 11 | Resources: 12 | cloudwatchalarmtoslack: 13 | Type: 'AWS::Serverless::Function' 14 | Properties: 15 | Handler: index.handler 16 | Runtime: nodejs12.x 17 | CodeUri: . 18 | Description: >- 19 | An Amazon SNS trigger that sends CloudWatch alarm notifications to 20 | Slack. 21 | MemorySize: 128 22 | Timeout: 3 23 | Policies: 24 | - KMSDecryptPolicy: 25 | KeyId: !Ref KeyIdParameter 26 | Events: 27 | SNS1: 28 | Type: SNS 29 | Properties: 30 | Topic: 31 | Ref: SNSTopic1 32 | Environment: 33 | Variables: 34 | slackChannel: slackChannelParameter 35 | kmsEncryptedHookUrl: kmsEncryptedHookUrlParameter 36 | SNSTopic1: 37 | Type: 'AWS::SNS::Topic' 38 | -------------------------------------------------------------------------------- /javascript/cloudwatch-logs-process-data/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const zlib = require('zlib'); 4 | 5 | exports.handler = (event, context, callback) => { 6 | const payload = new Buffer(event.awslogs.data, 'base64'); 7 | zlib.gunzip(payload, (err, res) => { 8 | if (err) { 9 | return callback(err); 10 | } 11 | const parsed = JSON.parse(res.toString('utf8')); 12 | console.log('Decoded payload:', JSON.stringify(parsed)); 13 | callback(null, `Successfully processed ${parsed.logEvents.length} log events.`); 14 | }); 15 | }; 16 | -------------------------------------------------------------------------------- /javascript/cloudwatch-logs-process-data/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/cloudwatch-logs-process-data/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | A real-time consumer of log events ingested by an Amazon CloudWatch Logs log 5 | group. 6 | Parameters: 7 | KeyIdParameter: 8 | Type: String 9 | Resources: 10 | cloudwatchlogsprocessdata: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: index.handler 14 | Runtime: nodejs12.x 15 | CodeUri: . 16 | Description: >- 17 | A real-time consumer of log events ingested by an Amazon CloudWatch Logs 18 | log group. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - KMSDecryptPolicy: 23 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/cloudwatch-logs-process-data/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "awslogs": { 3 | "data": "H4sIAAAAAAAAAHWPwQqCQBCGX0Xm7EFtK+smZBEUgXoLCdMhFtKV3akI8d0bLYmibvPPN3wz00CJxmQnTO41whwWQRIctmEcB6sQbFC3CjW3XW8kxpOpP+OC22d1Wml1qZkQGtoMsScxaczKN3plG8zlaHIta5KqWsozoTYw3/djzwhpLwivWFGHGpAFe7DL68JlBUk+l7KSN7tCOEJ4M3/qOI49vMHj+zCKdlFqLaU2ZHV2a4Ct/an0/ivdX8oYc1UVX860fQDQiMdxRQEAAA==" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /javascript/cloudwatch-logs-to-loggly/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/cloudwatch-logs-to-loggly/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Sends logs from Cloudwatch logs to Loggly using a Lambda function. 4 | Parameters: 5 | KeyIdParameter: 6 | Type: String 7 | Resources: 8 | cloudwatchlogstologgly: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: Sends logs from Cloudwatch logs to Loggly using a Lambda function. 15 | MemorySize: 128 16 | Timeout: 3 17 | Policies: 18 | - KMSDecryptPolicy: 19 | KeyId: !Ref KeyIdParameter 20 | Environment: 21 | Variables: 22 | kmsEncryptedCustomerToken: 23 | logglyTags: CloudWatch2Loggly 24 | logglyHostName: 25 | -------------------------------------------------------------------------------- /javascript/cognito-sync-trigger/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.log('Loading function'); 4 | 5 | exports.handler = (event, context, callback) => { 6 | //console.log('Received event:', JSON.stringify(event, null, 2)); 7 | const modifiedEvent = event; 8 | 9 | // Check for the event type 10 | if (event.eventType === 'SyncTrigger') { 11 | // Modify value for a key 12 | if ('SampleKey1' in event.datasetRecords) { 13 | modifiedEvent.datasetRecords.SampleKey1.newValue = 'ModifyValue1'; 14 | modifiedEvent.datasetRecords.SampleKey1.op = 'replace'; 15 | } 16 | 17 | // Remove a key 18 | if ('SampleKey2' in event.datasetRecords) { 19 | modifiedEvent.datasetRecords.SampleKey2.op = 'remove'; 20 | } 21 | 22 | // Add a key 23 | if (!('SampleKey3' in event.datasetRecords)) { 24 | modifiedEvent.datasetRecords.SampleKey3 = { 25 | newValue: 'ModifyValue3', 26 | op: 'replace', 27 | }; 28 | } 29 | } 30 | 31 | callback(null, modifiedEvent); 32 | }; 33 | -------------------------------------------------------------------------------- /javascript/cognito-sync-trigger/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/cognito-sync-trigger/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Cognito Sync trigger that modifies Cognito datasets based on the 5 | incoming event. 6 | Parameters: 7 | KeyIdParameter: 8 | Type: String 9 | Resources: 10 | cognitosynctrigger: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: index.handler 14 | Runtime: nodejs12.x 15 | CodeUri: . 16 | Description: >- 17 | An Amazon Cognito Sync trigger that modifies Cognito datasets based on 18 | the incoming event. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - KMSDecryptPolicy: 23 | KeyId: !Ref KeyIdParameter 24 | -------------------------------------------------------------------------------- /javascript/cognito-sync-trigger/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "eventType": "SyncTrigger", 4 | "region": "us-east-1", 5 | "identityPoolId": "identityPoolId", 6 | "identityId": "identityId", 7 | "datasetName": "datasetName", 8 | "datasetRecords": { 9 | "SampleKey1": { 10 | "oldValue": "oldValue1", 11 | "newValue": "newValue1", 12 | "op": "replace" 13 | }, 14 | "SampleKey2": { 15 | "oldValue": "oldValue2", 16 | "newValue": "newValue2", 17 | "op": "replace" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /javascript/config-rule-change-triggered/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An AWS Config rule that is triggered by configuration changes to EC2 5 | instances. Checks instance types. 6 | Resources: 7 | configrulechangetriggered: 8 | Type: 'AWS::Serverless::Function' 9 | Properties: 10 | Handler: index.handler 11 | Runtime: nodejs12.x 12 | CodeUri: . 13 | Description: >- 14 | An AWS Config rule that is triggered by configuration changes to EC2 15 | instances. Checks instance types. 16 | MemorySize: 128 17 | Timeout: 10 18 | Policies: 19 | - AWSConfigRulesExecutionRole 20 | -------------------------------------------------------------------------------- /javascript/config-rule-periodic/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An AWS Config rule that is triggered periodically. Checks for a maximum number 5 | of resources in your account. 6 | Resources: 7 | configruleperiodic: 8 | Type: 'AWS::Serverless::Function' 9 | Properties: 10 | Handler: index.handler 11 | Runtime: nodejs12.x 12 | CodeUri: . 13 | Description: >- 14 | An AWS Config rule that is triggered periodically. Checks for a maximum 15 | number of resources in your account. 16 | MemorySize: 128 17 | Timeout: 10 18 | Policies: 19 | - AWSConfigRulesExecutionRole 20 | -------------------------------------------------------------------------------- /javascript/dynamodb-process-stream/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.log('Loading function'); 4 | 5 | exports.handler = (event, context, callback) => { 6 | //console.log('Received event:', JSON.stringify(event, null, 2)); 7 | event.Records.forEach((record) => { 8 | console.log(record.eventID); 9 | console.log(record.eventName); 10 | console.log('DynamoDB Record: %j', record.dynamodb); 11 | }); 12 | callback(null, `Successfully processed ${event.Records.length} records.`); 13 | }; 14 | -------------------------------------------------------------------------------- /javascript/dynamodb-process-stream/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon DynamoDB trigger that logs the updates made to a table. 4 | Resources: 5 | dynamodbprocessstream: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: index.handler 9 | Runtime: nodejs12.x 10 | CodeUri: . 11 | Description: An Amazon DynamoDB trigger that logs the updates made to a table. 12 | MemorySize: 128 13 | Timeout: 3 14 | Policies: 15 | - AWSConfigRulesExecutionRole 16 | Events: 17 | DynamoDB1: 18 | Type: DynamoDB 19 | Properties: 20 | Stream: 21 | 'Fn::GetAtt': 22 | - Table1 23 | - StreamArn 24 | StartingPosition: TRIM_HORIZON 25 | BatchSize: 100 26 | Table1: 27 | Type: 'AWS::DynamoDB::Table' 28 | Properties: 29 | AttributeDefinitions: 30 | - AttributeName: id 31 | AttributeType: S 32 | KeySchema: 33 | - AttributeName: id 34 | KeyType: HASH 35 | ProvisionedThroughput: 36 | ReadCapacityUnits: 5 37 | WriteCapacityUnits: 5 38 | StreamSpecification: 39 | StreamViewType: NEW_IMAGE 40 | -------------------------------------------------------------------------------- /javascript/hello-world/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.log('Loading function'); 4 | 5 | exports.handler = (event, context, callback) => { 6 | //console.log('Received event:', JSON.stringify(event, null, 2)); 7 | console.log('value1 =', event.key1); 8 | console.log('value2 =', event.key2); 9 | console.log('value3 =', event.key3); 10 | callback(null, event.key1); // Echo back the first key value 11 | //callback('Something went wrong'); 12 | }; 13 | -------------------------------------------------------------------------------- /javascript/hello-world/readme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amazon-archives/serverless-app-examples/9485c6ca6adc65994e5c5b0002039e4547d6c3d2/javascript/hello-world/readme -------------------------------------------------------------------------------- /javascript/hello-world/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: A starter AWS Lambda function. 4 | Parameters: 5 | IdentityNameParameter: 6 | Type: String 7 | Resources: 8 | helloworld: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: A starter AWS Lambda function. 15 | MemorySize: 128 16 | Timeout: 3 17 | Policies: 18 | - SESSendBouncePolicy: 19 | IdentityName: !Ref IdentityNameParameter -------------------------------------------------------------------------------- /javascript/hello-world/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "key1": "value1", 3 | "key2": "value2", 4 | "key3": "value3" 5 | } 6 | -------------------------------------------------------------------------------- /javascript/https-request/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const https = require('https'); 4 | 5 | /** 6 | * Pass the data to send as `event.data`, and the request options as 7 | * `event.options`. For more information see the HTTPS module documentation 8 | * at https://nodejs.org/api/https.html. 9 | * 10 | * Will succeed with the response body. 11 | */ 12 | exports.handler = (event, context, callback) => { 13 | const req = https.request(event.options, (res) => { 14 | let body = ''; 15 | console.log('Status:', res.statusCode); 16 | console.log('Headers:', JSON.stringify(res.headers)); 17 | res.setEncoding('utf8'); 18 | res.on('data', (chunk) => body += chunk); 19 | res.on('end', () => { 20 | console.log('Successfully processed HTTPS response'); 21 | // If we know it's JSON, parse it 22 | if (res.headers['content-type'] === 'application/json') { 23 | body = JSON.parse(body); 24 | } 25 | callback(null, body); 26 | }); 27 | }); 28 | req.on('error', callback); 29 | req.write(JSON.stringify(event.data)); 30 | req.end(); 31 | }; 32 | -------------------------------------------------------------------------------- /javascript/https-request/readme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amazon-archives/serverless-app-examples/9485c6ca6adc65994e5c5b0002039e4547d6c3d2/javascript/https-request/readme -------------------------------------------------------------------------------- /javascript/https-request/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Demonstrates using a built-in Node.js module to make an HTTPS request. 4 | Parameters: 5 | IdentityNameParameter: 6 | Type: String 7 | Resources: 8 | httpsrequest: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: Demonstrates using a built-in Node.js module to make an HTTPS request. 15 | MemorySize: 128 16 | Timeout: 60 17 | Policies: 18 | - SESSendBouncePolicy: 19 | IdentityName: !Ref IdentityNameParameter 20 | -------------------------------------------------------------------------------- /javascript/image-processing-service/readme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amazon-archives/serverless-app-examples/9485c6ca6adc65994e5c5b0002039e4547d6c3d2/javascript/image-processing-service/readme -------------------------------------------------------------------------------- /javascript/image-processing-service/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Uses ImageMagick to perform simple image processing operations, such as resizing. 5 | Parameters: 6 | IdentityNameParameter: 7 | Type: String 8 | Resources: 9 | imageprocessingservice: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | Uses ImageMagick to perform simple image processing operations, such as resizing. 17 | MemorySize: 512 18 | Timeout: 30 19 | Policies: 20 | - SESSendBouncePolicy: 21 | IdentityName: !Ref IdentityNameParameter 22 | -------------------------------------------------------------------------------- /javascript/inbound-ses-spam-filter/readme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amazon-archives/serverless-app-examples/9485c6ca6adc65994e5c5b0002039e4547d6c3d2/javascript/inbound-ses-spam-filter/readme -------------------------------------------------------------------------------- /javascript/inbound-ses-spam-filter/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | A simple email filter for protection against spam and viruses as well as DKIM and SPF failures. 5 | Parameters: 6 | IdentityNameParameter: 7 | Type: String 8 | Resources: 9 | inboundsesspamfilter: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | A simple email filter for protection against spam and viruses as well as DKIM and SPF failures. 17 | MemorySize: 128 18 | Timeout: 10 19 | Policies: 20 | - SESSendBouncePolicy: 21 | IdentityName: !Ref IdentityNameParameter 22 | Environment: 23 | Variables: 24 | emailDomain: 25 | -------------------------------------------------------------------------------- /javascript/inspector-scheduled-run/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * A blueprint to schedule a recurring assessment run for an Amazon Inspector assessment template. 5 | * 6 | * This blueprint assumes that you've already done the following: 7 | * 1. onboarded with the Amazon Inspector service https://aws.amazon.com/inspector 8 | * 2. created an assessment target - what hosts you want to assess 9 | * 3. created an assessment template - how you want to assess your target 10 | * 11 | * Then, all you need to do to use this blueprint is to define an environment variable in the Lambda console called 12 | * `assessmentTemplateArn` and provide the template arn you want to run on a schedule. 13 | */ 14 | 15 | const AWS = require('aws-sdk'); 16 | 17 | const inspector = new AWS.Inspector(); 18 | 19 | const params = { 20 | assessmentTemplateArn: process.env.assessmentTemplateArn, 21 | }; 22 | 23 | exports.handler = (event, context, callback) => { 24 | try { 25 | // Inspector.StartAssessmentRun response will look something like: 26 | // {"assessmentRunArn":"arn:aws:inspector:us-west-2:123456789012:target/0-wJ0KWygn/template/0-jRPJqnQh/run/0-Ga1lDjhP" 27 | inspector.startAssessmentRun(params, (error, data) => { 28 | if (error) { 29 | console.log(error, error.stack); 30 | return callback(error); 31 | } 32 | 33 | console.log(data); 34 | return callback(null, data); 35 | }); 36 | } catch (error) { 37 | console.log('Caught Error: ', error); 38 | callback(error); 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /javascript/inspector-scheduled-run/readme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amazon-archives/serverless-app-examples/9485c6ca6adc65994e5c5b0002039e4547d6c3d2/javascript/inspector-scheduled-run/readme -------------------------------------------------------------------------------- /javascript/inspector-scheduled-run/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Schedules a recurring Amazon Inspector assessment run 4 | Parameters: 5 | TopicNameParameter: 6 | Type: String 7 | Resources: 8 | inspectorscheduledrun: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: Schedules a recurring Amazon Inspector assessment run 15 | MemorySize: 128 16 | Timeout: 10 17 | Policies: 18 | - SNSCrudPolicy: 19 | TopicName: !Ref TopicNameParameter 20 | Environment: 21 | Variables: 22 | assessmentTemplateArn: 23 | -------------------------------------------------------------------------------- /javascript/kinesis-analytics-process-compressed-record/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | console.log('Loading function'); 3 | const zlib = require('zlib'); 4 | 5 | exports.handler = (event, context, callback) => { 6 | let success = 0; // Number of valid entries found 7 | let failure = 0; // Number of invalid entries found 8 | /* Process the list of records */ 9 | const output = event.records.map((record) => { 10 | /* Data is base64 encoded, so decode here */ 11 | const compressedData = Buffer.from(record.data, 'base64'); 12 | try { 13 | const decompressedData = zlib.unzipSync(compressedData); 14 | /* Encode decompressed JSON or CSV */ 15 | const result = (Buffer.from(decompressedData, 'utf8')).toString('base64'); 16 | success++; 17 | return { 18 | recordId: record.recordId, 19 | result: 'Ok', 20 | data: result, 21 | }; 22 | } catch (err) { 23 | failure++; 24 | return { 25 | recordId: record.recordId, 26 | result: 'ProcessingFailed', 27 | data: record.data, 28 | }; 29 | } 30 | }); 31 | console.log(`Processing completed. Successful records ${success}, Failed records ${failure}.`); 32 | callback(null, { 33 | records: output, 34 | }); 35 | }; 36 | -------------------------------------------------------------------------------- /javascript/kinesis-analytics-process-compressed-record/readme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amazon-archives/serverless-app-examples/9485c6ca6adc65994e5c5b0002039e4547d6c3d2/javascript/kinesis-analytics-process-compressed-record/readme -------------------------------------------------------------------------------- /javascript/kinesis-analytics-process-compressed-record/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Analytics record pre-processor that receives compressed 5 | (GZIP or Deflate compressed) JSON or CSV records as input and returns 6 | decompressed records with a processing status. 7 | Parameters: 8 | FunctionNameParameter: 9 | Type: String 10 | TableNameParameter: 11 | Type: String 12 | Resources: 13 | kinesisanalyticsprocesscompressedrecord: 14 | Type: 'AWS::Serverless::Function' 15 | Properties: 16 | Handler: index.handler 17 | Runtime: nodejs12.x 18 | CodeUri: . 19 | Description: >- 20 | An Amazon Kinesis Analytics record pre-processor that receives 21 | compressed (GZIP or Deflate compressed) JSON or CSV records as input and 22 | returns decompressed records with a processing status. 23 | MemorySize: 128 24 | Timeout: 3 25 | Policies: 26 | - LambdaInvokePolicy: 27 | FunctionName: !Ref FunctionNameParameter 28 | - DynamoDBCrudPolicy: 29 | TableName: !Ref TableNameParameter 30 | -------------------------------------------------------------------------------- /javascript/kinesis-analytics-process-compressed-record/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocationId": "invocationIdExample", 3 | "applicationArn": "arn:aws:kinesisanalytics:us-east-1:123456789012:application/example-application", 4 | "streamArn": "arn:aws:kinesis:us-east-1:123456789012:stream/example-stream", 5 | "records": [ 6 | { 7 | "recordId": "49571347871967966406409637155186850213682522142927749122", 8 | "data": "H4sIAAAAAAAA/6vmUspLzE1VslLKTsxNzFHS4VJKTEkpSi0uBgol5SRmKHHVAgDd1tysJAAAAA==" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /javascript/kinesis-analytics-process-record/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | console.log('Loading function'); 3 | 4 | exports.handler = (event, context, callback) => { 5 | /* Process the list of records */ 6 | const output = event.records.map((record) => ({ 7 | recordId: record.recordId, 8 | result: 'Ok', 9 | data: record.data, 10 | })); 11 | console.log(`Processing completed. Successful records ${output.length}.`); 12 | callback(null, { records: output }); 13 | }; 14 | -------------------------------------------------------------------------------- /javascript/kinesis-analytics-process-record/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/kinesis-analytics-process-record/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Analytics record pre-processor that receives JSON or CSV 5 | records as input and returns them with a processing status. Use this processor 6 | as a starting point for custom transformation logic. 7 | Parameters: 8 | FunctionNameParameter: 9 | Type: String 10 | TableNameParameter: 11 | Type: String 12 | Resources: 13 | kinesisanalyticsprocessrecord: 14 | Type: 'AWS::Serverless::Function' 15 | Properties: 16 | Handler: index.handler 17 | Runtime: nodejs12.x 18 | CodeUri: . 19 | Description: >- 20 | An Amazon Kinesis Analytics record pre-processor that receives JSON or 21 | CSV records as input and returns them with a processing status. Use this 22 | processor as a starting point for custom transformation logic. 23 | MemorySize: 128 24 | Timeout: 3 25 | Policies: 26 | - LambdaInvokePolicy: 27 | FunctionName: !Ref FunctionNameParameter 28 | - DynamoDBCrudPolicy: 29 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /javascript/kinesis-analytics-process-record/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocationId": "invocationIdExample", 3 | "applicationArn": "arn:aws:kinesisanalytics:us-east-1:123456789012:application/example-application", 4 | "streamArn": "arn:aws:kinesis:us-east-1:123456789012:stream/example-stream", 5 | "records": [ 6 | { 7 | "recordId": "49571347871967966406409637155186850213682522142927749122", 8 | "data": "VGhpcyBpcyBhIHRlc3QgZnJvbSBLaW5lc2lzIEFuYWx5dGljcw==" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /javascript/kinesis-firehose-apachelog-to-csv/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | console.log('Loading function'); 3 | 4 | /* Apache Log format parser */ 5 | const parser = /^([\d.]+) (\S+) (\S+) \[([\w:/]+\s[\+\-]\d{4})\] "(.+?)" (\d{3}) (\d+)/; 6 | 7 | exports.handler = (event, context, callback) => { 8 | let success = 0; // Number of valid entries found 9 | let failure = 0; // Number of invalid entries found 10 | 11 | /* Process the list of records and transform them */ 12 | const output = event.records.map((record) => { 13 | const entry = (Buffer.from(record.data, 'base64')).toString('utf8'); 14 | const match = parser.exec(entry); 15 | if (match) { 16 | /* Prepare CSV version from Apache log data */ 17 | const result = `${match[1]},${match[2]},${match[3]},${match[4]},${match[5]},${match[6]},${match[7]}\n`; 18 | const payload = (Buffer.from(result, 'utf8')).toString('base64'); 19 | success++; 20 | return { 21 | recordId: record.recordId, 22 | result: 'Ok', 23 | data: payload, 24 | }; 25 | } else { 26 | /* Failed event, notify the error and leave the record intact */ 27 | failure++; 28 | return { 29 | recordId: record.recordId, 30 | result: 'ProcessingFailed', 31 | data: record.data, 32 | }; 33 | } 34 | }); 35 | console.log(`Processing completed. Successful records ${success}, Failed records ${failure}.`); 36 | callback(null, { records: output }); 37 | }; 38 | -------------------------------------------------------------------------------- /javascript/kinesis-firehose-apachelog-to-csv/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/kinesis-firehose-apachelog-to-csv/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that converts input records from 5 | Apache Common Log format to CSV. 6 | Parameters: 7 | FunctionNameParameter: 8 | Type: String 9 | TableNameParameter: 10 | Type: String 11 | Resources: 12 | kinesisfirehoseapachelogtocsv: 13 | Type: 'AWS::Serverless::Function' 14 | Properties: 15 | Handler: index.handler 16 | Runtime: nodejs12.x 17 | CodeUri: . 18 | Description: >- 19 | An Amazon Kinesis Firehose stream processor that converts input records 20 | from Apache Common Log format to CSV. 21 | MemorySize: 128 22 | Timeout: 3 23 | Policies: 24 | - LambdaInvokePolicy: 25 | FunctionName: !Ref FunctionNameParameter 26 | - DynamoDBCrudPolicy: 27 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /javascript/kinesis-firehose-apachelog-to-csv/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocationId": "invocationIdExample", 3 | "region": "us-east-1", 4 | "records": [ 5 | { 6 | "recordId": "49546986683135544286507457936321625675700192471156785154", 7 | "approximateArrivalTimestamp": 1495072949453, 8 | "data": "NjQuMjQyLjg4LjEwIC0gLSBbMDcvTWFyLzIwMDQ6MTY6MTA6MDIgLTA4MDBdICJHRVQgL21haWxtYW4vbGlzdGluZm8vaHNkaXZpc2lvbiBIVFRQLzEuMSIgMjAwIDYyOTE==" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /javascript/kinesis-firehose-apachelog-to-json/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that converts input records from 5 | Apache Common Log format to JSON. 6 | Parameters: 7 | FunctionNameParameter: 8 | Type: String 9 | TableNameParameter: 10 | Type: String 11 | Resources: 12 | kinesisfirehoseapachelogtojson: 13 | Type: 'AWS::Serverless::Function' 14 | Properties: 15 | Handler: index.handler 16 | Runtime: nodejs12.x 17 | CodeUri: . 18 | Description: >- 19 | An Amazon Kinesis Firehose stream processor that converts input records 20 | from Apache Common Log format to JSON. 21 | MemorySize: 128 22 | Timeout: 3 23 | Policies: 24 | - LambdaInvokePolicy: 25 | FunctionName: !Ref FunctionNameParameter 26 | - DynamoDBCrudPolicy: 27 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /javascript/kinesis-firehose-apachelog-to-json/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocationId": "invocationIdExample", 3 | "region": "us-east-1", 4 | "records": [ 5 | { 6 | "recordId": "49546986683135544286507457936321625675700192471156785154", 7 | "approximateArrivalTimestamp": 1495072949453, 8 | "data": "NjQuMjQyLjg4LjEwIC0gLSBbMDcvTWFyLzIwMDQ6MTY6MTA6MDIgLTA4MDBdICJHRVQgL21haWxtYW4vbGlzdGluZm8vaHNkaXZpc2lvbiBIVFRQLzEuMSIgMjAwIDYyOTE==" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /javascript/kinesis-firehose-cloudwatch-logs-processor/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that extracts individual log events from records sent by Cloudwatch Logs subscription filters. 5 | Parameters: 6 | BucketNameParameter: 7 | Type: String 8 | Resources: 9 | kinesisfirehosecloudwatchlogsprocessor: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | An Amazon Kinesis Firehose stream processor that extracts individual log events from records sent by Cloudwatch Logs subscription filters. 17 | MemorySize: 128 18 | Timeout: 3 19 | Policies: 20 | - S3CrudPolicy: 21 | BucketName: !Ref BucketNameParameter 22 | Outputs: 23 | FunctionName: 24 | Description: Name of the Lambda function name 25 | Value: 26 | Ref: kinesisfirehosecloudwatchlogsprocessor 27 | FunctionArn: 28 | Description: ARN of the Lambda function name 29 | Value: 30 | Fn::GetAtt: 31 | - kinesisfirehosecloudwatchlogsprocessor 32 | - Arn -------------------------------------------------------------------------------- /javascript/kinesis-firehose-process-record-streams-as-source/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | console.log('Loading function'); 3 | 4 | exports.handler = (event, context, callback) => { 5 | /*Print streams as source only data here*/ 6 | event.records.forEach((record) => { 7 | console.log(record.kinesisRecordMetadata.sequenceNumber); 8 | console.log(record.kinesisRecordMetadata.subsequenceNumber); 9 | console.log(record.kinesisRecordMetadata.partitionKey); 10 | console.log(record.kinesisRecordMetadata.shardId); 11 | console.log(record.kinesisRecordMetadata.approximateArrivalTimestamp); 12 | }); 13 | /* Process the list of records and transform them */ 14 | const output = event.records.map((record) => ({ 15 | /* This transformation is the "identity" transformation, the data is left intact */ 16 | recordId: record.recordId, 17 | result: 'Ok', 18 | data: record.data, 19 | })); 20 | console.log(`Processing completed. Successful records ${output.length}.`); 21 | callback(null, { records: output }); 22 | }; 23 | -------------------------------------------------------------------------------- /javascript/kinesis-firehose-process-record-streams-as-source/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/kinesis-firehose-process-record-streams-as-source/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that accesses the Kinesis Streams records in the input and returns them with a processing status. 5 | Parameters: 6 | FunctionNameParameter: 7 | Type: String 8 | TableNameParameter: 9 | Type: String 10 | Resources: 11 | kinesisfirehoseprocessrecordstreamsassource: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: index.handler 15 | Runtime: nodejs12.x 16 | CodeUri: . 17 | Description: >- 18 | An Amazon Kinesis Firehose stream processor that accesses the Kinesis Streams records in the input and returns them with a processing status. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - LambdaInvokePolicy: 23 | FunctionName: !Ref FunctionNameParameter 24 | - DynamoDBCrudPolicy: 25 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /javascript/kinesis-firehose-process-record-streams-as-source/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocationId": "invocationIdExample", 3 | "deliverySteamArn": "arn:aws:kinesis:EXAMPLE", 4 | "region": "us-east-1", 5 | "records": [ 6 | { 7 | "recordId": "49546986683135544286507457936321625675700192471156785154", 8 | "approximateArrivalTimestamp": 1495072949453, 9 | "kinesisRecordMetadata": { 10 | "sequenceNumber": "49545115243490985018280067714973144582180062593244200961", 11 | "subsequenceNumber": "123456", 12 | "partitionKey": "partitionKey-03", 13 | "shardId": "shardId-000000000000", 14 | "approximateArrivalTimestamp": 1495072949453 15 | }, 16 | "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /javascript/kinesis-firehose-process-record/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | console.log('Loading function'); 3 | 4 | exports.handler = (event, context, callback) => { 5 | /* Process the list of records and transform them */ 6 | const output = event.records.map((record) => ({ 7 | /* This transformation is the "identity" transformation, the data is left intact */ 8 | recordId: record.recordId, 9 | result: 'Ok', 10 | data: record.data, 11 | })); 12 | console.log(`Processing completed. Successful records ${output.length}.`); 13 | callback(null, { records: output }); 14 | }; 15 | -------------------------------------------------------------------------------- /javascript/kinesis-firehose-process-record/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/kinesis-firehose-process-record/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that accesses the records in the 5 | input and returns them with a processing status. 6 | Parameters: 7 | FunctionNameParameter: 8 | Type: String 9 | TableNameParameter: 10 | Type: String 11 | Resources: 12 | kinesisfirehoseprocessrecord: 13 | Type: 'AWS::Serverless::Function' 14 | Properties: 15 | Handler: index.handler 16 | Runtime: nodejs12.x 17 | CodeUri: . 18 | Description: >- 19 | An Amazon Kinesis Firehose stream processor that accesses the records in 20 | the input and returns them with a processing status. 21 | MemorySize: 128 22 | Timeout: 3 23 | Policies: 24 | - LambdaInvokePolicy: 25 | FunctionName: !Ref FunctionNameParameter 26 | - DynamoDBCrudPolicy: 27 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /javascript/kinesis-firehose-process-record/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocationId": "invocationIdExample", 3 | "deliveryStreamArn": "arn:aws:kinesis:EXAMPLE", 4 | "region": "us-east-1", 5 | "records": [ 6 | { 7 | "recordId": "49546986683135544286507457936321625675700192471156785154", 8 | "approximateArrivalTimestamp": 1495072949453, 9 | "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /javascript/kinesis-firehose-syslog-to-csv/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/kinesis-firehose-syslog-to-csv/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that converts input records from RFC3164 Syslog format to CSV. 5 | Parameters: 6 | FunctionNameParameter: 7 | Type: String 8 | TableNameParameter: 9 | Type: String 10 | Resources: 11 | kinesisfirehosesyslogtocsv: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: index.handler 15 | Runtime: nodejs12.x 16 | CodeUri: . 17 | Description: >- 18 | An Amazon Kinesis Firehose stream processor that converts input records from RFC3164 Syslog format to CSV. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - LambdaInvokePolicy: 23 | FunctionName: !Ref FunctionNameParameter 24 | - DynamoDBCrudPolicy: 25 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /javascript/kinesis-firehose-syslog-to-csv/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocationId": "fir", 3 | "region": "us-east-1", 4 | "records": [ 5 | { 6 | "recordId": "49546986683135544286507457936321625675700192471156785154", 7 | "approximateArrivalTimestamp": 1495072949453, 8 | "data": "SmFuIDEyIDA2OjMwOjAwIDEuMi4zLjQgYXBhY2hlX3NlcnZlcjogMS4yLjMuNCAtIC0gWzEyL0phbi8yMDExOjA2OjI5OjU5ICswMTAwXSAiR0VUIC9mb28vYmFyLmh0bWwgSFRUUC8xLjEiIDMwMSA5NiAiLSIgIk1vemlsbGEvNS4wIChXaW5kb3dzOyBVOyBXaW5kb3dzIE5UIDUuMTsgZnI7IHJ2OjEuOS4yLjEyKSBHZWNrby8yMDEwMTAyNiBGaXJlZm94LzMuNi4xMiAoIC5ORVQgQ0xSIDMuNS4zMDcyOSkiIFBJRCAxODkwNCBUaW1lIFRha2VuIDA=" 9 | }, 10 | { 11 | "recordId": "49546986683135544286507457936321625675700192471156785154", 12 | "approximateArrivalTimestamp": "2012-04-23T18:25:43.511Z", 13 | "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=" 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /javascript/kinesis-firehose-syslog-to-json/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/kinesis-firehose-syslog-to-json/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that converts input records from RFC3164 Syslog format to JSON. 5 | Parameters: 6 | FunctionNameParameter: 7 | Type: String 8 | TableNameParameter: 9 | Type: String 10 | Resources: 11 | kinesisfirehosesyslogtojson: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: index.handler 15 | Runtime: nodejs12.x 16 | CodeUri: . 17 | Description: >- 18 | An Amazon Kinesis Firehose stream processor that converts input records from RFC3164 Syslog format to JSON. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - LambdaInvokePolicy: 23 | FunctionName: !Ref FunctionNameParameter 24 | - DynamoDBCrudPolicy: 25 | TableName: !Ref TableNameParameter 26 | -------------------------------------------------------------------------------- /javascript/kinesis-firehose-syslog-to-json/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocationId": "fir", 3 | "region": "us-east-1", 4 | "records": [ 5 | { 6 | "recordId": "49546986683135544286507457936321625675700192471156785154", 7 | "approximateArrivalTimestamp": 1495072949453, 8 | "data": "SmFuIDEyIDA2OjMwOjAwIDEuMi4zLjQgYXBhY2hlX3NlcnZlcjogMS4yLjMuNCAtIC0gWzEyL0phbi8yMDExOjA2OjI5OjU5ICswMTAwXSAiR0VUIC9mb28vYmFyLmh0bWwgSFRUUC8xLjEiIDMwMSA5NiAiLSIgIk1vemlsbGEvNS4wIChXaW5kb3dzOyBVOyBXaW5kb3dzIE5UIDUuMTsgZnI7IHJ2OjEuOS4yLjEyKSBHZWNrby8yMDEwMTAyNiBGaXJlZm94LzMuNi4xMiAoIC5ORVQgQ0xSIDMuNS4zMDcyOSkiIFBJRCAxODkwNCBUaW1lIFRha2VuIDA=" 9 | }, 10 | { 11 | "recordId": "49546986683135544286507457936321625675700192471156785154", 12 | "approximateArrivalTimestamp": "2012-04-23T18:25:43.511Z", 13 | "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=" 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /javascript/kinesis-process-record/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.log('Loading function'); 4 | 5 | exports.handler = (event, context, callback) => { 6 | //console.log('Received event:', JSON.stringify(event, null, 2)); 7 | event.Records.forEach((record) => { 8 | // Kinesis data is base64 encoded so decode here 9 | const payload = new Buffer(record.kinesis.data, 'base64').toString('ascii'); 10 | console.log('Decoded payload:', payload); 11 | }); 12 | callback(null, `Successfully processed ${event.Records.length} records.`); 13 | }; 14 | -------------------------------------------------------------------------------- /javascript/kinesis-process-record/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/kinesis-process-record/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon Kinesis stream processor that logs the data being published. 4 | Parameters: 5 | FunctionNameParameter: 6 | Type: String 7 | TableNameParameter: 8 | Type: String 9 | Resources: 10 | kinesisprocessrecord: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: index.handler 14 | Runtime: nodejs12.x 15 | CodeUri: . 16 | Description: An Amazon Kinesis stream processor that logs the data being published. 17 | MemorySize: 128 18 | Timeout: 3 19 | Policies: 20 | - LambdaInvokePolicy: 21 | FunctionName: !Ref FunctionNameParameter 22 | - DynamoDBCrudPolicy: 23 | TableName: !Ref TableNameParameter 24 | Events: 25 | Kinesis1: 26 | Type: Kinesis 27 | Properties: 28 | Stream: 29 | 'Fn::GetAtt': 30 | - KinesisStream1 31 | - Arn 32 | StartingPosition: TRIM_HORIZON 33 | BatchSize: 100 34 | KinesisStream1: 35 | Type: 'AWS::Kinesis::Stream' 36 | Properties: 37 | ShardCount: 1 38 | -------------------------------------------------------------------------------- /javascript/kinesis-process-record/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "kinesis": { 5 | "partitionKey": "partitionKey-03", 6 | "kinesisSchemaVersion": "1.0", 7 | "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=", 8 | "sequenceNumber": "49545115243490985018280067714973144582180062593244200961", 9 | "approximateArrivalTimestamp": 1428537600.0 10 | }, 11 | "eventSource": "aws:kinesis", 12 | "eventID": "shardId-000000000000:49545115243490985018280067714973144582180062593244200961", 13 | "invokeIdentityArn": "arn:aws:iam::EXAMPLE", 14 | "eventVersion": "1.0", 15 | "eventName": "aws:kinesis:record", 16 | "eventSourceARN": "arn:aws:kinesis:EXAMPLE", 17 | "awsRegion": "us-east-1" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /javascript/lambda-test-harness/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/lambda-test-harness/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Provides a simple framework for conducting various tests of your Lambda functions. 5 | Parameters: 6 | FunctionNameParameter: 7 | Type: String 8 | TableNameParameter: 9 | Type: String 10 | Resources: 11 | lambdatestharness: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: index.handler 15 | Runtime: nodejs12.x 16 | CodeUri: . 17 | Description: >- 18 | Provides a simple framework for conducting various tests of your Lambda functions. 19 | MemorySize: 128 20 | Timeout: 60 21 | Policies: 22 | - LambdaInvokePolicy: 23 | FunctionName: !Ref FunctionNameParameter 24 | - DynamoDBCrudPolicy: 25 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /javascript/lex-book-trip/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/lex-book-trip/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.20.0 2 | -------------------------------------------------------------------------------- /javascript/lex-book-trip/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Book details of a visit, using Amazon Lex to perform natural language 5 | understanding 6 | Parameters: 7 | KeyIdParameter: 8 | Type: String 9 | Resources: 10 | lexbooktrip: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: index.handler 14 | Runtime: nodejs12.x 15 | CodeUri: . 16 | Description: >- 17 | Book details of a visit, using Amazon Lex to perform natural language 18 | understanding 19 | MemorySize: 128 20 | Timeout: 10 21 | Policies: 22 | - KMSDecryptPolicy: 23 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/lex-book-trip/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "messageVersion": "1.0", 3 | "invocationSource": "DialogCodeHook", 4 | "userId": "John", 5 | "sessionAttributes": {}, 6 | "bot": { 7 | "name": "BookTrip", 8 | "alias": "$LATEST", 9 | "version": "$LATEST" 10 | }, 11 | "outputDialogMode": "Text", 12 | "currentIntent": { 13 | "name": "BookHotel", 14 | "slots": { 15 | "Location": "Chicago", 16 | "CheckInDate": "2030-11-08", 17 | "Nights": 4, 18 | "RoomType": "queen" 19 | }, 20 | "confirmationStatus": "None" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /javascript/lex-make-appointment/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/lex-make-appointment/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Schedule a dentist appointment, using Amazon Lex to perform natural language 5 | understanding 6 | Parameters: 7 | KeyIdParameter: 8 | Type: String 9 | Resources: 10 | lexmakeappointment: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: index.handler 14 | Runtime: nodejs12.x 15 | CodeUri: . 16 | Description: >- 17 | Schedule a dentist appointment, using Amazon Lex to perform natural 18 | language understanding 19 | MemorySize: 128 20 | Timeout: 10 21 | Policies: 22 | - KMSDecryptPolicy: 23 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/lex-make-appointment/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "messageVersion": "1.0", 3 | "invocationSource": "DialogCodeHook", 4 | "userId": "John", 5 | "sessionAttributes": {}, 6 | "bot": { 7 | "name": "MakeAppointment", 8 | "alias": "$LATEST", 9 | "version": "$LATEST" 10 | }, 11 | "outputDialogMode": "Text", 12 | "currentIntent": { 13 | "name": "MakeAppointment", 14 | "slots": { 15 | "AppointmentType": "whitening", 16 | "Date": "2030-11-08", 17 | "Time": "10:00" 18 | }, 19 | "confirmationStatus": "None" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /javascript/lex-order-flowers/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /javascript/lex-order-flowers/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: 'Order flowers, using Amazon Lex to perform natural language understanding' 4 | Parameters: 5 | KeyIdParameter: 6 | Type: String 7 | Resources: 8 | lexorderflowers: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: >- 15 | Order flowers, using Amazon Lex to perform natural language 16 | understanding 17 | MemorySize: 128 18 | Timeout: 10 19 | Policies: 20 | - KMSDecryptPolicy: 21 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /javascript/lex-order-flowers/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "messageVersion": "1.0", 3 | "invocationSource": "DialogCodeHook", 4 | "userId": "John", 5 | "sessionAttributes": {}, 6 | "bot": { 7 | "name": "OrderFlowers", 8 | "alias": "$LATEST", 9 | "version": "$LATEST" 10 | }, 11 | "outputDialogMode": "Text", 12 | "currentIntent": { 13 | "name": "OrderFlowers", 14 | "slots": { 15 | "FlowerType": "lilies", 16 | "PickupDate": "2030-11-08", 17 | "PickupTime": "10:00" 18 | }, 19 | "confirmationStatus": "None" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /javascript/microservice-http-endpoint/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.log('Loading function'); 4 | 5 | const doc = require('dynamodb-doc'); 6 | 7 | const dynamo = new doc.DynamoDB(); 8 | 9 | 10 | /** 11 | * Demonstrates a simple HTTP endpoint using API Gateway. You have full 12 | * access to the request and response payload, including headers and 13 | * status code. 14 | * 15 | * To scan a DynamoDB table, make a GET request with the TableName as a 16 | * query string parameter. To put, update, or delete an item, make a POST, 17 | * PUT, or DELETE request respectively, passing in the payload to the 18 | * DynamoDB API as a JSON body. 19 | */ 20 | exports.handler = (event, context, callback) => { 21 | //console.log('Received event:', JSON.stringify(event, null, 2)); 22 | 23 | const done = (err, res) => callback(null, { 24 | statusCode: err ? '400' : '200', 25 | body: err ? err.message : JSON.stringify(res), 26 | headers: { 27 | 'Content-Type': 'application/json', 28 | }, 29 | }); 30 | 31 | switch (event.httpMethod) { 32 | case 'DELETE': 33 | dynamo.deleteItem(JSON.parse(event.body), done); 34 | break; 35 | case 'GET': 36 | dynamo.scan({ TableName: event.queryStringParameters.TableName }, done); 37 | break; 38 | case 'POST': 39 | dynamo.putItem(JSON.parse(event.body), done); 40 | break; 41 | case 'PUT': 42 | dynamo.updateItem(JSON.parse(event.body), done); 43 | break; 44 | default: 45 | done(new Error(`Unsupported method "${event.httpMethod}"`)); 46 | } 47 | }; 48 | -------------------------------------------------------------------------------- /javascript/microservice-http-endpoint/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs-upgrade-functions", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "throat": "^4.0.0" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /javascript/microservice-http-endpoint/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway. 5 | Parameters: 6 | TableNameParameter: 7 | Type: String 8 | Resources: 9 | microservicehttpendpoint: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway. 17 | MemorySize: 512 18 | Timeout: 10 19 | Policies: 20 | - DynamoDBCrudPolicy: 21 | TableName: !Ref TableNameParameter 22 | Events: 23 | Api1: 24 | Type: Api 25 | Properties: 26 | Path: /MyResource 27 | Method: ANY -------------------------------------------------------------------------------- /javascript/node-exec/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const exec = require('child_process').exec; 4 | 5 | exports.handler = (event, context, callback) => { 6 | if (!event.cmd) { 7 | return callback('Please specify a command to run as event.cmd'); 8 | } 9 | const child = exec(event.cmd, (error) => { 10 | // Resolve with result of process 11 | callback(error, 'Process complete!'); 12 | }); 13 | 14 | // Log process stdout and stderr 15 | child.stdout.on('data', console.log); 16 | child.stderr.on('data', console.error); 17 | }; 18 | -------------------------------------------------------------------------------- /javascript/node-exec/response/detect-faces-response.json: -------------------------------------------------------------------------------- 1 | {"FaceDetails": [{"BoundingBox": {"Width": 0.37220844626426697, "Top": 0.097087375819683075, "Height": 0.56011950969696045, "Left": 0.60049629211425781}, "Landmarks": [{"Y": 0.29746288061141968, "X": 0.74046933650970459, "Type": "eyeLeft"}, {"Y": 0.39010941982269287, "X": 0.85312539339065552, "Type": "eyeRight"}, {"Y": 0.43307429552078247, "X": 0.80672019720077515, "Type": "nose"}, {"Y": 0.51852452754974365, "X": 0.7020527720451355, "Type": "mouthLeft"}, {"Y": 0.56728619337081909, "X": 0.78770458698272705, "Type": "mouthRight"}], "Pose": {"Yaw": 25.503475189208984, "Roll": 27.584785461425781, "Pitch": 16.070867538452148}, "Quality": {"Sharpness": 140.0, "Brightness": 45.784263610839844}, "Confidence": 99.999870300292969}], "ResponseMetadata": {"RetryAttempts": 0, "HTTPStatusCode": 200, "RequestId": "5ec8d1f8-a853-11e6-ae5a-0f6c6597f701", "HTTPHeaders": {"date": "Fri, 11 Nov 2016 21:11:12 GMT", "x-amzn-requestid": "5ec8d1f8-a853-11e6-ae5a-0f6c6597f701", "content-length": "699", "content-type": "application/x-amz-json-1.1", "connection": "keep-alive"}}, "OrientationCorrection": "ROTATE_0"} 2 | -------------------------------------------------------------------------------- /javascript/node-exec/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Demonstrates running an external process using the Node.js child_process module. 5 | Parameters: 6 | BucketNameParameter: 7 | Type: String 8 | CollectionIdParameter: 9 | Type: String 10 | Resources: 11 | nodeexec: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: index.handler 15 | Runtime: nodejs12.x 16 | CodeUri: . 17 | Description: >- 18 | Demonstrates running an external process using the Node.js child_process module. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - S3CrudPolicy: 23 | BucketName: !Ref BucketNameParameter 24 | - RekognitionNoDataAccessPolicy: 25 | CollectionId: !Ref CollectionIdParameter 26 | - RekognitionWriteOnlyAccessPolicy: 27 | CollectionId: !Ref CollectionIdParameter -------------------------------------------------------------------------------- /javascript/node-exec/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmd": "pwd" 3 | } 4 | -------------------------------------------------------------------------------- /javascript/s3-get-object/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.log('Loading function'); 4 | 5 | const aws = require('aws-sdk'); 6 | 7 | const s3 = new aws.S3({ apiVersion: '2006-03-01' }); 8 | 9 | 10 | exports.handler = (event, context, callback) => { 11 | //console.log('Received event:', JSON.stringify(event, null, 2)); 12 | 13 | // Get the object from the event and show its content type 14 | const bucket = event.Records[0].s3.bucket.name; 15 | const key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' ')); 16 | const params = { 17 | Bucket: bucket, 18 | Key: key, 19 | }; 20 | s3.getObject(params, (err, data) => { 21 | if (err) { 22 | console.log(err); 23 | const message = `Error getting object ${key} from bucket ${bucket}. Make sure they exist and your bucket is in the same region as this function.`; 24 | console.log(message); 25 | callback(message); 26 | } else { 27 | console.log('CONTENT TYPE:', data.ContentType); 28 | callback(null, data.ContentType); 29 | } 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /javascript/s3-get-object/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon S3 trigger that retrieves metadata for the object that has been 5 | updated. 6 | Parameters: 7 | BucketNamePrefix: 8 | Type: String 9 | Default: sam-example 10 | Resources: 11 | s3getobject: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: index.handler 15 | Runtime: nodejs12.x 16 | CodeUri: . 17 | Description: >- 18 | An Amazon S3 trigger that retrieves metadata for the object that has 19 | been updated. 20 | MemorySize: 128 21 | Timeout: 3 22 | Policies: 23 | - S3CrudPolicy: 24 | BucketName: !Sub "${BucketNamePrefix}-get-object" 25 | Events: 26 | BucketEvent1: 27 | Type: S3 28 | Properties: 29 | Bucket: !Ref Bucket1 30 | Events: 31 | - 's3:ObjectCreated:*' 32 | Bucket1: 33 | Type: 'AWS::S3::Bucket' 34 | Properties: 35 | BucketName: !Sub "${BucketNamePrefix}-get-object" 36 | -------------------------------------------------------------------------------- /javascript/s3-get-object/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "eventVersion": "2.0", 5 | "eventSource": "aws:s3", 6 | "awsRegion": "us-east-1", 7 | "eventTime": "1970-01-01T00:00:00.000Z", 8 | "eventName": "ObjectCreated:Put", 9 | "userIdentity": { 10 | "principalId": "EXAMPLE" 11 | }, 12 | "requestParameters": { 13 | "sourceIPAddress": "127.0.0.1" 14 | }, 15 | "responseElements": { 16 | "x-amz-request-id": "EXAMPLE123456789", 17 | "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH" 18 | }, 19 | "s3": { 20 | "s3SchemaVersion": "1.0", 21 | "configurationId": "testConfigRule", 22 | "bucket": { 23 | "name": "example-bucket-get-object", 24 | "ownerIdentity": { 25 | "principalId": "EXAMPLE" 26 | }, 27 | "arn": "arn:aws:s3:::example-bucket-get-object" 28 | }, 29 | "object": { 30 | "key": "test/key", 31 | "size": 1024, 32 | "eTag": "0123456789abcdef0123456789abcdef", 33 | "sequencer": "0A1B2C3D4E5F678901" 34 | } 35 | } 36 | } 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /javascript/ses-notification-nodejs/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon SES notification handler for processing bounces, complaints and deliveries. 5 | Parameters: 6 | TableNameParameter: 7 | Type: String 8 | Resources: 9 | sesnotificationnodejs: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: index.handler 13 | Runtime: nodejs12.x 14 | CodeUri: . 15 | Description: >- 16 | An Amazon SES notification handler for processing bounces, complaints and deliveries. 17 | MemorySize: 128 18 | Timeout: 3 19 | Policies: 20 | - DynamoDBCrudPolicy: 21 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /javascript/simple-mobile-backend/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.log('Loading function'); 4 | 5 | const doc = require('dynamodb-doc'); 6 | 7 | const dynamo = new doc.DynamoDB(); 8 | 9 | 10 | /** 11 | * Provide an event that contains the following keys: 12 | * 13 | * - operation: one of the operations in the switch statement below 14 | * - tableName: required for operations that interact with DynamoDB 15 | * - payload: a parameter to pass to the operation being performed 16 | */ 17 | exports.handler = (event, context, callback) => { 18 | //console.log('Received event:', JSON.stringify(event, null, 2)); 19 | 20 | const operation = event.operation; 21 | const payload = event.payload; 22 | 23 | if (event.tableName) { 24 | payload.TableName = event.tableName; 25 | } 26 | 27 | switch (operation) { 28 | case 'create': 29 | dynamo.putItem(payload, callback); 30 | break; 31 | case 'read': 32 | dynamo.getItem(payload, callback); 33 | break; 34 | case 'update': 35 | dynamo.updateItem(payload, callback); 36 | break; 37 | case 'delete': 38 | dynamo.deleteItem(payload, callback); 39 | break; 40 | case 'list': 41 | dynamo.scan(payload, callback); 42 | break; 43 | case 'echo': 44 | callback(null, payload); 45 | break; 46 | case 'ping': 47 | callback(null, 'pong'); 48 | break; 49 | default: 50 | callback(new Error(`Unrecognized operation "${operation}"`)); 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /javascript/simple-mobile-backend/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: A simple mobile backend (read/write to DynamoDB). 4 | Parameters: 5 | TableNameParameter: 6 | Type: String 7 | Resources: 8 | simplemobilebackend: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: index.handler 12 | Runtime: nodejs12.x 13 | CodeUri: . 14 | Description: A simple mobile backend (read/write to DynamoDB). 15 | MemorySize: 128 16 | Timeout: 3 17 | Policies: 18 | - DynamoDBCrudPolicy: 19 | TableName: !Ref TableNameParameter 20 | -------------------------------------------------------------------------------- /javascript/slack-echo-command/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | A function that handles a Slack slash command and echoes the details back to 5 | the user. 6 | Parameters: 7 | KeyIdParameter: 8 | Type: String 9 | Resources: 10 | slackechocommand: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: index.handler 14 | Runtime: nodejs12.x 15 | CodeUri: . 16 | Description: >- 17 | A function that handles a Slack slash command and echoes the details 18 | back to the user. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - KMSDecryptPolicy: 23 | KeyId: !Ref KeyIdParameter 24 | Events: 25 | Api1: 26 | Type: Api 27 | Properties: 28 | Path: /MyResource 29 | Method: ANY 30 | Environment: 31 | Variables: 32 | kmsEncryptedToken: 33 | -------------------------------------------------------------------------------- /javascript/sns-message/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.log('Loading function'); 4 | 5 | exports.handler = (event, context, callback) => { 6 | //console.log('Received event:', JSON.stringify(event, null, 2)); 7 | const message = event.Records[0].Sns.Message; 8 | console.log('From SNS:', message); 9 | callback(null, message); 10 | }; 11 | -------------------------------------------------------------------------------- /javascript/sns-message/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon SNS trigger that logs the message pushed to the SNS topic. 4 | Resources: 5 | snsmessage: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: index.handler 9 | Runtime: nodejs12.x 10 | CodeUri: . 11 | Description: An Amazon SNS trigger that logs the message pushed to the SNS topic. 12 | MemorySize: 128 13 | Timeout: 3 14 | Events: 15 | SNS1: 16 | Type: SNS 17 | Properties: 18 | Topic: 19 | Ref: SNSTopic1 20 | SNSTopic1: 21 | Type: 'AWS::SNS::Topic' 22 | -------------------------------------------------------------------------------- /javascript/sns-message/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "EventSource": "aws:sns", 5 | "EventVersion": "1.0", 6 | "EventSubscriptionArn": "arn:aws:sns:us-east-1::ExampleTopic", 7 | "Sns": { 8 | "Type": "Notification", 9 | "MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e", 10 | "TopicArn": "arn:aws:sns:us-east-1:123456789012:ExampleTopic", 11 | "Subject": "example subject", 12 | "Message": "example message", 13 | "Timestamp": "1970-01-01T00:00:00.000Z", 14 | "SignatureVersion": "1", 15 | "Signature": "EXAMPLE", 16 | "SigningCertUrl": "EXAMPLE", 17 | "UnsubscribeUrl": "EXAMPLE", 18 | "MessageAttributes": { 19 | "Test": { 20 | "Type": "String", 21 | "Value": "TestString" 22 | }, 23 | "TestBinary": { 24 | "Type": "Binary", 25 | "Value": "TestBinary" 26 | } 27 | } 28 | } 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /javascript/sqs-poller/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Periodically polls an SQS queue and asynchronously consumes each message. 4 | Parameters: 5 | QueueNameParameter: 6 | Type: String 7 | Description: SQS queue name. 8 | QueueUrlParameter: 9 | Type: String 10 | AllowedPattern: '^https:\/\/sqs\.[a-z\-0-9]+\.amazonaws\.com(?:.cn)?\/[0-9]{12}\/.{1,80}$' 11 | Resources: 12 | sqspoller: 13 | Type: 'AWS::Serverless::Function' 14 | Properties: 15 | Handler: index.handler 16 | Runtime: nodejs12.x 17 | CodeUri: . 18 | Description: >- 19 | Periodically polls an SQS queue and asynchronously consumes each message. 20 | MemorySize: 128 21 | Timeout: 10 22 | Policies: 23 | - SQSPollerPolicy: 24 | QueueName: !Ref QueueNameParameter 25 | Environment: 26 | Variables: 27 | queueUrl: !Ref QueueUrlParameter 28 | -------------------------------------------------------------------------------- /javascript/step-functions-error/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.handler = (event, context, callback) => { 4 | function CustomError(message) { 5 | this.name = 'CustomError'; 6 | this.message = message; 7 | } 8 | CustomError.prototype = new Error(); 9 | 10 | const error = new CustomError('This is a custom error!'); 11 | callback(error); 12 | }; 13 | -------------------------------------------------------------------------------- /javascript/step-functions-error/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An AWS Lambda function that throws an error. AWS Step Functions state machines can be configured to handle (catch or retry) this error. 5 | Resources: 6 | stepfunctionserror: 7 | Type: 'AWS::Serverless::Function' 8 | Properties: 9 | Handler: index.handler 10 | Runtime: nodejs12.x 11 | CodeUri: . 12 | Description: >- 13 | An AWS Lambda function that throws an error. AWS Step Functions state machines can be configured to handle (catch or retry) this error. 14 | MemorySize: 128 15 | Timeout: 3 16 | Policies: 17 | - CloudWatchPutMetricPolicy: {} 18 | -------------------------------------------------------------------------------- /javascript/sumologic-process-logs/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Pushes CWL logs to SumoLogic. 4 | Resources: 5 | sumologicprocesslogs: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: index.handler 9 | Runtime: nodejs12.x 10 | CodeUri: . 11 | Description: Pushes CWL logs to SumoLogic. 12 | MemorySize: 128 13 | Timeout: 10 14 | Policies: 15 | - CloudWatchPutMetricPolicy: {} -------------------------------------------------------------------------------- /javascript/twilio-conference/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Allows multiple people to chat together in a conference room. 4 | Resources: 5 | twilioconference: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: index.handler 9 | Runtime: nodejs12.x 10 | CodeUri: . 11 | Description: Allows multiple people to chat together in a conference room. 12 | MemorySize: 128 13 | Timeout: 15 14 | Policies: 15 | - CloudWatchPutMetricPolicy: {} 16 | Events: 17 | Api1: 18 | Type: Api 19 | Properties: 20 | Path: /MyResource 21 | Method: ANY 22 | -------------------------------------------------------------------------------- /javascript/twilio-forward/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Forward a call to another phone number. 4 | Resources: 5 | twilioforward: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: index.handler 9 | Runtime: nodejs12.x 10 | CodeUri: . 11 | Description: Forward a call to another phone number. 12 | MemorySize: 128 13 | Timeout: 15 14 | Policies: 15 | - CloudWatchPutMetricPolicy: {} 16 | Events: 17 | Api1: 18 | Type: Api 19 | Properties: 20 | Path: /MyResource 21 | Method: ANY 22 | -------------------------------------------------------------------------------- /javascript/twilio-menu/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Play a greeting, and wait for the caller to press one or more digits on their keypad. 5 | Resources: 6 | twiliomenu: 7 | Type: 'AWS::Serverless::Function' 8 | Properties: 9 | Handler: index.handler 10 | Runtime: nodejs12.x 11 | CodeUri: . 12 | Description: >- 13 | Play a greeting, and wait for the caller to press one or more digits on their keypad. 14 | MemorySize: 128 15 | Timeout: 15 16 | Policies: 17 | - CloudWatchPutMetricPolicy: {} 18 | Events: 19 | Api1: 20 | Type: Api 21 | Properties: 22 | Path: /MyResource 23 | Method: ANY 24 | -------------------------------------------------------------------------------- /javascript/twilio-simple-blueprint/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.log('Loading function'); 4 | 5 | const output = ` 6 | 7 | 8 | 9 | Hello Amazon, this is Twilio powered by Lambda 10 | 11 | `; 12 | 13 | exports.handler = (event, context, callback) => callback(null, { 14 | statusCode: '200', 15 | body: output.trim(), 16 | headers: { 17 | 'Content-Type': 'application/xml', 18 | }, 19 | }); 20 | -------------------------------------------------------------------------------- /javascript/twilio-simple-blueprint/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: A simple backend for handling events sent from Twilio. 4 | Resources: 5 | twiliosimpleblueprint: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: index.handler 9 | Runtime: nodejs12.x 10 | CodeUri: . 11 | Description: A simple backend for handling events sent from Twilio. 12 | MemorySize: 128 13 | Timeout: 15 14 | Policies: 15 | - CloudWatchPutMetricPolicy: {} 16 | Events: 17 | Api1: 18 | Type: Api 19 | Properties: 20 | Path: /MyResource 21 | Method: ANY 22 | -------------------------------------------------------------------------------- /python/alexa-skills-kit-color-expert-python/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alexa-skill-kit-sdk-triviaskill", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "alexa-sdk": "^1.0.10" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /python/alexa-skills-kit-color-expert-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Demonstrates a basic skill built with the Amazon Alexa Skills Kit. 4 | Parameters: 5 | TopicNameParameter: 6 | Type: String 7 | Resources: 8 | alexaskillskitcolorexpertpython: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: lambda_function.lambda_handler 12 | Runtime: python2.7 13 | CodeUri: . 14 | Description: Demonstrates a basic skill built with the Amazon Alexa Skills Kit. 15 | MemorySize: 128 16 | Timeout: 3 17 | Policies: 18 | - SNSPublishMessagePolicy: 19 | TopicName: !Ref TopicNameParameter 20 | Events: 21 | AlexaSkillEvent: 22 | Type: AlexaSkill 23 | -------------------------------------------------------------------------------- /python/alexa-skills-kit-color-expert-python/testEvent.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "session": { 4 | "new": false, 5 | "sessionId": "amzn1.echo-api.session.123456789012", 6 | "application": { 7 | "applicationId": "amzn1.ask.skill.987654321" 8 | }, 9 | "attributes": {}, 10 | "user": { 11 | "userId": "amzn1.ask.account.testUser" 12 | } 13 | }, 14 | "context": { 15 | "AudioPlayer": { 16 | "playerActivity": "IDLE" 17 | }, 18 | "System": { 19 | "application": { 20 | "applicationId": "amzn1.ask.skill.987654321" 21 | }, 22 | "user": { 23 | "userId": "amzn1.ask.account.testUser" 24 | }, 25 | "device": { 26 | "supportedInterfaces": { 27 | "AudioPlayer": {} 28 | } 29 | } 30 | } 31 | }, 32 | "request": { 33 | "type": "IntentRequest", 34 | "requestId": "amzn1.echo-api.request.1234", 35 | "timestamp": "2016-10-27T21:06:28Z", 36 | "locale": "en-US", 37 | "intent": { 38 | "name": "MyColorIsIntent", 39 | "slots": { 40 | "Color": { 41 | "name": "Color", 42 | "value": "blue" 43 | } 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /python/api-gateway-authorizer-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: 'Blueprint for API Gateway custom authorizers, implemented in Python 2.7.' 4 | Parameters: 5 | TopicNameParameter: 6 | Type: String 7 | Resources: 8 | apigatewayauthorizerpython: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: lambda_function.lambda_handler 12 | Runtime: python2.7 13 | CodeUri: . 14 | Description: 'Blueprint for API Gateway custom authorizers, implemented in Python 2.7.' 15 | MemorySize: 256 16 | Timeout: 5 17 | Policies: 18 | - SNSPublishMessagePolicy: 19 | TopicName: !Ref TopicNameParameter 20 | -------------------------------------------------------------------------------- /python/cloudwatch-alarm-to-slack-python/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /python/cloudwatch-alarm-to-slack-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon SNS trigger that sends CloudWatch alarm notifications to Slack. 4 | Parameters: 5 | KeyIdParameter: 6 | Type: String 7 | slackChannelParameter: 8 | Type: String 9 | kmsEncryptedHookUrlParameter: 10 | Type: String 11 | Resources: 12 | cloudwatchalarmtoslackpython: 13 | Type: 'AWS::Serverless::Function' 14 | Properties: 15 | Handler: lambda_function.lambda_handler 16 | Runtime: python2.7 17 | CodeUri: . 18 | Description: >- 19 | An Amazon SNS trigger that sends CloudWatch alarm notifications to 20 | Slack. 21 | MemorySize: 128 22 | Timeout: 3 23 | Policies: 24 | - KMSDecryptPolicy: 25 | KeyId: !Ref KeyIdParameter 26 | Events: 27 | SNS1: 28 | Type: SNS 29 | Properties: 30 | Topic: 31 | Ref: SNSTopic1 32 | Environment: 33 | Variables: 34 | slackChannel: slackChannelParameter 35 | kmsEncryptedHookUrl: kmsEncryptedHookUrlParameter 36 | SNSTopic1: 37 | Type: 'AWS::SNS::Topic' 38 | -------------------------------------------------------------------------------- /python/cloudwatch-alarm-to-slack-python3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algorithmia-blueprint", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "algorithmia": "^0.3.9" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /python/cloudwatch-alarm-to-slack-python3/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon SNS trigger that sends CloudWatch alarm notifications to Slack. 4 | Parameters: 5 | KeyIdParameter: 6 | Type: String 7 | slackChannelParameter: 8 | Type: String 9 | kmsEncryptedHookUrlParameter: 10 | Type: String 11 | Resources: 12 | cloudwatchalarmtoslackpython3: 13 | Type: 'AWS::Serverless::Function' 14 | Properties: 15 | Handler: lambda_function.lambda_handler 16 | Runtime: python3.6 17 | CodeUri: . 18 | Description: >- 19 | An Amazon SNS trigger that sends CloudWatch alarm notifications to 20 | Slack. 21 | MemorySize: 128 22 | Timeout: 3 23 | Policies: 24 | - KMSDecryptPolicy: 25 | KeyId: !Ref KeyIdParameter 26 | Events: 27 | SNS1: 28 | Type: SNS 29 | Properties: 30 | Topic: 31 | Ref: SNSTopic1 32 | Environment: 33 | Variables: 34 | slackChannel: slackChannelParameter 35 | kmsEncryptedHookUrl: kmsEncryptedHookUrlParameter 36 | SNSTopic1: 37 | Type: 'AWS::SNS::Topic' 38 | -------------------------------------------------------------------------------- /python/datadog-process-rds-metrics/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Pushes RDS Enhanced metrics to Datadog. 4 | Parameters: 5 | KeyIdParameter: 6 | Type: String 7 | Resources: 8 | datadogprocessrdsmetrics: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: lambda_function.lambda_handler 12 | Runtime: python2.7 13 | CodeUri: . 14 | Description: Pushes RDS Enhanced metrics to Datadog. 15 | MemorySize: 128 16 | Timeout: 10 17 | Policies: 18 | - KMSDecryptPolicy: 19 | KeyId: !Ref KeyIdParameter 20 | Environment: 21 | Variables: 22 | kmsEncryptedKeys: 23 | -------------------------------------------------------------------------------- /python/dynamodb-process-stream-python/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import json 4 | 5 | print('Loading function') 6 | 7 | 8 | def lambda_handler(event, context): 9 | #print("Received event: " + json.dumps(event, indent=2)) 10 | for record in event['Records']: 11 | print(record['eventID']) 12 | print(record['eventName']) 13 | print("DynamoDB Record: " + json.dumps(record['dynamodb'], indent=2)) 14 | return 'Successfully processed {} records.'.format(len(event['Records'])) 15 | -------------------------------------------------------------------------------- /python/dynamodb-process-stream-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon DynamoDB trigger that logs the updates made to a table. 4 | Resources: 5 | dynamodbprocessstreampython: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: lambda_function.lambda_handler 9 | Runtime: python2.7 10 | CodeUri: . 11 | Description: An Amazon DynamoDB trigger that logs the updates made to a table. 12 | MemorySize: 128 13 | Timeout: 3 14 | Policies: 15 | - AWSConfigRulesExecutionRole 16 | Events: 17 | DynamoDB1: 18 | Type: DynamoDB 19 | Properties: 20 | Stream: 21 | 'Fn::GetAtt': 22 | - Table1 23 | - StreamArn 24 | StartingPosition: TRIM_HORIZON 25 | BatchSize: 100 26 | Table1: 27 | Type: 'AWS::DynamoDB::Table' 28 | Properties: 29 | AttributeDefinitions: 30 | - AttributeName: id 31 | AttributeType: S 32 | KeySchema: 33 | - AttributeName: id 34 | KeyType: HASH 35 | ProvisionedThroughput: 36 | ReadCapacityUnits: 5 37 | WriteCapacityUnits: 5 38 | StreamSpecification: 39 | StreamViewType: NEW_IMAGE 40 | -------------------------------------------------------------------------------- /python/dynamodb-process-stream-python3/lambda_function.py: -------------------------------------------------------------------------------- 1 | 2 | import json 3 | 4 | print('Loading function') 5 | 6 | 7 | def lambda_handler(event, context): 8 | #print("Received event: " + json.dumps(event, indent=2)) 9 | for record in event['Records']: 10 | print(record['eventID']) 11 | print(record['eventName']) 12 | print("DynamoDB Record: " + json.dumps(record['dynamodb'], indent=2)) 13 | return 'Successfully processed {} records.'.format(len(event['Records'])) 14 | -------------------------------------------------------------------------------- /python/dynamodb-process-stream-python3/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon DynamoDB trigger that logs the updates made to a table. 4 | Resources: 5 | dynamodbprocessstreampython3: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: lambda_function.lambda_handler 9 | Runtime: python3.6 10 | CodeUri: . 11 | Description: An Amazon DynamoDB trigger that logs the updates made to a table. 12 | MemorySize: 128 13 | Timeout: 3 14 | Policies: [] 15 | Events: 16 | DynamoDB1: 17 | Type: DynamoDB 18 | Properties: 19 | Stream: 20 | 'Fn::GetAtt': 21 | - Table1 22 | - StreamArn 23 | StartingPosition: TRIM_HORIZON 24 | BatchSize: 100 25 | Table1: 26 | Type: 'AWS::DynamoDB::Table' 27 | Properties: 28 | AttributeDefinitions: 29 | - AttributeName: id 30 | AttributeType: S 31 | KeySchema: 32 | - AttributeName: id 33 | KeyType: HASH 34 | ProvisionedThroughput: 35 | ReadCapacityUnits: 5 36 | WriteCapacityUnits: 5 37 | StreamSpecification: 38 | StreamViewType: NEW_IMAGE 39 | -------------------------------------------------------------------------------- /python/hello-world-python/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import json 4 | 5 | print('Loading function') 6 | 7 | 8 | def lambda_handler(event, context): 9 | #print("Received event: " + json.dumps(event, indent=2)) 10 | print("value1 = " + event['key1']) 11 | print("value2 = " + event['key2']) 12 | print("value3 = " + event['key3']) 13 | return event['key1'] # Echo back the first key value 14 | #raise Exception('Something went wrong') 15 | -------------------------------------------------------------------------------- /python/hello-world-python/readme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amazon-archives/serverless-app-examples/9485c6ca6adc65994e5c5b0002039e4547d6c3d2/python/hello-world-python/readme -------------------------------------------------------------------------------- /python/hello-world-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: A starter AWS Lambda function. 4 | Parameters: 5 | IdentityNameParameter: 6 | Type: String 7 | Resources: 8 | helloworldpython: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: lambda_function.lambda_handler 12 | Runtime: python2.7 13 | CodeUri: . 14 | Description: A starter AWS Lambda function. 15 | MemorySize: 128 16 | Timeout: 3 17 | Policies: 18 | - SESSendBouncePolicy: 19 | IdentityName: !Ref IdentityNameParameter 20 | -------------------------------------------------------------------------------- /python/hello-world-python3/lambda_function.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | print('Loading function') 4 | 5 | 6 | def lambda_handler(event, context): 7 | #print("Received event: " + json.dumps(event, indent=2)) 8 | print("value1 = " + event['key1']) 9 | print("value2 = " + event['key2']) 10 | print("value3 = " + event['key3']) 11 | return event['key1'] # Echo back the first key value 12 | #raise Exception('Something went wrong') 13 | -------------------------------------------------------------------------------- /python/hello-world-python3/readme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amazon-archives/serverless-app-examples/9485c6ca6adc65994e5c5b0002039e4547d6c3d2/python/hello-world-python3/readme -------------------------------------------------------------------------------- /python/hello-world-python3/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: A starter AWS Lambda function. 4 | Parameters: 5 | IdentityNameParameter: 6 | Type: String 7 | Resources: 8 | helloworldpython3: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: lambda_function.lambda_handler 12 | Runtime: python3.6 13 | CodeUri: . 14 | Description: A starter AWS Lambda function. 15 | MemorySize: 128 16 | Timeout: 3 17 | Policies: 18 | - SESSendBouncePolicy: 19 | IdentityName: !Ref IdentityNameParameter 20 | -------------------------------------------------------------------------------- /python/inbound-ses-spam-filter-python/readme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amazon-archives/serverless-app-examples/9485c6ca6adc65994e5c5b0002039e4547d6c3d2/python/inbound-ses-spam-filter-python/readme -------------------------------------------------------------------------------- /python/inbound-ses-spam-filter-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/inbound-ses-spam-filter-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | A simple email filter for protection against spam and viruses as well as DKIM and SPF failures. 5 | Parameters: 6 | IdentityNameParameter: 7 | Type: String 8 | Resources: 9 | inboundsesspamfilterpython: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: lambda_function.lambda_handler 13 | Runtime: python2.7 14 | CodeUri: . 15 | Description: >- 16 | A simple email filter for protection against spam and viruses as well as DKIM and SPF failures. 17 | MemorySize: 128 18 | Timeout: 10 19 | Policies: 20 | - SESSendBouncePolicy: 21 | IdentityName: !Ref IdentityNameParameter 22 | Environment: 23 | Variables: 24 | emailDomain: 25 | -------------------------------------------------------------------------------- /python/kinesis-analytics-process-kpl-record/aws_kinesis_agg/__init__.py: -------------------------------------------------------------------------------- 1 | #Kinesis Aggregation/Deaggregation Libraries for Python 2 | # 3 | #Copyright 2014, Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | # 5 | #Licensed under the Amazon Software License (the "License"). 6 | #You may not use this file except in compliance with the License. 7 | #A copy of the License is located at 8 | # 9 | # http://aws.amazon.com/asl/ 10 | # 11 | #or in the "license" file accompanying this file. This file is distributed 12 | #on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 | #express or implied. See the License for the specific language governing 14 | #permissions and limitations under the License. 15 | 16 | import md5 17 | 18 | #Message aggregation protocol-specific constants 19 | #(https://github.com/awslabs/amazon-kinesis-producer/blob/master/aggregation-format.md) 20 | MAGIC = '\xf3\x89\x9a\xc2' 21 | DIGEST_SIZE = md5.digest_size 22 | 23 | #Kinesis Limits 24 | #(https://docs.aws.amazon.com/kinesis/latest/APIReference/API_PutRecord.html) 25 | MAX_BYTES_PER_RECORD = 1024*1024 # 1 MB 26 | -------------------------------------------------------------------------------- /python/kinesis-analytics-process-kpl-record/requirements.txt: -------------------------------------------------------------------------------- 1 | protobuf==3.5.1 2 | -------------------------------------------------------------------------------- /python/kinesis-analytics-process-kpl-record/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Analytics record pre-processor that receives Kinesis 5 | Producer Library (KPL) aggregates of JSON or CSV records as input and returns 6 | de-aggregated records with a processing status. 7 | Parameters: 8 | FunctionNameParameter: 9 | Type: String 10 | TableNameParameter: 11 | Type: String 12 | Resources: 13 | kinesisanalyticsprocesskplrecord: 14 | Type: 'AWS::Serverless::Function' 15 | Properties: 16 | Handler: lambda_function.lambda_handler 17 | Runtime: python2.7 18 | CodeUri: . 19 | Description: >- 20 | An Amazon Kinesis Analytics record pre-processor that receives Kinesis 21 | Producer Library (KPL) aggregates of JSON or CSV records as input and 22 | returns de-aggregated records with a processing status. 23 | MemorySize: 128 24 | Timeout: 3 25 | Policies: 26 | Policies: 27 | - LambdaInvokePolicy: 28 | FunctionName: !Ref FunctionNameParameter 29 | - DynamoDBCrudPolicy: 30 | TableName: !Ref TableNameParameter 31 | -------------------------------------------------------------------------------- /python/kinesis-analytics-process-record-python/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import base64 4 | 5 | print('Loading function') 6 | 7 | 8 | def lambda_handler(event, context): 9 | output = [] 10 | 11 | for record in event['records']: 12 | payload = base64.b64decode(record['data']) 13 | 14 | # Do custom processing on the record payload here 15 | output_record = { 16 | 'recordId': record['recordId'], 17 | 'result': 'Ok', 18 | 'data': base64.b64encode(payload) 19 | } 20 | output.append(output_record) 21 | 22 | print('Successfully processed {} records.'.format(len(event['records']))) 23 | 24 | return {'records': output} 25 | -------------------------------------------------------------------------------- /python/kinesis-analytics-process-record-python/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/kinesis-analytics-process-record-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/kinesis-analytics-process-record-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Analytics record pre-processor that receives JSON or CSV 5 | records as input and returns them with a processing status. Use this processor 6 | as a starting point for custom transformation logic. 7 | Parameters: 8 | FunctionNameParameter: 9 | Type: String 10 | TableNameParameter: 11 | Type: String 12 | Resources: 13 | kinesisanalyticsprocessrecordpython: 14 | Type: 'AWS::Serverless::Function' 15 | Properties: 16 | Handler: lambda_function.lambda_handler 17 | Runtime: python2.7 18 | CodeUri: . 19 | Description: >- 20 | An Amazon Kinesis Analytics record pre-processor that receives JSON or 21 | CSV records as input and returns them with a processing status. Use this 22 | processor as a starting point for custom transformation logic. 23 | MemorySize: 128 24 | Timeout: 3 25 | Policies: 26 | - LambdaInvokePolicy: 27 | FunctionName: !Ref FunctionNameParameter 28 | - DynamoDBCrudPolicy: 29 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /python/kinesis-firehose-apachelog-to-csv-python/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import base64 4 | import re 5 | 6 | print('Loading function') 7 | 8 | 9 | def lambda_handler(event, context): 10 | output = [] 11 | succeeded_record_cnt = 0 12 | failed_record_cnt = 0 13 | 14 | for record in event['records']: 15 | print(record['recordId']) 16 | payload = base64.b64decode(record['data']) 17 | 18 | p = re.compile(r"^([\d.]+) (\S+) (\S+) \[([\w:/]+\s[\+\-]\d{4})\] \"(.+?)\" (\d{3}) (\d+)") 19 | m = p.match(payload) 20 | if m: 21 | succeeded_record_cnt += 1 22 | output_payload = m.group(1) + ',' + m.group(2) + ',' + m.group(3) + ',' + m.group(4) + ',' + m.group(5) + ',' + m.group(6) + ',' + m.group(7) + '\n' 23 | output_record = { 24 | 'recordId': record['recordId'], 25 | 'result': 'Ok', 26 | 'data': base64.b64encode(output_payload) 27 | } 28 | else: 29 | print('Parsing failed') 30 | failed_record_cnt += 1 31 | output_record = { 32 | 'recordId': record['recordId'], 33 | 'result': 'ProcessingFailed', 34 | 'data': record['data'] 35 | } 36 | 37 | output.append(output_record) 38 | 39 | print('Processing completed. Successful records {}, Failed records {}.'.format(succeeded_record_cnt, failed_record_cnt)) 40 | return {'records': output} 41 | -------------------------------------------------------------------------------- /python/kinesis-firehose-apachelog-to-csv-python/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/kinesis-firehose-apachelog-to-csv-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/kinesis-firehose-apachelog-to-csv-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that converts input records from 5 | Apache Common Log format to CSV. 6 | Parameters: 7 | FunctionNameParameter: 8 | Type: String 9 | TableNameParameter: 10 | Type: String 11 | Resources: 12 | kinesisfirehoseapachelogtocsvpython: 13 | Type: 'AWS::Serverless::Function' 14 | Properties: 15 | Handler: lambda_function.lambda_handler 16 | Runtime: python2.7 17 | CodeUri: . 18 | Description: >- 19 | An Amazon Kinesis Firehose stream processor that converts input records 20 | from Apache Common Log format to CSV. 21 | MemorySize: 128 22 | Timeout: 3 23 | Policies: 24 | - LambdaInvokePolicy: 25 | FunctionName: !Ref FunctionNameParameter 26 | - DynamoDBCrudPolicy: 27 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /python/kinesis-firehose-apachelog-to-json-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/kinesis-firehose-apachelog-to-json-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that converts input records from 5 | Apache Common Log format to JSON. 6 | Parameters: 7 | FunctionNameParameter: 8 | Type: String 9 | TableNameParameter: 10 | Type: String 11 | Resources: 12 | kinesisfirehoseapachelogtojsonpython: 13 | Type: 'AWS::Serverless::Function' 14 | Properties: 15 | Handler: lambda_function.lambda_handler 16 | Runtime: python2.7 17 | CodeUri: . 18 | Description: >- 19 | An Amazon Kinesis Firehose stream processor that converts input records 20 | from Apache Common Log format to JSON. 21 | MemorySize: 128 22 | Timeout: 3 23 | Policies: 24 | - LambdaInvokePolicy: 25 | FunctionName: !Ref FunctionNameParameter 26 | - DynamoDBCrudPolicy: 27 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /python/kinesis-firehose-process-record-python/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import base64 4 | 5 | print('Loading function') 6 | 7 | 8 | def lambda_handler(event, context): 9 | output = [] 10 | 11 | for record in event['records']: 12 | print(record['recordId']) 13 | payload = base64.b64decode(record['data']) 14 | 15 | # Do custom processing on the payload here 16 | 17 | output_record = { 18 | 'recordId': record['recordId'], 19 | 'result': 'Ok', 20 | 'data': base64.b64encode(payload) 21 | } 22 | output.append(output_record) 23 | 24 | print('Successfully processed {} records.'.format(len(event['records']))) 25 | 26 | return {'records': output} 27 | -------------------------------------------------------------------------------- /python/kinesis-firehose-process-record-python/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/kinesis-firehose-process-record-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/kinesis-firehose-process-record-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that accesses the records in the 5 | input and returns them with a processing status. Use this processor for any 6 | custom transformation logic. 7 | Parameters: 8 | FunctionNameParameter: 9 | Type: String 10 | TableNameParameter: 11 | Type: String 12 | Resources: 13 | kinesisfirehoseprocessrecordpython: 14 | Type: 'AWS::Serverless::Function' 15 | Properties: 16 | Handler: lambda_function.lambda_handler 17 | Runtime: python2.7 18 | CodeUri: . 19 | Description: >- 20 | An Amazon Kinesis Firehose stream processor that accesses the records in 21 | the input and returns them with a processing status. Use this processor 22 | for any custom transformation logic. 23 | MemorySize: 128 24 | Timeout: 3 25 | Policies: 26 | - LambdaInvokePolicy: 27 | FunctionName: !Ref FunctionNameParameter 28 | - DynamoDBCrudPolicy: 29 | TableName: !Ref TableNameParameter 30 | -------------------------------------------------------------------------------- /python/kinesis-firehose-process-record-streams-as-source-python/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import base64 4 | 5 | print('Loading function') 6 | 7 | 8 | def lambda_handler(event, context): 9 | output = [] 10 | 11 | for record in event['records']: 12 | print(record['recordId']) 13 | payload = base64.b64decode(record['data']) 14 | print(record['recordId']) 15 | 16 | # Print stream as source only data here 17 | kinesisMetadata = record['kinesisRecordMetadata'] 18 | print(kinesisMetadata['sequenceNumber']) 19 | print(kinesisMetadata['subsequenceNumber']) 20 | print(kinesisMetadata['partitionKey']) 21 | print(kinesisMetadata['shardId']) 22 | print(kinesisMetadata['approximateArrivalTimestamp']) 23 | 24 | # Do custom processing on the payload here 25 | output_record = { 26 | 'recordId': record['recordId'], 27 | 'result': 'Ok', 28 | 'data': base64.b64encode(payload) 29 | } 30 | output.append(output_record) 31 | 32 | print('Successfully processed {} records.'.format(len(event['records']))) 33 | 34 | return {'records': output} 35 | -------------------------------------------------------------------------------- /python/kinesis-firehose-process-record-streams-as-source-python/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/kinesis-firehose-process-record-streams-as-source-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/kinesis-firehose-process-record-streams-as-source-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that accesses the Kinesis Streams records in the input and returns them with a processing status. 5 | Parameters: 6 | FunctionNameParameter: 7 | Type: String 8 | TableNameParameter: 9 | Type: String 10 | Resources: 11 | kinesisfirehoseprocessrecordstreamsassourcepython: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: lambda_function.lambda_handler 15 | Runtime: python2.7 16 | CodeUri: . 17 | Description: >- 18 | An Amazon Kinesis Firehose stream processor that accesses the Kinesis Streams records in the input and returns them with a processing status. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - LambdaInvokePolicy: 23 | FunctionName: !Ref FunctionNameParameter 24 | - DynamoDBCrudPolicy: 25 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /python/kinesis-firehose-syslog-to-csv-python/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/kinesis-firehose-syslog-to-csv-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/kinesis-firehose-syslog-to-csv-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that converts input records from RFC3164 Syslog format to CSV. 5 | Parameters: 6 | FunctionNameParameter: 7 | Type: String 8 | TableNameParameter: 9 | Type: String 10 | Resources: 11 | kinesisfirehosesyslogtocsvpython: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: lambda_function.lambda_handler 15 | Runtime: python2.7 16 | CodeUri: . 17 | Description: >- 18 | An Amazon Kinesis Firehose stream processor that converts input records from RFC3164 Syslog format to CSV. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - LambdaInvokePolicy: 23 | FunctionName: !Ref FunctionNameParameter 24 | - DynamoDBCrudPolicy: 25 | TableName: !Ref TableNameParameter 26 | -------------------------------------------------------------------------------- /python/kinesis-firehose-syslog-to-json-python/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/kinesis-firehose-syslog-to-json-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/kinesis-firehose-syslog-to-json-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon Kinesis Firehose stream processor that converts input records from RFC3164 Syslog format to JSON. 5 | Parameters: 6 | FunctionNameParameter: 7 | Type: String 8 | TableNameParameter: 9 | Type: String 10 | Resources: 11 | kinesisfirehosesyslogtojsonpython: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: lambda_function.lambda_handler 15 | Runtime: python2.7 16 | CodeUri: . 17 | Description: >- 18 | An Amazon Kinesis Firehose stream processor that converts input records from RFC3164 Syslog format to JSON. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - LambdaInvokePolicy: 23 | FunctionName: !Ref FunctionNameParameter 24 | - DynamoDBCrudPolicy: 25 | TableName: !Ref TableNameParameter 26 | 27 | -------------------------------------------------------------------------------- /python/kinesis-process-record-python/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import base64 4 | import json 5 | 6 | print('Loading function') 7 | 8 | 9 | def lambda_handler(event, context): 10 | #print("Received event: " + json.dumps(event, indent=2)) 11 | for record in event['Records']: 12 | # Kinesis data is base64 encoded so decode here 13 | payload = base64.b64decode(record['kinesis']['data']) 14 | print("Decoded payload: " + payload) 15 | return 'Successfully processed {} records.'.format(len(event['Records'])) 16 | -------------------------------------------------------------------------------- /python/kinesis-process-record-python/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/kinesis-process-record-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/kinesis-process-record-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon Kinesis stream processor that logs the data being published. 4 | Parameters: 5 | FunctionNameParameter: 6 | Type: String 7 | TableNameParameter: 8 | Type: String 9 | Resources: 10 | kinesisprocessrecordpython: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: lambda_function.lambda_handler 14 | Runtime: python2.7 15 | CodeUri: . 16 | Description: An Amazon Kinesis stream processor that logs the data being published. 17 | MemorySize: 128 18 | Timeout: 3 19 | Policies: 20 | - LambdaInvokePolicy: 21 | FunctionName: !Ref FunctionNameParameter 22 | - DynamoDBCrudPolicy: 23 | TableName: !Ref TableNameParameter 24 | Events: 25 | Kinesis1: 26 | Type: Kinesis 27 | Properties: 28 | Stream: 29 | 'Fn::GetAtt': 30 | - KinesisStream1 31 | - Arn 32 | StartingPosition: TRIM_HORIZON 33 | BatchSize: 100 34 | KinesisStream1: 35 | Type: 'AWS::Kinesis::Stream' 36 | Properties: 37 | ShardCount: 1 38 | -------------------------------------------------------------------------------- /python/lambda-canary-python3/lambda_function.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | from datetime import datetime 4 | from urllib.request import urlopen 5 | 6 | SITE = os.environ['site'] # URL of the site to check, stored in the site environment variable 7 | EXPECTED = os.environ['expected'] # String expected to be on the page, stored in the expected environment variable 8 | 9 | 10 | def validate(res): 11 | '''Return False to trigger the canary 12 | 13 | Currently this simply checks whether the EXPECTED string is present. 14 | However, you could modify this to perform any number of arbitrary 15 | checks on the contents of SITE. 16 | ''' 17 | return EXPECTED in res 18 | 19 | 20 | def lambda_handler(event, context): 21 | print('Checking {} at {}...'.format(SITE, event['time'])) 22 | try: 23 | if not validate(str(urlopen(SITE).read())): 24 | raise Exception('Validation failed') 25 | except: 26 | print('Check failed!') 27 | raise 28 | else: 29 | print('Check passed!') 30 | return event['time'] 31 | finally: 32 | print('Check complete at {}'.format(str(datetime.now()))) 33 | -------------------------------------------------------------------------------- /python/lambda-canary-python3/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/lambda-canary-python3/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/lambda-canary-python3/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: 'Performs a periodic check of the given site, erroring out on test failure.' 4 | Parameters: 5 | FunctionNameParameter: 6 | Type: String 7 | Resources: 8 | lambdacanarypython3: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: lambda_function.lambda_handler 12 | Runtime: python3.6 13 | CodeUri: . 14 | Description: >- 15 | Performs a periodic check of the given site, erroring out on test failure. 16 | MemorySize: 128 17 | Timeout: 10 18 | Policies: 19 | - LambdaInvokePolicy: 20 | FunctionName: !Ref FunctionNameParameter 21 | Environment: 22 | Variables: 23 | site: 'https://www.amazon.com/' 24 | expected: Online Shopping 25 | -------------------------------------------------------------------------------- /python/lambda-canary/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import os 4 | from datetime import datetime 5 | from urllib2 import urlopen 6 | 7 | SITE = os.environ['site'] # URL of the site to check, stored in the site environment variable, e.g. https://aws.amazon.com 8 | EXPECTED = os.environ['expected'] # String expected to be on the page, stored in the expected environment variable, e.g. Amazon 9 | 10 | 11 | def validate(res): 12 | '''Return False to trigger the canary 13 | 14 | Currently this simply checks whether the EXPECTED string is present. 15 | However, you could modify this to perform any number of arbitrary 16 | checks on the contents of SITE. 17 | ''' 18 | return EXPECTED in res 19 | 20 | 21 | def lambda_handler(event, context): 22 | print('Checking {} at {}...'.format(SITE, event['time'])) 23 | try: 24 | if not validate(urlopen(SITE).read()): 25 | raise Exception('Validation failed') 26 | except: 27 | print('Check failed!') 28 | raise 29 | else: 30 | print('Check passed!') 31 | return event['time'] 32 | finally: 33 | print('Check complete at {}'.format(str(datetime.now()))) 34 | -------------------------------------------------------------------------------- /python/lambda-canary/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/lambda-canary/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/lambda-canary/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: 'Performs a periodic check of the given site, erroring out on test failure.' 4 | Parameters: 5 | FunctionNameParameter: 6 | Type: String 7 | TableNameParameter: 8 | Type: String 9 | Resources: 10 | lambdacanary: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: lambda_function.lambda_handler 14 | Runtime: python2.7 15 | CodeUri: . 16 | Description: >- 17 | Performs a periodic check of the given site, erroring out on test failure. 18 | MemorySize: 128 19 | Timeout: 10 20 | Policies: 21 | - LambdaInvokePolicy: 22 | FunctionName: !Ref FunctionNameParameter 23 | - DynamoDBCrudPolicy: 24 | TableName: !Ref TableNameParameter 25 | Environment: 26 | Variables: 27 | site: 28 | expected: 29 | -------------------------------------------------------------------------------- /python/lex-book-trip-python/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/lex-book-trip-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/lex-book-trip-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Book details of a visit, using Amazon Lex to perform natural language 5 | understanding 6 | Parameters: 7 | KeyIdParameter: 8 | Type: String 9 | Resources: 10 | lexbooktrippython: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: lambda_function.lambda_handler 14 | Runtime: python2.7 15 | CodeUri: . 16 | Description: >- 17 | Book details of a visit, using Amazon Lex to perform natural language 18 | understanding 19 | MemorySize: 128 20 | Timeout: 10 21 | Policies: 22 | - KMSDecryptPolicy: 23 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /python/lex-make-appointment-python/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/lex-make-appointment-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/lex-make-appointment-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Schedule a dentist appointment, using Amazon Lex to perform natural language 5 | understanding 6 | Parameters: 7 | KeyIdParameter: 8 | Type: String 9 | Resources: 10 | lexmakeappointmentpython: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: lambda_function.lambda_handler 14 | Runtime: python2.7 15 | CodeUri: . 16 | Description: >- 17 | Schedule a dentist appointment, using Amazon Lex to perform natural 18 | language understanding 19 | MemorySize: 128 20 | Timeout: 10 21 | Policies: 22 | - KMSDecryptPolicy: 23 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /python/lex-order-flowers-python/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/lex-order-flowers-python/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/lex-order-flowers-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: 'Order flowers, using Amazon Lex to perform natural language understanding' 4 | Parameters: 5 | KeyIdParameter: 6 | Type: String 7 | Resources: 8 | lexorderflowerspython: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: lambda_function.lambda_handler 12 | Runtime: python2.7 13 | CodeUri: . 14 | Description: >- 15 | Order flowers, using Amazon Lex to perform natural language 16 | understanding 17 | MemorySize: 128 18 | Timeout: 10 19 | Policies: 20 | - KMSDecryptPolicy: 21 | KeyId: !Ref KeyIdParameter -------------------------------------------------------------------------------- /python/logicmonitor-send-cloudwatch-events/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/logicmonitor-send-cloudwatch-events/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/logicmonitor-send-cloudwatch-events/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Creates LogicMonitor OpsNotes for CloudWatch Events, thereby enabling 5 | correlation between events and performance data. 6 | Parameters: 7 | KeyIdParameter: 8 | Type: String 9 | Resources: 10 | logicmonitorsendcloudwatchevents: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: lambda_function.lambda_handler 14 | Runtime: python2.7 15 | CodeUri: . 16 | Description: >- 17 | Creates LogicMonitor OpsNotes for CloudWatch Events, thereby enabling 18 | correlation between events and performance data. 19 | MemorySize: 128 20 | Timeout: 30 21 | Policies: 22 | - KMSDecryptPolicy: 23 | KeyId: !Ref KeyIdParameter 24 | Environment: 25 | Variables: 26 | ACCOUNT_NAME: 27 | API_ACCESS_ID: 28 | API_ACCESS_KEY: 29 | -------------------------------------------------------------------------------- /python/logicmonitor-send-eventbridge-events/readme: -------------------------------------------------------------------------------- 1 | ''' 2 | This function handles a Slack slash command and echoes the details back to the user. 3 | 4 | Follow these steps to configure the slash command in Slack: 5 | 6 | 1. Navigate to https://.slack.com/services/new 7 | 8 | 2. Search for and select "Slash Commands". 9 | 10 | 3. Enter a name for your command and click "Add Slash Command Integration". 11 | 12 | 4. Copy the token string from the integration settings and use it in the next section. 13 | 14 | 5. After you complete this blueprint, enter the provided API endpoint URL in the URL field. 15 | 16 | 17 | To encrypt your secrets use the following steps: 18 | 19 | 1. Create or use an existing KMS Key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html 20 | 21 | 2. Click the "Enable Encryption Helpers" checkbox 22 | 23 | 3. Paste into the kmsEncryptedToken environment variable and click encrypt 24 | 25 | 26 | Follow these steps to complete the configuration of your command API endpoint 27 | 28 | 1. When completing the blueprint configuration select "Open" for security 29 | on the "Configure triggers" page. 30 | 31 | 2. Enter a name for your execution role in the "Role name" field. 32 | Your function's execution role needs kms:Decrypt permissions. We have 33 | pre-selected the "KMS decryption permissions" policy template that will 34 | automatically add these permissions. 35 | 36 | 3. Update the URL for your Slack slash command with the invocation URL for the 37 | created API resource in the prod stage. 38 | ''' -------------------------------------------------------------------------------- /python/logicmonitor-send-eventbridge-events/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.13.0 2 | -------------------------------------------------------------------------------- /python/logicmonitor-send-eventbridge-events/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | Creates LogicMonitor OpsNotes for EventBridge Events, thereby enabling 5 | correlation between events and performance data. 6 | Parameters: 7 | KeyIdParameter: 8 | Type: String 9 | Resources: 10 | logicmonitorsendeventbridgeevents: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: lambda_function.lambda_handler 14 | Runtime: python2.7 15 | CodeUri: . 16 | Description: >- 17 | Creates LogicMonitor OpsNotes for EventBridge Events, thereby enabling 18 | correlation between events and performance data. 19 | MemorySize: 128 20 | Timeout: 30 21 | Policies: 22 | - KMSDecryptPolicy: 23 | KeyId: !Ref KeyIdParameter 24 | Environment: 25 | Variables: 26 | ACCOUNT_NAME: 27 | API_ACCESS_ID: 28 | API_ACCESS_KEY: 29 | -------------------------------------------------------------------------------- /python/microservice-http-endpoint-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway. 5 | Parameters: 6 | TableNameParameter: 7 | Type: String 8 | Resources: 9 | microservicehttpendpointpython: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: lambda_function.lambda_handler 13 | Runtime: python2.7 14 | CodeUri: . 15 | Description: >- 16 | A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway. 17 | MemorySize: 512 18 | Timeout: 10 19 | Policies: 20 | - DynamoDBCrudPolicy: 21 | TableName: !Ref TableNameParameter 22 | Events: 23 | Api1: 24 | Type: Api 25 | Properties: 26 | Path: /MyResource 27 | Method: ANY 28 | -------------------------------------------------------------------------------- /python/microservice-http-endpoint-python3/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway. 5 | 6 | Parameters: 7 | TableNameParameter: 8 | Type: String 9 | 10 | Globals: 11 | #https://github.com/awslabs/serverless-application-model/blob/develop/docs/globals.rst 12 | Function: 13 | Runtime: python3.6 14 | MemorySize: 512 15 | Environment: 16 | Variables: 17 | TABLE_NAME: 18 | Ref: Table 19 | 20 | Resources: 21 | microservicehttpendpointpython3: 22 | Type: 'AWS::Serverless::Function' 23 | Properties: 24 | Handler: lambda_function.lambda_handler 25 | CodeUri: . 26 | Description: >- 27 | A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway. 28 | Timeout: 10 29 | Policies: 30 | - DynamoDBCrudPolicy: 31 | TableName: !Ref TableNameParameter 32 | Events: 33 | Api1: 34 | Type: Api 35 | Properties: 36 | Path: /MyResource 37 | Method: ANY 38 | 39 | Table: 40 | Type: AWS::Serverless::SimpleTable 41 | -------------------------------------------------------------------------------- /python/microservice-http-endpoint-python3/test-payload.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": { 3 | "S": "id_string" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /python/microservice-http-endpoint-python3/test.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash -e 2 | 3 | # Test invocation using httpie (http) in place of curl for syntax simplicity 4 | # 5 | # Args: $1: API GW path 6 | # $2 json payload data file 7 | # 8 | # eg: ./test.sh https://.execute-api..amazonaws.com/Prod/MyResource ./test-payload.json 9 | 10 | set -x 11 | 12 | # Write one item 13 | 14 | http POST $1 Item:=@$2 15 | 16 | # Read all back 17 | 18 | http GET $1 19 | 20 | -------------------------------------------------------------------------------- /python/rekognition-python/response/detect-faces-response.json: -------------------------------------------------------------------------------- 1 | {"FaceDetails": [{"BoundingBox": {"Width": 0.37220844626426697, "Top": 0.097087375819683075, "Height": 0.56011950969696045, "Left": 0.60049629211425781}, "Landmarks": [{"Y": 0.29746288061141968, "X": 0.74046933650970459, "Type": "eyeLeft"}, {"Y": 0.39010941982269287, "X": 0.85312539339065552, "Type": "eyeRight"}, {"Y": 0.43307429552078247, "X": 0.80672019720077515, "Type": "nose"}, {"Y": 0.51852452754974365, "X": 0.7020527720451355, "Type": "mouthLeft"}, {"Y": 0.56728619337081909, "X": 0.78770458698272705, "Type": "mouthRight"}], "Pose": {"Yaw": 25.503475189208984, "Roll": 27.584785461425781, "Pitch": 16.070867538452148}, "Quality": {"Sharpness": 140.0, "Brightness": 45.784263610839844}, "Confidence": 99.999870300292969}], "ResponseMetadata": {"RetryAttempts": 0, "HTTPStatusCode": 200, "RequestId": "5ec8d1f8-a853-11e6-ae5a-0f6c6597f701", "HTTPHeaders": {"date": "Fri, 11 Nov 2016 21:11:12 GMT", "x-amzn-requestid": "5ec8d1f8-a853-11e6-ae5a-0f6c6597f701", "content-length": "699", "content-type": "application/x-amz-json-1.1", "connection": "keep-alive"}}, "OrientationCorrection": "ROTATE_0"} 2 | -------------------------------------------------------------------------------- /python/rekognition-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon S3 trigger that uses rekognition APIs to detect faces 4 | Parameters: 5 | BucketNamePrefix: 6 | Type: String 7 | Default: sam-example 8 | CollectionIdParameter: 9 | Type: String 10 | Resources: 11 | rekognitionpython: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: lambda_function.lambda_handler 15 | Runtime: python2.7 16 | CodeUri: . 17 | Description: An Amazon S3 trigger that uses rekognition APIs to detect faces 18 | MemorySize: 128 19 | Timeout: 3 20 | Policies: 21 | - S3CrudPolicy: 22 | BucketName: !Sub "${BucketNamePrefix}-rekognition" 23 | - RekognitionNoDataAccessPolicy: 24 | CollectionId: !Ref CollectionIdParameter 25 | - RekognitionWriteOnlyAccessPolicy: 26 | CollectionId: !Ref CollectionIdParameter 27 | Events: 28 | BucketEvent1: 29 | Type: S3 30 | Properties: 31 | Bucket: 32 | Ref: Bucket1 33 | Events: 34 | - 's3:ObjectCreated:*' 35 | Bucket1: 36 | Type: 'AWS::S3::Bucket' 37 | Properties: 38 | BucketName: !Sub "${BucketNamePrefix}-rekognition" 39 | -------------------------------------------------------------------------------- /python/s3-get-object-python/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import json 4 | import urllib 5 | import boto3 6 | 7 | print('Loading function') 8 | 9 | s3 = boto3.client('s3') 10 | 11 | 12 | def lambda_handler(event, context): 13 | #print("Received event: " + json.dumps(event, indent=2)) 14 | 15 | # Get the object from the event and show its content type 16 | bucket = event['Records'][0]['s3']['bucket']['name'] 17 | key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'].encode('utf8')) 18 | try: 19 | response = s3.get_object(Bucket=bucket, Key=key) 20 | print("CONTENT TYPE: " + response['ContentType']) 21 | return response['ContentType'] 22 | except Exception as e: 23 | print(e) 24 | print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket)) 25 | raise e 26 | -------------------------------------------------------------------------------- /python/s3-get-object-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon S3 trigger that retrieves metadata for the object that has been 5 | updated. 6 | Parameters: 7 | BucketNamePrefix: 8 | Type: String 9 | Default: sam-example 10 | Resources: 11 | s3getobjectpython: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: lambda_function.lambda_handler 15 | Runtime: python2.7 16 | CodeUri: . 17 | Description: >- 18 | An Amazon S3 trigger that retrieves metadata for the object that has 19 | been updated. 20 | MemorySize: 128 21 | Timeout: 3 22 | Policies: 23 | - S3CrudPolicy: 24 | BucketName: !Sub "${BucketNamePrefix}-get-object-python" 25 | Events: 26 | BucketEvent1: 27 | Type: S3 28 | Properties: 29 | Bucket: 30 | Ref: Bucket1 31 | Events: 32 | - 's3:ObjectCreated:*' 33 | Bucket1: 34 | Type: 'AWS::S3::Bucket' 35 | Properties: 36 | BucketName: !Sub "${BucketNamePrefix}-get-object-python" 37 | -------------------------------------------------------------------------------- /python/s3-get-object-python3/lambda_function.py: -------------------------------------------------------------------------------- 1 | 2 | import json 3 | import urllib.parse 4 | import boto3 5 | 6 | print('Loading function') 7 | 8 | s3 = boto3.client('s3') 9 | 10 | 11 | def lambda_handler(event, context): 12 | #print("Received event: " + json.dumps(event, indent=2)) 13 | 14 | # Get the object from the event and show its content type 15 | bucket = event['Records'][0]['s3']['bucket']['name'] 16 | key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8') 17 | try: 18 | response = s3.get_object(Bucket=bucket, Key=key) 19 | print("CONTENT TYPE: " + response['ContentType']) 20 | return response['ContentType'] 21 | except Exception as e: 22 | print(e) 23 | print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket)) 24 | raise e 25 | -------------------------------------------------------------------------------- /python/s3-get-object-python3/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon S3 trigger that retrieves metadata for the object that has been 5 | updated. 6 | Parameters: 7 | BucketNamePrefix: 8 | Type: String 9 | Default: sam-example 10 | Resources: 11 | s3getobjectpython3: 12 | Type: 'AWS::Serverless::Function' 13 | Properties: 14 | Handler: lambda_function.lambda_handler 15 | Runtime: python3.6 16 | CodeUri: . 17 | Description: >- 18 | An Amazon S3 trigger that retrieves metadata for the object that has 19 | been updated. 20 | MemorySize: 128 21 | Timeout: 3 22 | Policies: 23 | - S3CrudPolicy: 24 | BucketName: !Sub "${BucketNamePrefix}-get-object-python3" 25 | Events: 26 | BucketEvent1: 27 | Type: S3 28 | Properties: 29 | Bucket: 30 | Ref: Bucket1 31 | Events: 32 | - 's3:ObjectCreated:*' 33 | Bucket1: 34 | Type: 'AWS::S3::Bucket' 35 | Properties: 36 | BucketName: !Sub "${BucketNamePrefix}-get-object-python3" 37 | -------------------------------------------------------------------------------- /python/ses-notification-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An Amazon SES notification handler for processing bounces, complaints and deliveries. 5 | Parameters: 6 | TableNameParameter: 7 | Type: String 8 | Resources: 9 | sesnotificationpython: 10 | Type: 'AWS::Serverless::Function' 11 | Properties: 12 | Handler: lambda_function.lambda_handler 13 | Runtime: python2.7 14 | CodeUri: . 15 | Description: >- 16 | An Amazon SES notification handler for processing bounces, complaints and deliveries. 17 | MemorySize: 128 18 | Timeout: 3 19 | Policies: 20 | - DynamoDBCrudPolicy: 21 | TableName: !Ref TableNameParameter -------------------------------------------------------------------------------- /python/slack-echo-command-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | A function that handles a Slack slash command and echoes the details back to 5 | the user. 6 | Parameters: 7 | KeyIdParameter: 8 | Type: String 9 | Resources: 10 | slackechocommandpython: 11 | Type: 'AWS::Serverless::Function' 12 | Properties: 13 | Handler: lambda_function.lambda_handler 14 | Runtime: python2.7 15 | CodeUri: . 16 | Description: >- 17 | A function that handles a Slack slash command and echoes the details 18 | back to the user. 19 | MemorySize: 128 20 | Timeout: 3 21 | Policies: 22 | - KMSDecryptPolicy: 23 | KeyId: !Ref KeyIdParameter 24 | Events: 25 | Api1: 26 | Type: Api 27 | Properties: 28 | Path: /MyResource 29 | Method: ANY 30 | Environment: 31 | Variables: 32 | kmsEncryptedToken: 33 | -------------------------------------------------------------------------------- /python/sns-message-python/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import json 4 | 5 | print('Loading function') 6 | 7 | 8 | def lambda_handler(event, context): 9 | #print("Received event: " + json.dumps(event, indent=2)) 10 | message = event['Records'][0]['Sns']['Message'] 11 | print("From SNS: " + message) 12 | return message 13 | -------------------------------------------------------------------------------- /python/sns-message-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: An Amazon SNS trigger that logs the message pushed to the SNS topic. 4 | Resources: 5 | snsmessagepython: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: lambda_function.lambda_handler 9 | Runtime: python2.7 10 | CodeUri: . 11 | Description: An Amazon SNS trigger that logs the message pushed to the SNS topic. 12 | MemorySize: 128 13 | Timeout: 3 14 | Events: 15 | SNS1: 16 | Type: SNS 17 | Properties: 18 | Topic: 19 | Ref: SNSTopic1 20 | SNSTopic1: 21 | Type: 'AWS::SNS::Topic' 22 | -------------------------------------------------------------------------------- /python/step-functions-error-python/lambda_function.py: -------------------------------------------------------------------------------- 1 | def lambda_handler(event, context): 2 | class CustomException(Exception): 3 | pass 4 | 5 | raise CustomException('This is a custom error!') 6 | -------------------------------------------------------------------------------- /python/step-functions-error-python/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: >- 4 | An AWS Lambda function that throws an error. AWS Step Functions state machines can be configured to handle (catch or retry) this error. 5 | Resources: 6 | stepfunctionserrorpython: 7 | Type: 'AWS::Serverless::Function' 8 | Properties: 9 | Handler: lambda_function.lambda_handler 10 | Runtime: python2.7 11 | CodeUri: . 12 | Description: >- 13 | An AWS Lambda function that throws an error. AWS Step Functions state machines can be configured to handle (catch or retry) this error. 14 | MemorySize: 128 15 | Timeout: 3 16 | Policies: 17 | - CloudWatchPutMetricPolicy: {} -------------------------------------------------------------------------------- /python/step-functions-send-to-sns/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import json 4 | import urllib 5 | import boto3 6 | 7 | print('Loading message function...') 8 | 9 | 10 | def send_to_sns(message, context): 11 | 12 | # This function receives JSON input with three fields: the ARN of an SNS topic, 13 | # a string with the subject of the message, and a string with the body of the message. 14 | # The message is then sent to the SNS topic. 15 | # 16 | # Example: 17 | # { 18 | # "topic": "arn:aws:sns:REGION:123456789012:MySNSTopic", 19 | # "subject": "This is the subject of the message.", 20 | # "message": "This is the body of the message." 21 | # } 22 | 23 | sns = boto3.client('sns') 24 | sns.publish( 25 | TopicArn=message['topic'], 26 | Subject=message['subject'], 27 | Message=message['body'] 28 | ) 29 | 30 | return ('Sent a message to an Amazon SNS topic.') 31 | -------------------------------------------------------------------------------- /python/step-functions-send-to-sns/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Sends an SNS message from input JSON 4 | Parameters: 5 | TopicNameParameter: 6 | Type: String 7 | Resources: 8 | stepfunctionssendtosns: 9 | Type: 'AWS::Serverless::Function' 10 | Properties: 11 | Handler: lambda_function.send_to_sns 12 | Runtime: python2.7 13 | CodeUri: . 14 | Description: Sends an SNS message from input JSON 15 | MemorySize: 128 16 | Timeout: 3 17 | Policies: 18 | - SNSPublishMessagePolicy: 19 | TopicName: !Ref TopicNameParameter -------------------------------------------------------------------------------- /python/vpn-conn-monitor/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: 'AWS::Serverless-2016-10-31' 3 | Description: Monitors VPN connection status of an account in all regions. 4 | Resources: 5 | vpnconnmonitor: 6 | Type: 'AWS::Serverless::Function' 7 | Properties: 8 | Handler: monitor_vpn_lambda.lambda_handler 9 | Runtime: python2.7 10 | CodeUri: . 11 | Description: Monitors VPN connection status of an account in all regions. 12 | MemorySize: 128 13 | Timeout: 120 14 | Policies: 15 | - CloudWatchPutMetricPolicy: {} 16 | - EC2VPNDescribePolicy: {} --------------------------------------------------------------------------------