From de44b336bb5a1c7362825293d3bdeea849ae3433 Mon Sep 17 00:00:00 2001 From: Nestor Carvantes Date: Wed, 10 Apr 2019 14:25:47 -0700 Subject: [PATCH 01/34] chore: Delete nodejs-upgrade-functions sample app --- .../apps/nodejs-upgrade-functions/index.js | 167 ------------------ .../nodejs-upgrade-functions/package.json | 8 - .../nodejs-upgrade-functions/template.yaml | 30 ---- 3 files changed, 205 deletions(-) delete mode 100644 examples/apps/nodejs-upgrade-functions/index.js delete mode 100644 examples/apps/nodejs-upgrade-functions/package.json delete mode 100644 examples/apps/nodejs-upgrade-functions/template.yaml diff --git a/examples/apps/nodejs-upgrade-functions/index.js b/examples/apps/nodejs-upgrade-functions/index.js deleted file mode 100644 index 3bd1125a2..000000000 --- a/examples/apps/nodejs-upgrade-functions/index.js +++ /dev/null @@ -1,167 +0,0 @@ -/* - This blueprint helps in transitioning Node.js v0.10 functions. It can be run in three modes: - - List: to list all existing Node.js v0.10 functions and their versions in the current region - - Backup: to publish a version of your current deprecated functions $LATEST version. - - Upgrade: to upgrade the runtime field of existing Node.js v0.10 functions $LATEST version from ‘nodejs’ to - ‘node.js4.3’ or ‘node.js6.10’ - - Notes: - - IMPORTANT: This blueprint only upgrades the runtime value of your nodejs v0.10 functions, you should test your - functions to make sure they behave as expected when operating in the new runtime environment. - - Creating Node.js v0.10 functions has been turned off since January 2017. When run in Backup mode, this blueprint - will publish a version of the existing code and configuration of your function. When run in Upgrade mode this - blueprint will upgrade the value of the runtime of $LATEST version of your function. You can point clients of your - existing function to the backup version if required while you work on validating the upgrade. - - If a function fails to backup or upgrade, this Lambda execution will stop and logs will be available in Cloud - Watch for debugging. - - If you have a large number of functions in your account, this function may take multiple invokes to upgrade your - functions. - - If you receive this error message: "The role defined for the function cannot be assumed by Lambda.", please - confirm that the function being upgraded has a correct execution role value and that role exists in IAM. Try - running this blueprint again after the error has been corrected. - - This blueprint is able to upgrade runtimes for the $LATEST version only. Please follow instructions in the - documentation to transition other versions. - - Usage: - 1. Create a function using this blueprint. The functions role should have listFunctions and - updateFunctionConfiguration privileges in its execution role. - 2. To list all existing Node.js v0.10 functions and their versions in the current region, run the function without any - change from the console. This displays the functions and versions as a json list both in the output pane on the console - as well as Cloudwatch logs. - 3. To publish backup versions of your listed functions before upgrading them, make the following changes to the - function's configuration: - a. Change the MODE environment variable's value to Backup. - b. Running this blueprint multiple times in backup mode will add multiple backups to your functions. - 4. To upgrade the runtime field of the listed functions to a newer value, make the following changes to the function’s - configuration: - a. Change the MODE environment variable’s value to Upgrade. - b. Change the TARGET_RUNTIME environment variable’s value to the runtime that you’d like to transition to. Valid - values are nodejs6.10 || nodejs8.10. - c. Change the EXCEPTIONS environment variable’s value to a list of function names to exclude them from being - upgraded. The value should be a comma separated list of function names alone, not ARNs. - d. Run the function from the console. - 5. Repeat step 4 multiple times if you have a lot of functions that need to be upgraded. - 6. Repeat steps 1-5 for all regions you have Lambda functions in. - */ - -'use strict'; - -const AWS = require('aws-sdk'); -const throat = require('throat'); - -const lambda = new AWS.Lambda(); -exports.handler = (event, context, callback) => { - const memory = { Functions: [], Versions: [] }; - const deprecatedRuntime = 'nodejs'; - const targetRuntime = process.env.TARGET_RUNTIME || 'nodejs6.10'; - const mode = (process.env.MODE || 'list').toLowerCase(); - const list = mode === 'list'; - const upgrade = mode === 'upgrade'; - const backup = mode === 'backup'; - const exceptions = process.env.EXCEPTIONS ? process.env.EXCEPTIONS.split(',') : []; - console.log(`Blueprint Deprecated Runtime set to ${deprecatedRuntime}`); - console.log(`Blueprint TARGET_RUNTIME set to ${targetRuntime}`); - console.log(`Blueprint MODE set to ${process.env.MODE}`); - console.log(`Blueprint EXCEPTIONS set to ${process.env.EXCEPTIONS}`); - - function report() { - const formatExample = { DeprecatedFunctionName: ['DeprecatedVersion1', 'DeprecatedVersion2'] }; - const functionNames = memory.Functions.map((fn) => { - const obj = {}; - obj[`${fn.FunctionName}`] = JSON.stringify(memory.Versions.filter(vs => vs.FunctionName === `${fn.FunctionName}`).map(vs => vs.Version)); - return obj; - }); - if (functionNames.length) { - functionNames.unshift(formatExample); - console.log('Printing deprecated functions and their corresponding deprecated versions.' + - 'The following functions runtimes will be upgraded. Example format: ', functionNames); - } else { - console.log('No deprecated functions found.'); - } - } - - function backupFunctions(functions) { - return Promise.all(functions.map(throat(1, (fn) => { - console.log(`Starting backup of function ${fn}`); - const params = { - FunctionName: fn, - Description: 'Node 0.10 Deprecation Blueprint Backup', - }; - return lambda.publishVersion(params).promise(); - }))); - } - - function upgradeFunctions(functions) { - return Promise.all(functions.map(throat(1, (fn) => { - console.log(`Starting runtime upgrade of function ${fn}`); - const params = { - FunctionName: fn, - Runtime: targetRuntime, - }; - return lambda.updateFunctionConfiguration(params).promise(); - }))); - } - - function getVersions(functions) { - return Promise.all(functions.map(throat(1, (fn) => { - const params = { - FunctionName: fn, - }; - return lambda.listVersionsByFunction(params).promise(); - }))); - } - - function getFunctions(params) { - lambda.listFunctions(params, (err, data) => { - if (err) { - callback(err, err.stack); - } else { - Array.prototype.push.apply(memory.Functions, data.Functions.filter((item) => item.Runtime === deprecatedRuntime && - exceptions.indexOf(item.FunctionName) === -1)); - if (data.NextMarker) { - const nextListFunctionsParams = { - Marker: data.NextMarker, - MaxItems: 50, - }; - setTimeout(() => getFunctions(nextListFunctionsParams), 100); - } else { - // retrieved all functions - console.log(`Total deprecated functions retreived: ${memory.Functions.length}`); - getVersions(memory.Functions.map(fn => fn.FunctionName)).then((versions) => { - memory.Versions = versions; - if (list) { - report(); - console.log('Report Complete.'); - } else if (backup) { - console.log(`Starting Function Backup Operation for ${memory.Functions.length} deprecated functions.`); - backupFunctions(memory.Functions.map(fn => fn.FunctionName)) - .then(() => { - console.log('Function Backup Operation Complete. See CloudWatch logs for Errors' + - ' that may have occurred.'); - }) - .catch((error) => { - console.log(error); - }); - } else if (upgrade) { - console.log(`Starting Function Upgrade Operation for ${memory.Functions.length} deprecated functions.`); - upgradeFunctions(memory.Functions.map(fn => fn.FunctionName)) - .then(() => { - console.log('Function Upgrade Operation Complete. See CloudWatch logs for Errors' + - ' that may have occurred.'); - }) - .catch((error) => { - console.log(error); - }); - } else { - console.log('no MODE environment variable specified.'); - } - }); - } - } - }); - } - const starterParams = { - MaxItems: 50, - }; - getFunctions(starterParams); -}; diff --git a/examples/apps/nodejs-upgrade-functions/package.json b/examples/apps/nodejs-upgrade-functions/package.json deleted file mode 100644 index 348d78f27..000000000 --- a/examples/apps/nodejs-upgrade-functions/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "nodejs-upgrade-functions", - "version": "1.0.0", - "private": true, - "dependencies": { - "throat": "^4.0.0" - } -} diff --git a/examples/apps/nodejs-upgrade-functions/template.yaml b/examples/apps/nodejs-upgrade-functions/template.yaml deleted file mode 100644 index 08df59c57..000000000 --- a/examples/apps/nodejs-upgrade-functions/template.yaml +++ /dev/null @@ -1,30 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: 'AWS::Serverless-2016-10-31' -Description: Upgrade deprecated Nodejs v0.10 functions to a newer runtime. -Parameters: - BucketNameParameter: - Type: String - CollectionIdParameter: - Type: String -Resources: - nodejsupgradefunctions: - Type: 'AWS::Serverless::Function' - Properties: - Handler: index.handler - Runtime: nodejs6.10 - CodeUri: . - Description: Upgrade deprecated Nodejs v0.10 functions to a newer runtime. - MemorySize: 128 - Timeout: 300 - Policies: - - S3CrudPolicy: - BucketName: !Ref BucketNameParameter - - RekognitionNoDataAccessPolicy: - CollectionId: !Ref CollectionIdParameter - - RekognitionWriteOnlyAccessPolicy: - CollectionId: !Ref CollectionIdParameter - Environment: - Variables: - EXCEPTIONS: - TARGET_RUNTIME: nodejs6.10 - MODE: List From 8798806bce073a20f4fbc03c5d87d1d35eede094 Mon Sep 17 00:00:00 2001 From: Nestor Carvantes Date: Wed, 10 Apr 2019 16:21:07 -0700 Subject: [PATCH 02/34] docs: update example apps from nodejs6.10 to nodejs8.10 (#883) Add sample test events --- .../template.yaml | 2 +- .../testEvent.json | 47 +++++++++++++++++++ .../apps/cloudfront-ab-test/template.yaml | 2 +- .../apps/cloudfront-ab-test/testEvent.json | 36 ++++++++++++++ .../template.yaml | 2 +- .../testEvent.json | 42 +++++++++++++++++ .../cloudfront-http-redirect/template.yaml | 2 +- .../template.yaml | 2 +- .../testEvent.json | 37 +++++++++++++++ .../template.yaml | 2 +- .../testEvent.json | 35 ++++++++++++++ .../template.yaml | 2 +- .../testEvent.json | 30 ++++++++++++ .../template.yaml | 2 +- .../testEvent.json | 30 ++++++++++++ .../template.yaml | 2 +- .../testEvent.json | 24 ++++++++++ .../template.yaml | 2 +- .../template.yaml | 2 +- .../testEvent.json | 36 ++++++++++++++ examples/apps/hello-world/template.yaml | 2 +- examples/apps/hello-world/testEvent.json | 5 ++ .../template.yaml | 2 +- .../testEvent.json | 11 +++++ .../template.yaml | 2 +- .../testEvent.json | 11 +++++ .../template.yaml | 2 +- .../testEvent.json | 11 +++++ .../template.yaml | 2 +- .../testEvent.json | 11 +++++ .../template.yaml | 2 +- .../testEvent.json | 27 +++++++++++ .../template.yaml | 2 +- .../testEvent.json | 19 ++++++++ .../template.yaml | 2 +- .../testEvent.json | 16 +++++++ .../microservice-http-endpoint/template.yaml | 2 +- examples/apps/node-exec/template.yaml | 2 +- examples/apps/node-exec/testEvent.json | 3 ++ examples/apps/s3-get-object/template.yaml | 2 +- examples/apps/s3-get-object/testEvent.json | 38 +++++++++++++++ 41 files changed, 491 insertions(+), 22 deletions(-) create mode 100644 examples/apps/alexa-skills-kit-color-expert/testEvent.json create mode 100644 examples/apps/cloudfront-ab-test/testEvent.json create mode 100644 examples/apps/cloudfront-access-request-in-response/testEvent.json create mode 100644 examples/apps/cloudfront-modify-querystring/testEvent.json create mode 100644 examples/apps/cloudfront-modify-response-header/testEvent.json create mode 100644 examples/apps/cloudfront-multiple-remote-calls-aggregate-response/testEvent.json create mode 100644 examples/apps/cloudfront-redirect-on-viewer-country/testEvent.json create mode 100644 examples/apps/cloudfront-redirect-unauthenticated-users/testEvent.json create mode 100644 examples/apps/cloudfront-simple-remote-call/testEvent.json create mode 100644 examples/apps/hello-world/testEvent.json create mode 100644 examples/apps/kinesis-analytics-process-compressed-record/testEvent.json create mode 100644 examples/apps/kinesis-analytics-process-record/testEvent.json create mode 100644 examples/apps/kinesis-firehose-apachelog-to-csv/testEvent.json create mode 100644 examples/apps/kinesis-firehose-apachelog-to-json/testEvent.json create mode 100644 examples/apps/kinesis-firehose-cloudwatch-logs-processor/testEvent.json create mode 100644 examples/apps/kinesis-firehose-process-record-streams-as-source/testEvent.json create mode 100644 examples/apps/kinesis-firehose-syslog-to-csv/testEvent.json create mode 100644 examples/apps/node-exec/testEvent.json create mode 100644 examples/apps/s3-get-object/testEvent.json diff --git a/examples/apps/alexa-skills-kit-color-expert/template.yaml b/examples/apps/alexa-skills-kit-color-expert/template.yaml index 7edc09a44..55169f45f 100644 --- a/examples/apps/alexa-skills-kit-color-expert/template.yaml +++ b/examples/apps/alexa-skills-kit-color-expert/template.yaml @@ -9,7 +9,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: Demonstrates a basic skill built with the Amazon Alexa Skills Kit. MemorySize: 128 diff --git a/examples/apps/alexa-skills-kit-color-expert/testEvent.json b/examples/apps/alexa-skills-kit-color-expert/testEvent.json new file mode 100644 index 000000000..4c76993ce --- /dev/null +++ b/examples/apps/alexa-skills-kit-color-expert/testEvent.json @@ -0,0 +1,47 @@ +{ + "version": "1.0", + "session": { + "new": false, + "sessionId": "amzn1.echo-api.session.123456789012", + "application": { + "applicationId": "amzn1.ask.skill.987654321" + }, + "attributes": {}, + "user": { + "userId": "amzn1.ask.account.testUser" + } + }, + "context": { + "AudioPlayer": { + "playerActivity": "IDLE" + }, + "System": { + "application": { + "applicationId": "amzn1.ask.skill.987654321" + }, + "user": { + "userId": "amzn1.ask.account.testUser" + }, + "device": { + "supportedInterfaces": { + "AudioPlayer": {} + } + } + } + }, + "request": { + "type": "IntentRequest", + "requestId": "amzn1.echo-api.request.1234", + "timestamp": "2016-10-27T21:06:28Z", + "locale": "en-US", + "intent": { + "name": "MyColorIsIntent", + "slots": { + "Color": { + "name": "Color", + "value": "blue" + } + } + } + } +} diff --git a/examples/apps/cloudfront-ab-test/template.yaml b/examples/apps/cloudfront-ab-test/template.yaml index 8ad8d9b9d..f2ad3d901 100644 --- a/examples/apps/cloudfront-ab-test/template.yaml +++ b/examples/apps/cloudfront-ab-test/template.yaml @@ -9,7 +9,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: 'Blueprint for CloudFront ab testing, implemented in NodeJS.' MemorySize: 128 diff --git a/examples/apps/cloudfront-ab-test/testEvent.json b/examples/apps/cloudfront-ab-test/testEvent.json new file mode 100644 index 000000000..8d3f7b11f --- /dev/null +++ b/examples/apps/cloudfront-ab-test/testEvent.json @@ -0,0 +1,36 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "/experiment-pixel.jpg", + "method": "GET", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "user-agent": [ + { + "key": "User-Agent", + "value": "Test Agent" + } + ], + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "cookie": [ + { + "key": "Cookie", + "value": "SomeCookie=1; AnotherOne=A;" + } + ] + } + } + } + } + ] +} diff --git a/examples/apps/cloudfront-access-request-in-response/template.yaml b/examples/apps/cloudfront-access-request-in-response/template.yaml index 17225c048..e755cf1ec 100644 --- a/examples/apps/cloudfront-access-request-in-response/template.yaml +++ b/examples/apps/cloudfront-access-request-in-response/template.yaml @@ -10,7 +10,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- Blueprint for setting CloudFront response header based on value in the request header implemented in NodeJS. diff --git a/examples/apps/cloudfront-access-request-in-response/testEvent.json b/examples/apps/cloudfront-access-request-in-response/testEvent.json new file mode 100644 index 000000000..258a53b65 --- /dev/null +++ b/examples/apps/cloudfront-access-request-in-response/testEvent.json @@ -0,0 +1,42 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "user-name": [ + { + "key": "User-Name", + "value": "CloudFront" + } + ] + }, + "clientIp": "2001:cdba::3257:9652", + "uri": "/test", + "method": "GET" + }, + "response": { + "status": "200", + "statusDescription": "OK", + "headers": { + "x-cache": [ + { + "key": "X-Cache", + "value": "Hello from Cloudfront" + } + ] + } + } + } + } + ] +} diff --git a/examples/apps/cloudfront-http-redirect/template.yaml b/examples/apps/cloudfront-http-redirect/template.yaml index a7928a716..5239605e3 100644 --- a/examples/apps/cloudfront-http-redirect/template.yaml +++ b/examples/apps/cloudfront-http-redirect/template.yaml @@ -9,7 +9,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: Blueprint for returning HTTP redirect implemented in NodeJS. MemorySize: 128 diff --git a/examples/apps/cloudfront-modify-querystring/template.yaml b/examples/apps/cloudfront-modify-querystring/template.yaml index fe62ad73d..2b65862f4 100644 --- a/examples/apps/cloudfront-modify-querystring/template.yaml +++ b/examples/apps/cloudfront-modify-querystring/template.yaml @@ -10,7 +10,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- Blueprint to add a header based on the values in a key-value pair in a query string. diff --git a/examples/apps/cloudfront-modify-querystring/testEvent.json b/examples/apps/cloudfront-modify-querystring/testEvent.json new file mode 100644 index 000000000..c296040a1 --- /dev/null +++ b/examples/apps/cloudfront-modify-querystring/testEvent.json @@ -0,0 +1,37 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "/test", + "querystring": "auth=test&foo=bar", + "method": "GET", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Test Agent" + } + ], + "user-name": [ + { + "key": "User-Name", + "value": "aws-cloudfront" + } + ] + } + } + } + } + ] +} diff --git a/examples/apps/cloudfront-modify-response-header/template.yaml b/examples/apps/cloudfront-modify-response-header/template.yaml index 2bc838d93..2276c30a1 100644 --- a/examples/apps/cloudfront-modify-response-header/template.yaml +++ b/examples/apps/cloudfront-modify-response-header/template.yaml @@ -9,7 +9,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- Blueprint for modifying CloudFront response header implemented in NodeJS. diff --git a/examples/apps/cloudfront-modify-response-header/testEvent.json b/examples/apps/cloudfront-modify-response-header/testEvent.json new file mode 100644 index 000000000..3e1b2f9f0 --- /dev/null +++ b/examples/apps/cloudfront-modify-response-header/testEvent.json @@ -0,0 +1,35 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "response": { + "status": "200", + "statusDescription": "OK", + "headers": { + "vary": [ + { + "key": "Vary", + "value": "*" + } + ], + "last-modified": [ + { + "key": "Last-Modified", + "value": "2016-11-25" + } + ], + "x-amz-meta-last-modified": [ + { + "key": "X-Amz-Meta-Last-Modified", + "value": "2016-01-01" + } + ] + } + } + } + } + ] +} diff --git a/examples/apps/cloudfront-multiple-remote-calls-aggregate-response/template.yaml b/examples/apps/cloudfront-multiple-remote-calls-aggregate-response/template.yaml index 5eb48bcad..0ac38b1a9 100644 --- a/examples/apps/cloudfront-multiple-remote-calls-aggregate-response/template.yaml +++ b/examples/apps/cloudfront-multiple-remote-calls-aggregate-response/template.yaml @@ -10,7 +10,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- Blueprint for generating aggregated response from multiple remote calls on origin-request trigger implemented in NodeJS. diff --git a/examples/apps/cloudfront-multiple-remote-calls-aggregate-response/testEvent.json b/examples/apps/cloudfront-multiple-remote-calls-aggregate-response/testEvent.json new file mode 100644 index 000000000..a3518e525 --- /dev/null +++ b/examples/apps/cloudfront-multiple-remote-calls-aggregate-response/testEvent.json @@ -0,0 +1,30 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "/forecast/Seattle:NewYork:Chicago:SanFrancisco", + "method": "GET", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Test Agent" + } + ] + } + } + } + } + ] +} diff --git a/examples/apps/cloudfront-redirect-on-viewer-country/template.yaml b/examples/apps/cloudfront-redirect-on-viewer-country/template.yaml index 8e1a6a9a1..a414a01a6 100644 --- a/examples/apps/cloudfront-redirect-on-viewer-country/template.yaml +++ b/examples/apps/cloudfront-redirect-on-viewer-country/template.yaml @@ -10,7 +10,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- Blueprint for generating a redirect response based on the viewer country. Triggered by an origin-request. Implemented in NodeJS. diff --git a/examples/apps/cloudfront-redirect-on-viewer-country/testEvent.json b/examples/apps/cloudfront-redirect-on-viewer-country/testEvent.json new file mode 100644 index 000000000..bfa6d15b6 --- /dev/null +++ b/examples/apps/cloudfront-redirect-on-viewer-country/testEvent.json @@ -0,0 +1,30 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "/test", + "method": "GET", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "cloudfront-viewer-country": [ + { + "key": "CloudFront-Viewer-Country", + "value": "TW" + } + ] + } + } + } + } + ] +} diff --git a/examples/apps/cloudfront-redirect-unauthenticated-users/template.yaml b/examples/apps/cloudfront-redirect-unauthenticated-users/template.yaml index 6f6d288d5..5828c9fff 100644 --- a/examples/apps/cloudfront-redirect-unauthenticated-users/template.yaml +++ b/examples/apps/cloudfront-redirect-unauthenticated-users/template.yaml @@ -10,7 +10,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- Blueprint for redirecting unauthenticated users to sign-in page; triggered by CloudFront viewer-request event. diff --git a/examples/apps/cloudfront-redirect-unauthenticated-users/testEvent.json b/examples/apps/cloudfront-redirect-unauthenticated-users/testEvent.json new file mode 100644 index 000000000..4f8e6ec1a --- /dev/null +++ b/examples/apps/cloudfront-redirect-unauthenticated-users/testEvent.json @@ -0,0 +1,24 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "/test", + "method": "GET", + "querystring": "foo=bar", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ] + } + } + } + } + ] +} diff --git a/examples/apps/cloudfront-response-generation/template.yaml b/examples/apps/cloudfront-response-generation/template.yaml index 7d339d823..c0c08cd42 100644 --- a/examples/apps/cloudfront-response-generation/template.yaml +++ b/examples/apps/cloudfront-response-generation/template.yaml @@ -10,7 +10,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- Blueprint for generating a response from viewer-request trigger implemented in NodeJS. diff --git a/examples/apps/cloudfront-simple-remote-call/template.yaml b/examples/apps/cloudfront-simple-remote-call/template.yaml index 17d44000b..be3a4d5f5 100644 --- a/examples/apps/cloudfront-simple-remote-call/template.yaml +++ b/examples/apps/cloudfront-simple-remote-call/template.yaml @@ -10,7 +10,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- Blueprint for generating a response from origin-request trigger diff --git a/examples/apps/cloudfront-simple-remote-call/testEvent.json b/examples/apps/cloudfront-simple-remote-call/testEvent.json new file mode 100644 index 000000000..1eaa48f92 --- /dev/null +++ b/examples/apps/cloudfront-simple-remote-call/testEvent.json @@ -0,0 +1,36 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "/test", + "method": "GET", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Test Agent" + } + ], + "user-name": [ + { + "key": "User-Name", + "value": "aws-cloudfront" + } + ] + } + } + } + } + ] +} diff --git a/examples/apps/hello-world/template.yaml b/examples/apps/hello-world/template.yaml index fe9712bc7..7e79099d9 100644 --- a/examples/apps/hello-world/template.yaml +++ b/examples/apps/hello-world/template.yaml @@ -9,7 +9,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: A starter AWS Lambda function. MemorySize: 128 diff --git a/examples/apps/hello-world/testEvent.json b/examples/apps/hello-world/testEvent.json new file mode 100644 index 000000000..fd2722e85 --- /dev/null +++ b/examples/apps/hello-world/testEvent.json @@ -0,0 +1,5 @@ +{ + "key1": "value1", + "key2": "value2", + "key3": "value3" +} diff --git a/examples/apps/kinesis-analytics-process-compressed-record/template.yaml b/examples/apps/kinesis-analytics-process-compressed-record/template.yaml index 836265b32..3b784ed9d 100644 --- a/examples/apps/kinesis-analytics-process-compressed-record/template.yaml +++ b/examples/apps/kinesis-analytics-process-compressed-record/template.yaml @@ -14,7 +14,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- An Amazon Kinesis Analytics record pre-processor that receives diff --git a/examples/apps/kinesis-analytics-process-compressed-record/testEvent.json b/examples/apps/kinesis-analytics-process-compressed-record/testEvent.json new file mode 100644 index 000000000..835449a4c --- /dev/null +++ b/examples/apps/kinesis-analytics-process-compressed-record/testEvent.json @@ -0,0 +1,11 @@ +{ + "invocationId": "invocationIdExample", + "applicationArn": "arn:aws:kinesisanalytics:us-east-1:123456789012:application/example-application", + "streamArn": "arn:aws:kinesis:us-east-1:123456789012:stream/example-stream", + "records": [ + { + "recordId": "49571347871967966406409637155186850213682522142927749122", + "data": "H4sIAAAAAAAA/6vmUspLzE1VslLKTsxNzFHS4VJKTEkpSi0uBgol5SRmKHHVAgDd1tysJAAAAA==" + } + ] +} diff --git a/examples/apps/kinesis-analytics-process-record/template.yaml b/examples/apps/kinesis-analytics-process-record/template.yaml index 615ea2698..f31ed620f 100644 --- a/examples/apps/kinesis-analytics-process-record/template.yaml +++ b/examples/apps/kinesis-analytics-process-record/template.yaml @@ -14,7 +14,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- An Amazon Kinesis Analytics record pre-processor that receives JSON or diff --git a/examples/apps/kinesis-analytics-process-record/testEvent.json b/examples/apps/kinesis-analytics-process-record/testEvent.json new file mode 100644 index 000000000..bb7fbd446 --- /dev/null +++ b/examples/apps/kinesis-analytics-process-record/testEvent.json @@ -0,0 +1,11 @@ +{ + "invocationId": "invocationIdExample", + "applicationArn": "arn:aws:kinesisanalytics:us-east-1:123456789012:application/example-application", + "streamArn": "arn:aws:kinesis:us-east-1:123456789012:stream/example-stream", + "records": [ + { + "recordId": "49571347871967966406409637155186850213682522142927749122", + "data": "VGhpcyBpcyBhIHRlc3QgZnJvbSBLaW5lc2lzIEFuYWx5dGljcw==" + } + ] +} diff --git a/examples/apps/kinesis-firehose-apachelog-to-csv/template.yaml b/examples/apps/kinesis-firehose-apachelog-to-csv/template.yaml index 8362fb286..a4194a3d1 100644 --- a/examples/apps/kinesis-firehose-apachelog-to-csv/template.yaml +++ b/examples/apps/kinesis-firehose-apachelog-to-csv/template.yaml @@ -13,7 +13,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- An Amazon Kinesis Firehose stream processor that converts input records diff --git a/examples/apps/kinesis-firehose-apachelog-to-csv/testEvent.json b/examples/apps/kinesis-firehose-apachelog-to-csv/testEvent.json new file mode 100644 index 000000000..daf0b4243 --- /dev/null +++ b/examples/apps/kinesis-firehose-apachelog-to-csv/testEvent.json @@ -0,0 +1,11 @@ +{ + "invocationId": "invocationIdExample", + "region": "us-east-1", + "records": [ + { + "recordId": "49546986683135544286507457936321625675700192471156785154", + "approximateArrivalTimestamp": 1495072949453, + "data": "NjQuMjQyLjg4LjEwIC0gLSBbMDcvTWFyLzIwMDQ6MTY6MTA6MDIgLTA4MDBdICJHRVQgL21haWxtYW4vbGlzdGluZm8vaHNkaXZpc2lvbiBIVFRQLzEuMSIgMjAwIDYyOTE==" + } + ] +} diff --git a/examples/apps/kinesis-firehose-apachelog-to-json/template.yaml b/examples/apps/kinesis-firehose-apachelog-to-json/template.yaml index ecec7ba08..849b876dc 100644 --- a/examples/apps/kinesis-firehose-apachelog-to-json/template.yaml +++ b/examples/apps/kinesis-firehose-apachelog-to-json/template.yaml @@ -13,7 +13,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- An Amazon Kinesis Firehose stream processor that converts input records diff --git a/examples/apps/kinesis-firehose-apachelog-to-json/testEvent.json b/examples/apps/kinesis-firehose-apachelog-to-json/testEvent.json new file mode 100644 index 000000000..daf0b4243 --- /dev/null +++ b/examples/apps/kinesis-firehose-apachelog-to-json/testEvent.json @@ -0,0 +1,11 @@ +{ + "invocationId": "invocationIdExample", + "region": "us-east-1", + "records": [ + { + "recordId": "49546986683135544286507457936321625675700192471156785154", + "approximateArrivalTimestamp": 1495072949453, + "data": "NjQuMjQyLjg4LjEwIC0gLSBbMDcvTWFyLzIwMDQ6MTY6MTA6MDIgLTA4MDBdICJHRVQgL21haWxtYW4vbGlzdGluZm8vaHNkaXZpc2lvbiBIVFRQLzEuMSIgMjAwIDYyOTE==" + } + ] +} diff --git a/examples/apps/kinesis-firehose-cloudwatch-logs-processor/template.yaml b/examples/apps/kinesis-firehose-cloudwatch-logs-processor/template.yaml index 0ee0d6072..8645e1cf8 100644 --- a/examples/apps/kinesis-firehose-cloudwatch-logs-processor/template.yaml +++ b/examples/apps/kinesis-firehose-cloudwatch-logs-processor/template.yaml @@ -10,7 +10,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- An Amazon Kinesis Firehose stream processor that extracts individual log events from records sent by Cloudwatch Logs subscription filters. diff --git a/examples/apps/kinesis-firehose-cloudwatch-logs-processor/testEvent.json b/examples/apps/kinesis-firehose-cloudwatch-logs-processor/testEvent.json new file mode 100644 index 000000000..9a562a0ac --- /dev/null +++ b/examples/apps/kinesis-firehose-cloudwatch-logs-processor/testEvent.json @@ -0,0 +1,27 @@ +{ + "records": [ + { + "recordId": "49578734086442259037497492980620233840400173390482112514000000", + "data": "H4sIAAAAAAAAADWO0QqCMBiFX2XsWiJFi7wLUW8sIYUuQmLpnxvpJttMQnz3Ztrlxzmc8424BaVIDfmnA+zjID3nlzS5n8IsO8YhtrAYOMg5aURfDUSXNBG1MkEj6liKvjPZQpmWQNoFVf9QpWSdZoJHrNEgFfZvxa8XvoHrGUfMqqWumdHQpDVjtmdvHc91dwdn71p/vVngmqBVD616PgoolC/Ga0SBNJoi8USVWWKczM8oYhKoULDBUzF9Aeua5yHsAAAA", + "approximateArrivalTimestamp": 1510254469499 + }, + { + "recordId": "49578734086442259037497492980621442766219788363254202370000000", + "data": "H4sIAAAAAAAAAJWRTWsbMRCG/8ueLZjRjL5yc9NNLnZDapemlFAkrTYstb3Lep0Qgv97x00KgTSHnAQzmkeP3nmqtmW/j3dl/TiU6qz6PF/Pfy3r1Wp+WVezqn/YlVHK2pK3Hr0Jxkt5099djv1hkE7uh0eVHzZqE7epiarb3fe/ixzDYVJoELRhssYQqsXLlEJ3jd8//biy4QYWz7jVNJa4/TDveQwV+qsada0v/HnthLg/pH0eu2Hq+t1Ft5nKuK/Ofn4EvnpDUAu7Xi6/LL9en3/z1e1f7fq+7KYT+qnqGrEnsi54AGS2wbHWxjCjoWAYGawmzawByIG3Dp0JzjOxsaI8dbKJKW4l1BcTdgg+zP5tSPCeQ/Bso/I+o+I2kUptjgrRlQyasslUHWdvZRwGJ4+HYJGCtiKgQTYKSJ4gODLgAkpFk3f0rkyA1zLGSsvoVsVCRTFakUkNqKxt1IyFc8T/y0gEmoHZo5a/W9HhU0TeWHMyIJaoQC6zDvC+DL6WSW3MqZSkiolJcWoalWybJSNIJTXcRgjV8fb4BwwLrNzwAgAA", + "approximateArrivalTimestamp": 1510254473773 + }, + { + "recordId": "49578734086442259037497492980622651692039402992428908546000000", + "data": "H4sIAAAAAAAAAJWRbWsbMQyA/8t9jkGSJdnut2zLCiXZyJKyZaMM352vHEty4e7SUkr++9yXwUbXD8Vgg2w9eizdF7s0DPE6re8OqTgrPkzX05+L2Wo1PZ8Vk6K73ac+h0mtV49egvgc3nbX5313POSbqjvcmep2a7ZxV9bRtPub7lfKx+E4GhQEErYqYtHMn7MMuiV+fbf5rOEbzJ9wq7FPcfdm3lOaNReXyws/3cw2fvk9A4djOVR9exjbbv+x3Y6pH4qzH29hr14QzFzXi8WnxZfl+0tfXD1az27SfnxA3xdtneWtVRc8ADJrcEwkwoxigzAyiBNxzkJuIxGrei+g3gbgrDy2eRBj3OWePpuwQ/Bh8mdAGR+J69pJMFXKihwTGJ+aYJArpkjYQB2K0+SljMPgyFIIijaQgs2BAMEyexbns1NeoqpsCV+VCfCPTOVLLgUMU4h5S5UpE4BRm6ROqCEF/r8MExBDro3ED0XBMigFVM0iQlkRvZLml9a/LoN/yzSYKoIKTOmVTf6VNTHZxkjTIElkqlCL09XpN5PgkxrvAgAA", + "approximateArrivalTimestamp": 1510254474027 + }, + { + "recordId": "49578734086442259037497492980623860617859017621603614722000000", + "data": "H4sIAAAAAAAAAJWRW28aQQyF/8s+M9J47LHHeaMtzUOhEQXSVlVUDctstCqwCJZEUcR/r3OpFCnNQ17mcjw+8+n4vtqUwyFfl/ndrlRn1afhfPh7MprNhuejalB1t9uyNzkwJk6QosZk8rq7Pt93x51V6m535+rbtVvnzXKVXbu96f4U23bH3kEEHyIhx4jgxs9dDmQK3z/8vGD94cdPdrN+X/Lm3X5PbcHp5QLkYrqYLC6/mOHhuDzU+3bXt932c7vuy/5Qnf16j/fslYMb83wy+Tr5Nv24SNXVI/Xopmz7B+v7ql0ZPCKLJu+BiFUohBiJIKJGAvIkSTgpsU8aVBNangymsCH3rQ2izxvL9JmEBOzh4N+AzL6gX3JD7CLn4kg8OiVduahNkIa0BtbqNHgNI6AS0P5kQA3sUcA4IDCElCBKwgdgiCoI+CaM+pcwbAVfN8F5r2owGV0OdpWkS8kp52a1/D8MBR8sDUoQKDIbDnqlhAgQLTMWz8YbRQT92zDwEkbIQ10YHUZbKGfvUmrAIWodih2btKpOV6e/zXGIX+8CAAA=", + "approximateArrivalTimestamp": 1510254474388 + } + ], + "region": "us-east-1", + "deliveryStreamArn": "arn:aws:firehose:us-east-1:123456789012:deliverystream/copy-cwl-lambda-invoke-input-151025436553-Firehose-8KILJ01Q5OBN", + "invocationId": "a7234216-12b6-4bc0-96d7-82606c0e80cf" +} diff --git a/examples/apps/kinesis-firehose-process-record-streams-as-source/template.yaml b/examples/apps/kinesis-firehose-process-record-streams-as-source/template.yaml index aa67bdecc..781807150 100644 --- a/examples/apps/kinesis-firehose-process-record-streams-as-source/template.yaml +++ b/examples/apps/kinesis-firehose-process-record-streams-as-source/template.yaml @@ -12,7 +12,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- An Amazon Kinesis Firehose stream processor that accesses the Kinesis Streams records in the input and returns them with a processing status. diff --git a/examples/apps/kinesis-firehose-process-record-streams-as-source/testEvent.json b/examples/apps/kinesis-firehose-process-record-streams-as-source/testEvent.json new file mode 100644 index 000000000..deb243e4f --- /dev/null +++ b/examples/apps/kinesis-firehose-process-record-streams-as-source/testEvent.json @@ -0,0 +1,19 @@ +{ + "invocationId": "invocationIdExample", + "deliverySteamArn": "arn:aws:kinesis:EXAMPLE", + "region": "us-east-1", + "records": [ + { + "recordId": "49546986683135544286507457936321625675700192471156785154", + "approximateArrivalTimestamp": 1495072949453, + "kinesisRecordMetadata": { + "sequenceNumber": "49545115243490985018280067714973144582180062593244200961", + "subsequenceNumber": "123456", + "partitionKey": "partitionKey-03", + "shardId": "shardId-000000000000", + "approximateArrivalTimestamp": 1495072949453 + }, + "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=" + } + ] +} diff --git a/examples/apps/kinesis-firehose-syslog-to-csv/template.yaml b/examples/apps/kinesis-firehose-syslog-to-csv/template.yaml index 31f5e83ef..172222e59 100644 --- a/examples/apps/kinesis-firehose-syslog-to-csv/template.yaml +++ b/examples/apps/kinesis-firehose-syslog-to-csv/template.yaml @@ -12,7 +12,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- An Amazon Kinesis Firehose stream processor that converts input records from RFC3164 Syslog format to CSV. diff --git a/examples/apps/kinesis-firehose-syslog-to-csv/testEvent.json b/examples/apps/kinesis-firehose-syslog-to-csv/testEvent.json new file mode 100644 index 000000000..8d867f528 --- /dev/null +++ b/examples/apps/kinesis-firehose-syslog-to-csv/testEvent.json @@ -0,0 +1,16 @@ +{ + "invocationId": "fir", + "region": "us-east-1", + "records": [ + { + "recordId": "49546986683135544286507457936321625675700192471156785154", + "approximateArrivalTimestamp": 1495072949453, + "data": "SmFuIDEyIDA2OjMwOjAwIDEuMi4zLjQgYXBhY2hlX3NlcnZlcjogMS4yLjMuNCAtIC0gWzEyL0phbi8yMDExOjA2OjI5OjU5ICswMTAwXSAiR0VUIC9mb28vYmFyLmh0bWwgSFRUUC8xLjEiIDMwMSA5NiAiLSIgIk1vemlsbGEvNS4wIChXaW5kb3dzOyBVOyBXaW5kb3dzIE5UIDUuMTsgZnI7IHJ2OjEuOS4yLjEyKSBHZWNrby8yMDEwMTAyNiBGaXJlZm94LzMuNi4xMiAoIC5ORVQgQ0xSIDMuNS4zMDcyOSkiIFBJRCAxODkwNCBUaW1lIFRha2VuIDA=" + }, + { + "recordId": "49546986683135544286507457936321625675700192471156785154", + "approximateArrivalTimestamp": "2012-04-23T18:25:43.511Z", + "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=" + } + ] +} diff --git a/examples/apps/microservice-http-endpoint/template.yaml b/examples/apps/microservice-http-endpoint/template.yaml index afe573092..986be557d 100644 --- a/examples/apps/microservice-http-endpoint/template.yaml +++ b/examples/apps/microservice-http-endpoint/template.yaml @@ -10,7 +10,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway. diff --git a/examples/apps/node-exec/template.yaml b/examples/apps/node-exec/template.yaml index 67fc630bf..3150c841a 100644 --- a/examples/apps/node-exec/template.yaml +++ b/examples/apps/node-exec/template.yaml @@ -12,7 +12,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- Demonstrates running an external process using the Node.js child_process module. diff --git a/examples/apps/node-exec/testEvent.json b/examples/apps/node-exec/testEvent.json new file mode 100644 index 000000000..a3ed7c7b2 --- /dev/null +++ b/examples/apps/node-exec/testEvent.json @@ -0,0 +1,3 @@ +{ + "cmd": "pwd" +} diff --git a/examples/apps/s3-get-object/template.yaml b/examples/apps/s3-get-object/template.yaml index 9a813e419..9ab349e87 100644 --- a/examples/apps/s3-get-object/template.yaml +++ b/examples/apps/s3-get-object/template.yaml @@ -12,7 +12,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler - Runtime: nodejs6.10 + Runtime: nodejs8.10 CodeUri: . Description: >- An Amazon S3 trigger that retrieves metadata for the object that has diff --git a/examples/apps/s3-get-object/testEvent.json b/examples/apps/s3-get-object/testEvent.json new file mode 100644 index 000000000..23ead1551 --- /dev/null +++ b/examples/apps/s3-get-object/testEvent.json @@ -0,0 +1,38 @@ +{ + "Records": [ + { + "eventVersion": "2.0", + "eventSource": "aws:s3", + "awsRegion": "us-east-1", + "eventTime": "1970-01-01T00:00:00.000Z", + "eventName": "ObjectCreated:Put", + "userIdentity": { + "principalId": "EXAMPLE" + }, + "requestParameters": { + "sourceIPAddress": "127.0.0.1" + }, + "responseElements": { + "x-amz-request-id": "EXAMPLE123456789", + "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH" + }, + "s3": { + "s3SchemaVersion": "1.0", + "configurationId": "testConfigRule", + "bucket": { + "name": "example-bucket-get-object", + "ownerIdentity": { + "principalId": "EXAMPLE" + }, + "arn": "arn:aws:s3:::example-bucket-get-object" + }, + "object": { + "key": "test/key", + "size": 1024, + "eTag": "0123456789abcdef0123456789abcdef", + "sequencer": "0A1B2C3D4E5F678901" + } + } + } + ] +} From 1fd6dc3b20b0d68110291ef7c38b0c059391804f Mon Sep 17 00:00:00 2001 From: Nestor Carvantes Date: Wed, 10 Apr 2019 18:50:37 -0700 Subject: [PATCH 03/34] chore: Delete misplaced package.json in several example apps --- examples/apps/cloudfront-ab-test/package.json | 8 -------- .../cloudfront-access-request-in-response/package.json | 8 -------- examples/apps/cloudfront-http-redirect/package.json | 8 -------- examples/apps/cloudfront-modify-querystring/package.json | 8 -------- .../apps/cloudfront-modify-response-header/package.json | 8 -------- .../package.json | 8 -------- .../cloudfront-redirect-on-viewer-country/package.json | 8 -------- examples/apps/cloudfront-response-generation/package.json | 8 -------- examples/apps/cloudfront-simple-remote-call/package.json | 8 -------- 9 files changed, 72 deletions(-) delete mode 100644 examples/apps/cloudfront-ab-test/package.json delete mode 100644 examples/apps/cloudfront-access-request-in-response/package.json delete mode 100644 examples/apps/cloudfront-http-redirect/package.json delete mode 100644 examples/apps/cloudfront-modify-querystring/package.json delete mode 100644 examples/apps/cloudfront-modify-response-header/package.json delete mode 100644 examples/apps/cloudfront-multiple-remote-calls-aggregate-response/package.json delete mode 100644 examples/apps/cloudfront-redirect-on-viewer-country/package.json delete mode 100644 examples/apps/cloudfront-response-generation/package.json delete mode 100644 examples/apps/cloudfront-simple-remote-call/package.json diff --git a/examples/apps/cloudfront-ab-test/package.json b/examples/apps/cloudfront-ab-test/package.json deleted file mode 100644 index 02d6a7da6..000000000 --- a/examples/apps/cloudfront-ab-test/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "algorithmia-blueprint", - "version": "1.0.0", - "private": true, - "dependencies": { - "algorithmia": "^0.3.9" - } -} diff --git a/examples/apps/cloudfront-access-request-in-response/package.json b/examples/apps/cloudfront-access-request-in-response/package.json deleted file mode 100644 index 02d6a7da6..000000000 --- a/examples/apps/cloudfront-access-request-in-response/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "algorithmia-blueprint", - "version": "1.0.0", - "private": true, - "dependencies": { - "algorithmia": "^0.3.9" - } -} diff --git a/examples/apps/cloudfront-http-redirect/package.json b/examples/apps/cloudfront-http-redirect/package.json deleted file mode 100644 index 02d6a7da6..000000000 --- a/examples/apps/cloudfront-http-redirect/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "algorithmia-blueprint", - "version": "1.0.0", - "private": true, - "dependencies": { - "algorithmia": "^0.3.9" - } -} diff --git a/examples/apps/cloudfront-modify-querystring/package.json b/examples/apps/cloudfront-modify-querystring/package.json deleted file mode 100644 index 02d6a7da6..000000000 --- a/examples/apps/cloudfront-modify-querystring/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "algorithmia-blueprint", - "version": "1.0.0", - "private": true, - "dependencies": { - "algorithmia": "^0.3.9" - } -} diff --git a/examples/apps/cloudfront-modify-response-header/package.json b/examples/apps/cloudfront-modify-response-header/package.json deleted file mode 100644 index 02d6a7da6..000000000 --- a/examples/apps/cloudfront-modify-response-header/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "algorithmia-blueprint", - "version": "1.0.0", - "private": true, - "dependencies": { - "algorithmia": "^0.3.9" - } -} diff --git a/examples/apps/cloudfront-multiple-remote-calls-aggregate-response/package.json b/examples/apps/cloudfront-multiple-remote-calls-aggregate-response/package.json deleted file mode 100644 index 02d6a7da6..000000000 --- a/examples/apps/cloudfront-multiple-remote-calls-aggregate-response/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "algorithmia-blueprint", - "version": "1.0.0", - "private": true, - "dependencies": { - "algorithmia": "^0.3.9" - } -} diff --git a/examples/apps/cloudfront-redirect-on-viewer-country/package.json b/examples/apps/cloudfront-redirect-on-viewer-country/package.json deleted file mode 100644 index 02d6a7da6..000000000 --- a/examples/apps/cloudfront-redirect-on-viewer-country/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "algorithmia-blueprint", - "version": "1.0.0", - "private": true, - "dependencies": { - "algorithmia": "^0.3.9" - } -} diff --git a/examples/apps/cloudfront-response-generation/package.json b/examples/apps/cloudfront-response-generation/package.json deleted file mode 100644 index 02d6a7da6..000000000 --- a/examples/apps/cloudfront-response-generation/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "algorithmia-blueprint", - "version": "1.0.0", - "private": true, - "dependencies": { - "algorithmia": "^0.3.9" - } -} diff --git a/examples/apps/cloudfront-simple-remote-call/package.json b/examples/apps/cloudfront-simple-remote-call/package.json deleted file mode 100644 index 02d6a7da6..000000000 --- a/examples/apps/cloudfront-simple-remote-call/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "algorithmia-blueprint", - "version": "1.0.0", - "private": true, - "dependencies": { - "algorithmia": "^0.3.9" - } -} From 4e8723aa3d3eb10ded304a71cd3d952161ca2bcd Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Fri, 12 Apr 2019 23:25:24 -0700 Subject: [PATCH 04/34] chore: run cfn lint on translator test output (#888) --- docs/cloudformation_compatibility.rst | 2 +- requirements/dev.txt | 1 + samtranslator/model/cloudformation.py | 2 +- samtranslator/model/sam_resources.py | 4 +- .../input/api_endpoint_configuration.yaml | 2 +- .../input/api_with_auth_all_minimum.yaml | 21 +- .../input/api_with_auth_no_default.yaml | 21 +- tests/translator/input/api_with_cors.yaml | 13 +- ..._with_cors_and_only_credentials_false.yaml | 7 +- .../input/api_with_cors_and_only_maxage.yaml | 7 +- .../input/api_with_resource_refs.yaml | 13 +- tests/translator/input/basic_application.yaml | 9 +- tests/translator/input/basic_function.yaml | 10 +- .../input/basic_function_with_tags.yaml | 2 +- tests/translator/input/basic_layer.yaml | 10 +- tests/translator/input/depends_on.yaml | 4 +- tests/translator/input/explicit_api.yaml | 3 + .../input/function_managed_inline_policy.yaml | 6 +- ...function_with_alias_and_event_sources.yaml | 7 +- .../input/function_with_condition.yaml | 7 +- ...ction_with_deployment_and_custom_role.yaml | 2 +- .../input/function_with_layers.yaml | 4 +- .../input/function_with_many_layers.yaml | 4 +- .../input/function_with_resource_refs.yaml | 21 +- tests/translator/input/globals_for_api.yaml | 13 + .../input/globals_for_function.yaml | 8 +- ...api_with_serverless_rest_api_resource.yaml | 2 +- .../translator/input/intrinsic_functions.yaml | 32 +- .../input/layers_all_properties.yaml | 2 - ...api_with_serverless_rest_api_resource.yaml | 14 + ...ting_other_notification_configuration.yaml | 1 + tests/translator/input/s3_with_condition.yaml | 5 + .../simple_table_ref_parameter_intrinsic.yaml | 10 + .../input/simple_table_with_extra_tags.yaml | 7 +- .../input/simple_table_with_table_name.yaml | 5 + .../output/api_endpoint_configuration.json | 4 +- .../output/api_with_auth_all_minimum.json | 596 ++++++++++------- .../output/api_with_auth_no_default.json | 582 +++++++++------- tests/translator/output/api_with_cors.json | 174 +++-- ..._with_cors_and_only_credentials_false.json | 59 +- .../output/api_with_cors_and_only_maxage.json | 47 ++ .../output/api_with_resource_refs.json | 18 +- .../aws-cn/api_endpoint_configuration.json | 4 +- .../aws-cn/api_with_auth_all_minimum.json | 630 ++++++++++-------- .../aws-cn/api_with_auth_no_default.json | 618 +++++++++-------- .../output/aws-cn/api_with_cors.json | 106 ++- ..._with_cors_and_only_credentials_false.json | 59 +- .../aws-cn/api_with_cors_and_only_maxage.json | 47 ++ .../output/aws-cn/api_with_resource_refs.json | 18 +- .../output/aws-cn/basic_application.json | 102 +-- .../output/aws-cn/basic_function.json | 236 +++---- .../aws-cn/basic_function_with_tags.json | 2 +- .../translator/output/aws-cn/basic_layer.json | 82 ++- .../translator/output/aws-cn/depends_on.json | 4 +- .../output/aws-cn/error_missing_queue.json | 6 - .../output/aws-cn/error_missing_stream.json | 6 - .../aws-cn/existing_event_logical_id.json | 8 - .../existing_permission_logical_id.json | 8 - .../aws-cn/existing_role_logical_id.json | 8 - .../output/aws-cn/explicit_api.json | 18 +- .../function_managed_inline_policy.json | 22 +- ...function_with_alias_and_event_sources.json | 23 +- .../aws-cn/function_with_condition.json | 22 +- ...ction_with_deployment_and_custom_role.json | 9 +- .../output/aws-cn/function_with_layers.json | 298 +++++---- .../aws-cn/function_with_many_layers.json | 80 ++- .../aws-cn/function_with_resource_refs.json | 60 +- .../output/aws-cn/globals_for_api.json | 161 +++-- .../output/aws-cn/globals_for_function.json | 40 +- .../output/aws-cn/intrinsic_functions.json | 473 +++++++------ .../output/aws-cn/layers_all_properties.json | 170 +++-- ...api_with_serverless_rest_api_resource.json | 137 +++- ...ting_other_notification_configuration.json | 15 +- .../output/aws-cn/s3_with_condition.json | 44 +- .../simple_table_ref_parameter_intrinsic.json | 14 + .../aws-cn/simple_table_with_extra_tags.json | 8 +- .../aws-cn/simple_table_with_table_name.json | 6 + .../api_endpoint_configuration.json | 4 +- .../aws-us-gov/api_with_auth_all_minimum.json | 626 +++++++++-------- .../aws-us-gov/api_with_auth_no_default.json | 606 +++++++++-------- .../output/aws-us-gov/api_with_cors.json | 106 ++- ..._with_cors_and_only_credentials_false.json | 59 +- .../api_with_cors_and_only_maxage.json | 47 ++ .../aws-us-gov/api_with_resource_refs.json | 18 +- .../output/aws-us-gov/basic_application.json | 102 +-- .../output/aws-us-gov/basic_function.json | 408 ++++++------ .../aws-us-gov/basic_function_with_tags.json | 2 +- .../output/aws-us-gov/basic_layer.json | 82 ++- .../output/aws-us-gov/depends_on.json | 4 +- .../aws-us-gov/error_missing_queue.json | 6 - .../aws-us-gov/error_missing_stream.json | 6 - .../aws-us-gov/existing_event_logical_id.json | 8 - .../existing_permission_logical_id.json | 8 - .../aws-us-gov/existing_role_logical_id.json | 8 - .../output/aws-us-gov/explicit_api.json | 18 +- .../function_managed_inline_policy.json | 22 +- ...function_with_alias_and_event_sources.json | 23 +- .../aws-us-gov/function_with_condition.json | 22 +- ...ction_with_deployment_and_custom_role.json | 9 +- .../aws-us-gov/function_with_layers.json | 298 +++++---- .../aws-us-gov/function_with_many_layers.json | 80 ++- .../function_with_resource_refs.json | 60 +- .../output/aws-us-gov/globals_for_api.json | 175 ++--- .../aws-us-gov/globals_for_function.json | 40 +- .../aws-us-gov/intrinsic_functions.json | 473 +++++++------ .../aws-us-gov/layers_all_properties.json | 170 +++-- ...api_with_serverless_rest_api_resource.json | 134 +++- ...ting_other_notification_configuration.json | 15 +- .../output/aws-us-gov/s3_with_condition.json | 44 +- .../simple_table_ref_parameter_intrinsic.json | 14 + .../simple_table_with_extra_tags.json | 8 +- .../simple_table_with_table_name.json | 6 + .../translator/output/basic_application.json | 102 +-- tests/translator/output/basic_function.json | 234 +++---- .../output/basic_function_with_tags.json | 2 +- tests/translator/output/basic_layer.json | 82 ++- tests/translator/output/depends_on.json | 4 +- tests/translator/output/explicit_api.json | 18 +- .../function_managed_inline_policy.json | 20 +- ...function_with_alias_and_event_sources.json | 23 +- .../output/function_with_condition.json | 22 +- ...ction_with_deployment_and_custom_role.json | 9 +- .../output/function_with_layers.json | 298 +++++---- .../output/function_with_many_layers.json | 80 ++- .../output/function_with_resource_refs.json | 60 +- tests/translator/output/globals_for_api.json | 149 +++-- .../output/globals_for_function.json | 40 +- .../output/intrinsic_functions.json | 441 ++++++------ .../output/layers_all_properties.json | 170 +++-- ...api_with_serverless_rest_api_resource.json | 134 +++- ...ting_other_notification_configuration.json | 15 +- .../translator/output/s3_with_condition.json | 44 +- .../simple_table_ref_parameter_intrinsic.json | 14 + .../output/simple_table_with_extra_tags.json | 8 +- .../output/simple_table_with_table_name.json | 6 + tests/translator/test_translator.py | 39 +- tests/translator/validator/test_validator.py | 1 - versions/2016-10-31.md | 2 +- 138 files changed, 6508 insertions(+), 4525 deletions(-) delete mode 100644 tests/translator/output/aws-cn/error_missing_queue.json delete mode 100644 tests/translator/output/aws-cn/error_missing_stream.json delete mode 100644 tests/translator/output/aws-cn/existing_event_logical_id.json delete mode 100644 tests/translator/output/aws-cn/existing_permission_logical_id.json delete mode 100644 tests/translator/output/aws-cn/existing_role_logical_id.json delete mode 100644 tests/translator/output/aws-us-gov/error_missing_queue.json delete mode 100644 tests/translator/output/aws-us-gov/error_missing_stream.json delete mode 100644 tests/translator/output/aws-us-gov/existing_event_logical_id.json delete mode 100644 tests/translator/output/aws-us-gov/existing_permission_logical_id.json delete mode 100644 tests/translator/output/aws-us-gov/existing_role_logical_id.json diff --git a/docs/cloudformation_compatibility.rst b/docs/cloudformation_compatibility.rst index 71b182f70..fcce6ef05 100644 --- a/docs/cloudformation_compatibility.rst +++ b/docs/cloudformation_compatibility.rst @@ -182,7 +182,7 @@ AWS::Serverless::Application ================================== ======================== ======================== Location None SAM expects exact values for the Location property Parameters All -NotificationArns All +NotificationARNs All Tags All TimeoutInMinutes All ================================== ======================== ======================== diff --git a/requirements/dev.txt b/requirements/dev.txt index 07d399e59..1fe5d9f99 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -11,6 +11,7 @@ py>=1.4.33 mock>=2.0.0 parameterized>=0.6.1 requests>=2.20.0 +cfn-lint>=0.18.1 # CLI requirements docopt>=0.6.2 diff --git a/samtranslator/model/cloudformation.py b/samtranslator/model/cloudformation.py index 5d2409c2f..c178681c6 100644 --- a/samtranslator/model/cloudformation.py +++ b/samtranslator/model/cloudformation.py @@ -9,7 +9,7 @@ class NestedStack(Resource): property_types = { 'TemplateURL': PropertyType(True, is_str()), 'Parameters': PropertyType(False, is_type(dict)), - 'NotificationArns': PropertyType(False, list_of(is_str())), + 'NotificationARNs': PropertyType(False, list_of(is_str())), 'Tags': PropertyType(False, list_of(is_type(dict))), 'TimeoutInMinutes': PropertyType(False, is_type(int)) } diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 3e6ae61c2..e20b45c8c 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -569,7 +569,7 @@ class SamApplication(SamResourceMacro): 'Location': PropertyType(True, one_of(is_str(), is_type(dict))), 'TemplateUrl': PropertyType(False, is_str()), 'Parameters': PropertyType(False, is_type(dict)), - 'NotificationArns': PropertyType(False, list_of(is_str())), + 'NotificationARNs': PropertyType(False, list_of(is_str())), 'Tags': PropertyType(False, is_type(dict)), 'TimeoutInMinutes': PropertyType(False, is_type(int)) } @@ -586,7 +586,7 @@ def _construct_nested_stack(self): nested_stack = NestedStack(self.logical_id, depends_on=self.depends_on, attributes=self.get_passthrough_resource_attributes()) nested_stack.Parameters = self.Parameters - nested_stack.NotificationArns = self.NotificationArns + nested_stack.NotificationARNs = self.NotificationARNs application_tags = self._get_application_tags() nested_stack.Tags = self._construct_tag_list(self.Tags, application_tags) nested_stack.TimeoutInMinutes = self.TimeoutInMinutes diff --git a/tests/translator/input/api_endpoint_configuration.yaml b/tests/translator/input/api_endpoint_configuration.yaml index 8855fbb35..899d2d692 100644 --- a/tests/translator/input/api_endpoint_configuration.yaml +++ b/tests/translator/input/api_endpoint_configuration.yaml @@ -1,4 +1,4 @@ -Properties: +Parameters: EndpointConfig: Type: String diff --git a/tests/translator/input/api_with_auth_all_minimum.yaml b/tests/translator/input/api_with_auth_all_minimum.yaml index 2c1d03ad4..75568f21d 100644 --- a/tests/translator/input/api_with_auth_all_minimum.yaml +++ b/tests/translator/input/api_with_auth_all_minimum.yaml @@ -32,6 +32,12 @@ Resources: Identity: Headers: - Authorization1 + MyAuthFn: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 MyFn: Type: AWS::Serverless::Function Properties: @@ -56,4 +62,17 @@ Resources: Properties: RestApiId: !Ref MyApiWithLambdaRequestAuth Method: get - Path: /lambda-request \ No newline at end of file + Path: /lambda-request + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/translator/input/api_with_auth_no_default.yaml b/tests/translator/input/api_with_auth_no_default.yaml index f3d3b81d8..5b033d79a 100644 --- a/tests/translator/input/api_with_auth_no_default.yaml +++ b/tests/translator/input/api_with_auth_no_default.yaml @@ -29,6 +29,12 @@ Resources: Identity: Headers: - Authorization1 + MyAuthFn: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 MyFn: Type: AWS::Serverless::Function Properties: @@ -53,4 +59,17 @@ Resources: Properties: RestApiId: !Ref MyApiWithLambdaRequestAuth Method: get - Path: /lambda-request \ No newline at end of file + Path: /lambda-request + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/translator/input/api_with_cors.yaml b/tests/translator/input/api_with_cors.yaml index d7e93d58a..6c6765dba 100644 --- a/tests/translator/input/api_with_cors.yaml +++ b/tests/translator/input/api_with_cors.yaml @@ -22,7 +22,18 @@ Resources: Properties: Path: /foo Method: any - + RestApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.handler + Runtime: nodejs8.10 + GetHtmlFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.handler + Runtime: nodejs8.10 ExplicitApi: Type: AWS::Serverless::Api Properties: diff --git a/tests/translator/input/api_with_cors_and_only_credentials_false.yaml b/tests/translator/input/api_with_cors_and_only_credentials_false.yaml index d04e949c3..37f9e772d 100644 --- a/tests/translator/input/api_with_cors_and_only_credentials_false.yaml +++ b/tests/translator/input/api_with_cors_and_only_credentials_false.yaml @@ -4,7 +4,12 @@ Globals: AllowCredentials: false Resources: - + ImplicitApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs8.10 ExplicitApi: Type: AWS::Serverless::Api Properties: diff --git a/tests/translator/input/api_with_cors_and_only_maxage.yaml b/tests/translator/input/api_with_cors_and_only_maxage.yaml index 0cf47de47..62ade857b 100644 --- a/tests/translator/input/api_with_cors_and_only_maxage.yaml +++ b/tests/translator/input/api_with_cors_and_only_maxage.yaml @@ -5,7 +5,12 @@ Globals: MaxAge: 600 Resources: - + ImplicitApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs8.10 ExplicitApi: Type: AWS::Serverless::Api Properties: diff --git a/tests/translator/input/api_with_resource_refs.yaml b/tests/translator/input/api_with_resource_refs.yaml index c294fe6cd..3381677ef 100644 --- a/tests/translator/input/api_with_resource_refs.yaml +++ b/tests/translator/input/api_with_resource_refs.yaml @@ -23,9 +23,12 @@ Resources: Method: GET Outputs: - ImplicitApiDeployment: !Ref ServerlessRestApi.Deployment - ImplicitApiStage: !Ref ServerlessRestApi.Stage - - ExplicitApiDeployment: !Ref MyApi.Deployment - ExplicitApiStage: !Ref MyApi.Stage + ImplicitApiDeployment: + Value: !Ref ServerlessRestApi.Deployment + ImplicitApiStage: + Value: !Ref ServerlessRestApi.Stage + ExplicitApiDeployment: + Value: !Ref MyApi.Deployment + ExplicitApiStage: + Value: !Ref MyApi.Stage diff --git a/tests/translator/input/basic_application.yaml b/tests/translator/input/basic_application.yaml index 6cef038fb..03e665a41 100644 --- a/tests/translator/input/basic_application.yaml +++ b/tests/translator/input/basic_application.yaml @@ -1,3 +1,8 @@ +Conditions: + TestCondition: + Fn::Equals: + - True + - False Resources: BasicApplication: Type: 'AWS::Serverless::Application' @@ -16,7 +21,7 @@ Resources: TagName: TagValue Parameters: IdentityNameParameter: IdentityName - NotificationArns: + NotificationARNs: - arn:aws:sns:us-east-1:123456789012:sns-arn TimeoutInMinutes: 15 @@ -29,7 +34,7 @@ Resources: ApplicationWithCondition: Type: 'AWS::Serverless::Application' - Condition: "this is a test" + Condition: TestCondition Properties: Location: ApplicationId: arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world diff --git a/tests/translator/input/basic_function.yaml b/tests/translator/input/basic_function.yaml index 974784764..ae6ba50b4 100644 --- a/tests/translator/input/basic_function.yaml +++ b/tests/translator/input/basic_function.yaml @@ -1,3 +1,10 @@ +Parameters: + SomeParameter: + Type: String + Default: param + SomeOtherParameter: + Type: String + Default: otherparam Resources: MinimalFunction: Type: 'AWS::Serverless::Function' @@ -28,7 +35,7 @@ Resources: CodeUri: Bucket: somebucket Key: somekey - Version: 1 + Version: "1" Handler: hello.handler Runtime: python2.7 @@ -47,7 +54,6 @@ Resources: SubnetIds: - subnet-9d4a7b6c - subnet-65ea5f08 - SubnetIdsUsingRef: - {Ref: SomeParameter} - {Ref: SomeOtherParameter} Role: arn:aws:iam::012345678901:role/lambda_basic_execution diff --git a/tests/translator/input/basic_function_with_tags.yaml b/tests/translator/input/basic_function_with_tags.yaml index 682af3f4d..aced4f2d3 100644 --- a/tests/translator/input/basic_function_with_tags.yaml +++ b/tests/translator/input/basic_function_with_tags.yaml @@ -24,5 +24,5 @@ Resources: TagKey2: "" TagKey3: Ref: TagValueParam - TagKey4: 123 + TagKey4: "123" diff --git a/tests/translator/input/basic_layer.yaml b/tests/translator/input/basic_layer.yaml index 39e0443ca..170af09b1 100644 --- a/tests/translator/input/basic_layer.yaml +++ b/tests/translator/input/basic_layer.yaml @@ -1,3 +1,9 @@ +Conditions: + TestCondition: + Fn::Equals: + - beta + - beta + Resources: MinimalLayer: Type: 'AWS::Serverless::LayerVersion' @@ -10,7 +16,7 @@ Resources: ContentUri: Bucket: somebucket Key: somekey - Version: 1 + Version: "v1" RetentionPolicy: Delete CompleteLayer: @@ -27,6 +33,6 @@ Resources: LayerWithCondition: Type: 'AWS::Serverless::LayerVersion' - Condition: "this is a test" + Condition: TestCondition Properties: ContentUri: s3://sam-demo-bucket/layer.zip diff --git a/tests/translator/input/depends_on.yaml b/tests/translator/input/depends_on.yaml index 909fcecce..7ea5e5aad 100644 --- a/tests/translator/input/depends_on.yaml +++ b/tests/translator/input/depends_on.yaml @@ -41,8 +41,8 @@ Resources: - { "AttributeName" : "id", "KeyType" : "HASH"} ProvisionedThroughput: - ReadCapacityUnits: "5" - WriteCapacityUnits: "5" + ReadCapacityUnits: 5 + WriteCapacityUnits: 5 StreamSpecification: StreamViewType: "NEW_IMAGE" diff --git a/tests/translator/input/explicit_api.yaml b/tests/translator/input/explicit_api.yaml index b3a70bbb6..0cef803f7 100644 --- a/tests/translator/input/explicit_api.yaml +++ b/tests/translator/input/explicit_api.yaml @@ -2,6 +2,9 @@ Parameters: MyStageName: Type: String Default: Production + something: + Type: String + Default: something Resources: GetHtmlFunction: diff --git a/tests/translator/input/function_managed_inline_policy.yaml b/tests/translator/input/function_managed_inline_policy.yaml index 6a42afe78..538d5f3c6 100644 --- a/tests/translator/input/function_managed_inline_policy.yaml +++ b/tests/translator/input/function_managed_inline_policy.yaml @@ -1,3 +1,7 @@ +Parameters: + SomeManagedPolicyArn: + Type: String + Default: arn:aws:iam::aws:policy/OtherPolicy Resources: Function: Type: 'AWS::Serverless::Function' @@ -19,4 +23,4 @@ Resources: # Intrinsic functions & custom policy ARNs must be supported - {"Ref": "SomeManagedPolicyArn"} - - arn:aws:1234:iam:policy/CustomerCreatedManagedPolicy + - arn:aws:iam::123456789012:policy/CustomerCreatedManagedPolicy diff --git a/tests/translator/input/function_with_alias_and_event_sources.yaml b/tests/translator/input/function_with_alias_and_event_sources.yaml index fd8112fa1..0d436671c 100644 --- a/tests/translator/input/function_with_alias_and_event_sources.yaml +++ b/tests/translator/input/function_with_alias_and_event_sources.yaml @@ -1,7 +1,10 @@ # Testing Alias Invoke with ALL event sources supported by Lambda # We are looking to check if the event sources and their associated Lambda::Permission resources are # connect to the Alias and *not* the function - +Parameters: + MyStageName: + Type: String + Default: beta Resources: MyAwesomeFunction: Type: 'AWS::Serverless::Function' @@ -96,4 +99,4 @@ Resources: Key: webpage_swagger.json Variables: LambdaFunction: - Fn::GetAtt: ["MyAwesomeFunction.Alias", "Arn"] + Ref: "MyAwesomeFunction" diff --git a/tests/translator/input/function_with_condition.yaml b/tests/translator/input/function_with_condition.yaml index ed32206bc..059ea737b 100644 --- a/tests/translator/input/function_with_condition.yaml +++ b/tests/translator/input/function_with_condition.yaml @@ -1,7 +1,12 @@ +Conditions: + TestCondition: + Fn::Equals: + - test + - test Resources: ConditionFunction: Type: 'AWS::Serverless::Function' - Condition: "this is a test" + Condition: "TestCondition" Properties: CodeUri: s3://sam-demo-bucket/hello.zip Handler: hello.handler diff --git a/tests/translator/input/function_with_deployment_and_custom_role.yaml b/tests/translator/input/function_with_deployment_and_custom_role.yaml index 787615ac8..448b0fdc0 100644 --- a/tests/translator/input/function_with_deployment_and_custom_role.yaml +++ b/tests/translator/input/function_with_deployment_and_custom_role.yaml @@ -19,7 +19,7 @@ Resources: CodeUri: s3://sam-demo-bucket/hello.zip Handler: hello.handler Runtime: python2.7 - Role: !Ref DeploymentRole + Role: !GetAtt DeploymentRole.Arn DeploymentRole: Type: AWS::IAM::Role diff --git a/tests/translator/input/function_with_layers.yaml b/tests/translator/input/function_with_layers.yaml index e9b0b9a4e..1e34324d0 100644 --- a/tests/translator/input/function_with_layers.yaml +++ b/tests/translator/input/function_with_layers.yaml @@ -24,8 +24,8 @@ Resources: Handler: hello.handler Runtime: python2.7 Layers: - - !Sub arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:CorpXLayer:1 - - Fn::Sub: arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:CorpYLayer:1 + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpXLayer:1 + - Fn::Sub: arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpYLayer:1 FunctionReferencesLayer: Type: 'AWS::Serverless::Function' diff --git a/tests/translator/input/function_with_many_layers.yaml b/tests/translator/input/function_with_many_layers.yaml index 0aff4d87a..78ba2bc4a 100644 --- a/tests/translator/input/function_with_many_layers.yaml +++ b/tests/translator/input/function_with_many_layers.yaml @@ -7,9 +7,9 @@ Resources: Runtime: python2.7 Layers: - arn:aws:lambda:us-east-1:123456789101:layer:z:1 - - !Sub arn:aws:lambda:${AWS:Region}:123456789101:layer:a:1 + - !Sub arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1 - arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1 - - !Sub arn:${AWS:Partition}:lambda:${AWS:Region}:123456789101:layer:c:1 + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1 - !Ref MyLayer MyLayer: diff --git a/tests/translator/input/function_with_resource_refs.yaml b/tests/translator/input/function_with_resource_refs.yaml index 1c3d15124..02732661c 100644 --- a/tests/translator/input/function_with_resource_refs.yaml +++ b/tests/translator/input/function_with_resource_refs.yaml @@ -27,19 +27,26 @@ Resources: Fn::GetAtt: ["MinimalFunction.Alias", "Name"] Outputs: - AliasArn: !Ref MinimalFunction.Alias + AliasArn: + Value: !Ref MinimalFunction.Alias - AliasName: !GetAtt MinimalFunction.Alias.Name + AliasName: + Value: !GetAtt MinimalFunction.Alias.Name # Alias doesn't exist for this function. This reference must not resolve - MustNotResolve: !GetAtt FunctionWithoutAlias.Alias.Name + MustNotResolve: + Value: !GetAtt FunctionWithoutAlias.Alias.Name AliasInSub: - Fn::Sub: ["Hello ${MinimalFunction.Alias} ${MinimalFunction.Alias.Name} ${SomeValue}", {"SomeValue": "World"}] + Value: + Fn::Sub: ["Hello ${MinimalFunction.Alias} ${MinimalFunction.Alias.Name} ${SomeValue}", {"SomeValue": "World"}] - VersionArn: !Ref MinimalFunction.Version + VersionArn: + Value: !Ref MinimalFunction.Version VersionNumber: - Fn::GetAtt: ["MinimalFunction.Version", "Version"] + Value: + Fn::GetAtt: ["MinimalFunction.Version", "Version"] UnResolvedVersion: - Ref: FunctionWithoutAlias.Version + Value: + Ref: FunctionWithoutAlias.Version diff --git a/tests/translator/input/globals_for_api.yaml b/tests/translator/input/globals_for_api.yaml index 22f43805a..5d3a95632 100644 --- a/tests/translator/input/globals_for_api.yaml +++ b/tests/translator/input/globals_for_api.yaml @@ -43,3 +43,16 @@ Resources: uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations responses: {} + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/translator/input/globals_for_function.yaml b/tests/translator/input/globals_for_function.yaml index 1490bf245..f3acd0e89 100644 --- a/tests/translator/input/globals_for_function.yaml +++ b/tests/translator/input/globals_for_function.yaml @@ -6,8 +6,10 @@ Globals: MemorySize: 1024 Timeout: 30 VpcConfig: - SecurityGroupIds: + SecurityGroupIds: - sg-edcd9784 + SubnetIds: + - sub-id-2 Environment: Variables: Var1: value1 @@ -18,7 +20,7 @@ Globals: AutoPublishAlias: live PermissionsBoundary: arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary Layers: - - !Sub arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer:1 + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1 ReservedConcurrentExecutions: 50 Resources: @@ -45,6 +47,6 @@ Resources: AutoPublishAlias: prod PermissionsBoundary: arn:aws:1234:iam:boundary/OverridePermissionsBoundary Layers: - - !Sub arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer2:2 + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2 ReservedConcurrentExecutions: 100 diff --git a/tests/translator/input/implicit_api_with_serverless_rest_api_resource.yaml b/tests/translator/input/implicit_api_with_serverless_rest_api_resource.yaml index ad7c015b9..be49ab464 100644 --- a/tests/translator/input/implicit_api_with_serverless_rest_api_resource.yaml +++ b/tests/translator/input/implicit_api_with_serverless_rest_api_resource.yaml @@ -42,4 +42,4 @@ Resources: Properties: CodeUri: s3://sam-demo-bucket/hello.zip Handler: hello.handler - Runtime: python2.7 + Runtime: python2.7 diff --git a/tests/translator/input/intrinsic_functions.yaml b/tests/translator/input/intrinsic_functions.yaml index 1f2d7db94..a17a2378c 100644 --- a/tests/translator/input/intrinsic_functions.yaml +++ b/tests/translator/input/intrinsic_functions.yaml @@ -13,6 +13,9 @@ Parameters: MyExplicitApiName: Type: String Default: SomeName + CodeKey: + Type: String + Default: "key" Conditions: TrueCondition: @@ -30,7 +33,7 @@ Resources: Bucket: Ref: CodeBucket Key: - "Fn::Sub": ["code.zip"] + "Fn::Sub": "code.zip.${CodeKey}" Version: "Fn::Join": ["", ["some", "version"]] @@ -114,8 +117,8 @@ Resources: - { "AttributeName" : "id", "KeyType" : "HASH"} ProvisionedThroughput: - ReadCapacityUnits: "5" - WriteCapacityUnits: "5" + ReadCapacityUnits: 5 + WriteCapacityUnits: 5 StreamSpecification: StreamViewType: "NEW_IMAGE" @@ -145,9 +148,26 @@ Resources: DeadLetterQueue: Type: SNS TargetArn: - Fn::GetAtt: - - SnsDlqQueue - - Arn + Ref: SnsDlqQueue SnsDlqQueue: Type: AWS::SNS::Topic + + MyNewRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: ['sts:AssumeRole'] + Effect: Allow + Principal: + Service: [lambda.amazonaws.com] + Version: '2012-10-17' + Policies: + - PolicyDocument: + Statement: + - Action: ['cloudwatch:*', 'logs:*'] + Effect: Allow + Resource: '*' + Version: '2012-10-17' + PolicyName: lambdaRole diff --git a/tests/translator/input/layers_all_properties.yaml b/tests/translator/input/layers_all_properties.yaml index a9cd53a73..03fef5dbc 100644 --- a/tests/translator/input/layers_all_properties.yaml +++ b/tests/translator/input/layers_all_properties.yaml @@ -30,8 +30,6 @@ Outputs: Value: !Ref MyLayer FunctionName: Value: !Ref MyFunction - LayerAtt: # For testing purposes only - Value: !GetAtt MyLayer.Arn FunctionAtt: Value: !GetAtt MyFunction.Arn LayerSub: diff --git a/tests/translator/input/no_implicit_api_with_serverless_rest_api_resource.yaml b/tests/translator/input/no_implicit_api_with_serverless_rest_api_resource.yaml index 6b0d74142..0998b13b3 100644 --- a/tests/translator/input/no_implicit_api_with_serverless_rest_api_resource.yaml +++ b/tests/translator/input/no_implicit_api_with_serverless_rest_api_resource.yaml @@ -58,3 +58,17 @@ Resources: Images: Type: AWS::S3::Bucket + + RestApiFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python3.6 + + GetHtmlFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python3.6 \ No newline at end of file diff --git a/tests/translator/input/s3_existing_other_notification_configuration.yaml b/tests/translator/input/s3_existing_other_notification_configuration.yaml index fa6315381..b181bb7a6 100644 --- a/tests/translator/input/s3_existing_other_notification_configuration.yaml +++ b/tests/translator/input/s3_existing_other_notification_configuration.yaml @@ -19,3 +19,4 @@ Resources: NotificationConfiguration: TopicConfigurations: - Topic: my-super-awesome-topic + Event: s3:ObjectRemoved:* diff --git a/tests/translator/input/s3_with_condition.yaml b/tests/translator/input/s3_with_condition.yaml index e0f4e7988..e83ec38f9 100644 --- a/tests/translator/input/s3_with_condition.yaml +++ b/tests/translator/input/s3_with_condition.yaml @@ -1,3 +1,8 @@ +Conditions: + MyCondition: + Fn::Equals: + - yes + - no Resources: ThumbnailFunction: Type: AWS::Serverless::Function diff --git a/tests/translator/input/simple_table_ref_parameter_intrinsic.yaml b/tests/translator/input/simple_table_ref_parameter_intrinsic.yaml index f76765d2e..55fcfdec8 100644 --- a/tests/translator/input/simple_table_ref_parameter_intrinsic.yaml +++ b/tests/translator/input/simple_table_ref_parameter_intrinsic.yaml @@ -1,3 +1,13 @@ +Parameters: + ReadCapacity: + Type: Number + Default: 15 + WriteCapacity: + Type: Number + Default: 15 + EnableSSE: + Type: String # Boolean parameter types not allowed + Default: True Resources: MinimalTableRefParamLongForm: Type: 'AWS::Serverless::SimpleTable' diff --git a/tests/translator/input/simple_table_with_extra_tags.yaml b/tests/translator/input/simple_table_with_extra_tags.yaml index 156d819bf..d8daa60c0 100644 --- a/tests/translator/input/simple_table_with_extra_tags.yaml +++ b/tests/translator/input/simple_table_with_extra_tags.yaml @@ -1,3 +1,8 @@ +Parameters: + TagValueParam: + Type: String + Default: value + Resources: MinimalTableWithTags: Type: 'AWS::Serverless::SimpleTable' @@ -7,4 +12,4 @@ Resources: TagKey2: "" TagKey3: Ref: TagValueParam - TagKey4: 123 + TagKey4: "123" diff --git a/tests/translator/input/simple_table_with_table_name.yaml b/tests/translator/input/simple_table_with_table_name.yaml index 33eb6fd3b..8055c0d70 100644 --- a/tests/translator/input/simple_table_with_table_name.yaml +++ b/tests/translator/input/simple_table_with_table_name.yaml @@ -1,3 +1,8 @@ +Parameters: + MySimpleTableParameter: + Type: String + Default: TableName + Resources: MinimalTableWithTableName: Type: 'AWS::Serverless::SimpleTable' diff --git a/tests/translator/output/api_endpoint_configuration.json b/tests/translator/output/api_endpoint_configuration.json index fbf42a6f2..76ab88247 100644 --- a/tests/translator/output/api_endpoint_configuration.json +++ b/tests/translator/output/api_endpoint_configuration.json @@ -1,5 +1,5 @@ { - "Properties": { + "Parameters": { "EndpointConfig": { "Type": "String" } @@ -8,11 +8,11 @@ "ImplicitApiFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", diff --git a/tests/translator/output/api_with_auth_all_minimum.json b/tests/translator/output/api_with_auth_all_minimum.json index b3c4c4fd9..c2ce66294 100644 --- a/tests/translator/output/api_with_auth_all_minimum.json +++ b/tests/translator/output/api_with_auth_all_minimum.json @@ -1,89 +1,105 @@ { "Resources": { - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__Stage__": "Prod", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/cognito": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [{ - "MyCognitoAuth": [] - }], + }, + "security": [ + { + "MyCognitoAuth": [] + } + ], "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "providerARNs": [{ - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - }], + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } } } } - }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeployment6e52add211" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + } + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } + } + }, + "MyFnLambdaRequestPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } @@ -91,55 +107,154 @@ ] } } - }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyApiWithCognitoAuthDeployment62312fa971": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "Description": "RestApi deployment id: 62312fa9711ad898b40e76b7a4ae1358305b0bcd", + "StageName": "Stage" + } + }, + "MyFnCognitoPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + } + } + ] + } + } + }, + "MyAuthFn": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyFnRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MyApiWithCognitoAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment6e52add211" - }, + "Ref": "MyApiWithCognitoAuthDeployment62312fa971" + }, "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" - }, + "Ref": "MyApiWithCognitoAuth" + }, "StageName": "Prod" } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnCognitoPermissionProd": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", { - "__Stage__": "Prod", + "__Stage__": "Prod", "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" + "Ref": "MyApiWithCognitoAuth" } } ] } } - }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } + } + }, + "MyFnLambdaTokenPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + { + "__Stage__": "Prod", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } @@ -147,20 +262,30 @@ ] } } - }, + }, + "MyApiWithLambdaRequestAuthDeployment6e52add211": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "Description": "RestApi deployment id: 6e52add211cda52ae10a7cc0e0afcf4afc682f9f", + "StageName": "Stage" + } + }, "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", { - "__Stage__": "Prod", + "__Stage__": "Prod", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } @@ -168,277 +293,232 @@ ] } } - }, + }, "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/lambda-token": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [{ - "MyLambdaTokenAuth": [] - }], + }, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "token", + "type": "token", "authorizerUri": { "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] } } ] } - }, + }, "x-amazon-apigateway-authtype": "custom" } } } } - }, - "MyApiWithCognitoAuthDeployment62312fa971": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 62312fa9711ad898b40e76b7a4ae1358305b0bcd", - "StageName": "Stage" - } - }, - "MyFnLambdaRequestPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaTokenPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { - "__Stage__": "*", + "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithLambdaTokenAuth" } } ] } } - }, - "MyFnLambdaTokenPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] + } + }, + "MyFn": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" ] - } + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] } - }, - "MyFnCognitoPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaTokenAuthDeployment445c6c96e7": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "Description": "RestApi deployment id: 445c6c96e7f43bd49f83bd67ae0d6813c517348f", + "StageName": "Stage" + } + }, + "MyAuthFnRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } ] } } - }, + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment445c6c96e7" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + } + }, "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/lambda-request": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [{ - "MyLambdaRequestAuth": [] - }], + }, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + "in": "header", + "type": "apiKey", + "name": "Unused", "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", + "type": "request", + "identitySource": "method.request.header.Authorization1", "authorizerUri": { "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] } } ] } - }, + }, "x-amazon-apigateway-authtype": "custom" } } } } - }, - "MyApiWithLambdaTokenAuthDeployment445c6c96e7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "Description": "RestApi deployment id: 445c6c96e7f43bd49f83bd67ae0d6813c517348f", - "StageName": "Stage" - } - }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment445c6c96e7" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "StageName": "Prod" - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } - }, - "MyApiWithLambdaRequestAuthDeployment6e52add211": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "Description": "RestApi deployment id: 6e52add211cda52ae10a7cc0e0afcf4afc682f9f", - "StageName": "Stage" - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment62312fa971" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs8.10", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } } } } \ No newline at end of file diff --git a/tests/translator/output/api_with_auth_no_default.json b/tests/translator/output/api_with_auth_no_default.json index 2a981e6ed..df04de541 100644 --- a/tests/translator/output/api_with_auth_no_default.json +++ b/tests/translator/output/api_with_auth_no_default.json @@ -1,127 +1,121 @@ { "Resources": { - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__Stage__": "Prod", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/cognito": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + }, "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "providerARNs": [{ - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - }], + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } } } } - }, - "MyApiWithCognitoAuthDeployment039b508d89": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeployment7d0d103fdf" + }, "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 039b508d8974255326ad180948c0f232635032d8", - "StageName": "Stage" + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" } - }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithLambdaTokenAuth" } } ] } } - }, - "MyApiWithLambdaRequestAuthDeployment7d0d103fdf": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyFnLambdaRequestPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "Description": "RestApi deployment id: 7d0d103fdf357021c9e3f88a03f27a766045308f", - "StageName": "Stage" + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaTokenPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { - "__Stage__": "Prod", + "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } @@ -129,103 +123,133 @@ ] } } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnCognitoPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", { - "__Stage__": "Prod", + "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithCognitoAuth" } } ] } } - }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + }, + "MyAuthFn": { + "Type": "AWS::Lambda::Function", "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/lambda-token": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {} + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyFnRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" + ] + } + } + }, + "MyApiWithCognitoAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeployment039b508d89" + }, + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + } + }, + "MyFnCognitoPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + } } - } + ] } } - }, - "MyApiWithLambdaTokenAuthDeployment50695ee60b": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyApiWithCognitoAuthDeployment039b508d89": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "Description": "RestApi deployment id: 50695ee60b97eeade77bcc6137fa5dabc526938d", + "Ref": "MyApiWithCognitoAuth" + }, + "Description": "RestApi deployment id: 039b508d8974255326ad180948c0f232635032d8", "StageName": "Stage" } - }, - "MyFnLambdaRequestPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "MyFn" - }, + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } @@ -233,32 +257,30 @@ ] } } - }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyApiWithLambdaRequestAuthDeployment7d0d103fdf": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment7d0d103fdf" - }, "RestApiId": { "Ref": "MyApiWithLambdaRequestAuth" - }, - "StageName": "Prod" + }, + "Description": "RestApi deployment id: 7d0d103fdf357021c9e3f88a03f27a766045308f", + "StageName": "Stage" } - }, - "MyFnLambdaTokenPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaTokenPermissionProd": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { - "__Stage__": "*", + "__Stage__": "Prod", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } @@ -266,170 +288,222 @@ ] } } - }, - "MyFnCognitoPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaRequestPermissionProd": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", { - "__Stage__": "*", + "__Stage__": "Prod", "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" + "Ref": "MyApiWithLambdaRequestAuth" } } ] } } - }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + }, + "MyApiWithLambdaTokenAuth": { + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { - "/lambda-request": { + "/lambda-token": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + }, "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + "MyLambdaTokenAuth": { + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", + "type": "token", "authorizerUri": { "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] } } ] } - }, + }, "x-amazon-apigateway-authtype": "custom" } } } } - }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaTokenAuthDeployment50695ee60b": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "Description": "RestApi deployment id: 50695ee60b97eeade77bcc6137fa5dabc526938d", + "StageName": "Stage" + } + }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", + "Properties": { + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] + } + }, + "MyFn": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { "Fn::GetAtt": [ - "MyAuthFn", + "MyFnRole", "Arn" ] - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyAuthFnRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } ] } } - }, + }, "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithLambdaTokenAuthDeployment50695ee60b" - }, + }, "RestApiId": { "Ref": "MyApiWithLambdaTokenAuth" - }, + }, "StageName": "Prod" } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", + }, + "MyApiWithLambdaRequestAuth": { + "Type": "AWS::ApiGateway::RestApi", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/lambda-request": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + }, + "responses": {} + } } - }] + }, + "swagger": "2.0", + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "type": "apiKey", + "name": "Unused", + "x-amazon-apigateway-authorizer": { + "type": "request", + "identitySource": "method.request.header.Authorization1", + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + } + }, + "x-amazon-apigateway-authtype": "custom" + } + } } } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment039b508d89" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs8.10", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } } } } \ No newline at end of file diff --git a/tests/translator/output/api_with_cors.json b/tests/translator/output/api_with_cors.json index 65525b4ca..fc0f7df4f 100644 --- a/tests/translator/output/api_with_cors.json +++ b/tests/translator/output/api_with_cors.json @@ -3,11 +3,11 @@ "ImplicitApiFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -89,40 +89,6 @@ } } }, - "ServerlessRestApiDeploymente13d39e2d1": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: e13d39e2d16b8aad18f87490157d347817fa3071", - "StageName": "Stage" - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment3a5a78688c" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymente13d39e2d1" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, "ExplicitApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { @@ -158,9 +124,9 @@ "application/json": "{}\n" }, "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Origin": "origins", "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Credentials": "'true'" } } @@ -181,7 +147,7 @@ }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, "Access-Control-Allow-Credentials": { "type": "string" } @@ -208,9 +174,9 @@ "application/json": "{}\n" }, "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Origin": "origins", "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Credentials": "'true'" } } @@ -231,7 +197,7 @@ }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, "Access-Control-Allow-Credentials": { "type": "string" } @@ -259,6 +225,76 @@ } } }, + "GetHtmlFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "ServerlessRestApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymente13d39e2d1" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + } + }, + "ServerlessRestApiDeploymente13d39e2d1": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Description": "RestApi deployment id: e13d39e2d16b8aad18f87490157d347817fa3071", + "StageName": "Stage" + } + }, + "RestApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "ImplicitApiFunctionGetHtmlPermissionProd": { "Type": "AWS::Lambda::Permission", "Properties": { @@ -286,10 +322,45 @@ "RestApiId": { "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", + "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", "StageName": "Stage" } }, + "RestApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ExplicitApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment3a5a78688c" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + } + }, "ServerlessRestApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { @@ -426,6 +497,29 @@ } } }, + "GetHtmlFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, "ImplicitApiFunctionAnyApiPermissionTest": { "Type": "AWS::Lambda::Permission", "Properties": { diff --git a/tests/translator/output/api_with_cors_and_only_credentials_false.json b/tests/translator/output/api_with_cors_and_only_credentials_false.json index 4e1658dba..fe7a5f402 100644 --- a/tests/translator/output/api_with_cors_and_only_credentials_false.json +++ b/tests/translator/output/api_with_cors_and_only_credentials_false.json @@ -1,13 +1,50 @@ { "Resources": { - "ExplicitApiDeployment398246867a": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunction": { + "Type": "AWS::Lambda::Function", "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" }, - "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", - "StageName": "Stage" + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ImplicitApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } } }, "ExplicitApiProdStage": { @@ -22,6 +59,16 @@ "StageName": "Prod" } }, + "ExplicitApiDeployment398246867a": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", + "StageName": "Stage" + } + }, "ExplicitApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { diff --git a/tests/translator/output/api_with_cors_and_only_maxage.json b/tests/translator/output/api_with_cors_and_only_maxage.json index 65a15ae90..a19fcdfdb 100644 --- a/tests/translator/output/api_with_cors_and_only_maxage.json +++ b/tests/translator/output/api_with_cors_and_only_maxage.json @@ -1,5 +1,52 @@ { "Resources": { + "ImplicitApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ImplicitApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "ExplicitApiDeploymentb61cfb7d60": { "Type": "AWS::ApiGateway::Deployment", "Properties": { diff --git a/tests/translator/output/api_with_resource_refs.json b/tests/translator/output/api_with_resource_refs.json index 4f1b9f72f..e30d09c62 100644 --- a/tests/translator/output/api_with_resource_refs.json +++ b/tests/translator/output/api_with_resource_refs.json @@ -1,27 +1,35 @@ { "Outputs": { "ImplicitApiDeployment": { - "Ref": "ServerlessRestApiDeploymente468b80e17" + "Value": { + "Ref": "ServerlessRestApiDeploymente468b80e17" + } }, "ExplicitApiDeployment": { - "Ref": "MyApiDeployment359f256a3b" + "Value": { + "Ref": "MyApiDeployment359f256a3b" + } }, "ExplicitApiStage": { - "Ref": "MyApifooStage" + "Value": { + "Ref": "MyApifooStage" + } }, "ImplicitApiStage": { - "Ref": "ServerlessRestApiProdStage" + "Value": { + "Ref": "ServerlessRestApiProdStage" + } } }, "Resources": { "MyFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyFunctionRole", diff --git a/tests/translator/output/aws-cn/api_endpoint_configuration.json b/tests/translator/output/aws-cn/api_endpoint_configuration.json index 7b91d7825..d7d46ce5a 100644 --- a/tests/translator/output/aws-cn/api_endpoint_configuration.json +++ b/tests/translator/output/aws-cn/api_endpoint_configuration.json @@ -1,5 +1,5 @@ { - "Properties": { + "Parameters": { "EndpointConfig": { "Type": "String" } @@ -8,11 +8,11 @@ "ImplicitApiFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", diff --git a/tests/translator/output/aws-cn/api_with_auth_all_minimum.json b/tests/translator/output/aws-cn/api_with_auth_all_minimum.json index 4ee847bdb..0e0c8284e 100644 --- a/tests/translator/output/aws-cn/api_with_auth_all_minimum.json +++ b/tests/translator/output/aws-cn/api_with_auth_all_minimum.json @@ -1,97 +1,113 @@ { "Resources": { - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__Stage__": "Prod", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/cognito": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [{ - "MyCognitoAuth": [] - }], + }, + "security": [ + { + "MyCognitoAuth": [] + } + ], "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "providerARNs": [{ - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - }], + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } } - }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeploymentd3ee2721bc" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + } + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] - }, + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } + } + }, + "MyFnLambdaRequestPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", { + "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } @@ -99,42 +115,175 @@ ] } } - }, - "MyApiWithLambdaTokenAuthDeploymenta48b731095": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyFnLambdaTokenPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "Description": "RestApi deployment id: a48b7310952ed029bd212c380e89a1bd39c74eae", - "StageName": "Stage" + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } } - }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyFnCognitoPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + } + } + ] + } + } + }, + "MyAuthFn": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyFnRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MyApiWithCognitoAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeploymentd3ee2721bc" - }, + "Ref": "MyApiWithCognitoAuthDeploymenta9cf768eaa" + }, "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" - }, + "Ref": "MyApiWithCognitoAuth" + }, "StageName": "Prod" } - }, + }, + "MyFnCognitoPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + } + } + ] + } + } + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } + } + }, + "MyApiWithLambdaTokenAuthDeploymenta48b731095": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "Description": "RestApi deployment id: a48b7310952ed029bd212c380e89a1bd39c74eae", + "StageName": "Stage" + } + }, "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { - "__Stage__": "Prod", + "__Stage__": "Prod", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } @@ -142,20 +291,20 @@ ] } } - }, + }, "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", { - "__Stage__": "Prod", + "__Stage__": "Prod", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } @@ -163,306 +312,237 @@ ] } } - }, + }, "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/lambda-token": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [{ - "MyLambdaTokenAuth": [] - }], + }, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "token", + "type": "token", "authorizerUri": { "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] } } ] } - }, + }, "x-amazon-apigateway-authtype": "custom" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } } - }, + }, "MyApiWithCognitoAuthDeploymenta9cf768eaa": { - "Type": "AWS::ApiGateway::Deployment", + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: a9cf768eaa1ac6804c7a7b05b79d7ee79d369fcf", + }, + "Description": "RestApi deployment id: a9cf768eaa1ac6804c7a7b05b79d7ee79d369fcf", "StageName": "Stage" } - }, - "MyFnLambdaRequestPermissionTest": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } - } - ] - } - } - }, + }, "MyApiWithLambdaRequestAuthDeploymentd3ee2721bc": { - "Type": "AWS::ApiGateway::Deployment", + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyApiWithLambdaRequestAuth" - }, - "Description": "RestApi deployment id: d3ee2721bcff60c4d00d26138ccf8007434bb862", + }, + "Description": "RestApi deployment id: d3ee2721bcff60c4d00d26138ccf8007434bb862", "StageName": "Stage" } - }, - "MyFnLambdaTokenPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] + } + }, + "MyFn": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" ] - } + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] } - }, - "MyFnCognitoPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyAuthFnRole": { + "Type": "AWS::IAM::Role", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } ] } } - }, + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeploymenta48b731095" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + } + }, "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/lambda-request": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [{ - "MyLambdaRequestAuth": [] - }], + }, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + "in": "header", + "type": "apiKey", + "name": "Unused", "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", + "type": "request", + "identitySource": "method.request.header.Authorization1", "authorizerUri": { "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] } } ] } - }, + }, "x-amazon-apigateway-authtype": "custom" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } } - }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } - ] - } - } - }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeploymenta48b731095" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "StageName": "Prod" - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeploymenta9cf768eaa" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs8.10", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } } } } \ No newline at end of file diff --git a/tests/translator/output/aws-cn/api_with_auth_no_default.json b/tests/translator/output/aws-cn/api_with_auth_no_default.json index b8df0978d..13038031d 100644 --- a/tests/translator/output/aws-cn/api_with_auth_no_default.json +++ b/tests/translator/output/aws-cn/api_with_auth_no_default.json @@ -1,124 +1,118 @@ { "Resources": { - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__Stage__": "Prod", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/cognito": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + }, "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "providerARNs": [{ - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - }], + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } } - }, - "MyApiWithLambdaRequestAuthDeployment93e0147508": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyFnLambdaRequestPermissionProd": { + "Type": "AWS::Lambda::Permission", "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "Description": "RestApi deployment id: 93e01475088ff4675852021a99279d60fc93cd6a", - "StageName": "Stage" + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } } - }, + }, "MyApiWithCognitoAuthDeployment6a169547ee": { - "Type": "AWS::ApiGateway::Deployment", + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 6a169547eef02f4a0cd9fdc97aca9d1e8a106b11", + }, + "Description": "RestApi deployment id: 6a169547eef02f4a0cd9fdc97aca9d1e8a106b11", "StageName": "Stage" } - }, + }, "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithLambdaRequestAuthDeployment93e0147508" - }, + }, "RestApiId": { "Ref": "MyApiWithLambdaRequestAuth" - }, + }, "StageName": "Prod" } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "MyFn" - }, + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "Prod", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } @@ -126,20 +120,20 @@ ] } } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaRequestPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", { - "__Stage__": "Prod", + "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } @@ -147,312 +141,392 @@ ] } } - }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + }, + "MyFnLambdaTokenPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/lambda-token": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {} + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" } } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" + ] + } + } + }, + "MyFnCognitoPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + } } + ] + } + } + }, + "MyAuthFn": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + ] + } + }, + "MyFnRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" } } - }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyApiWithCognitoAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeploymente838608f2f" - }, + "Ref": "MyApiWithCognitoAuthDeployment6a169547ee" + }, "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, + "Ref": "MyApiWithCognitoAuth" + }, "StageName": "Prod" } - }, - "MyFnLambdaRequestPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaTokenAuthDeploymente838608f2f": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "Description": "RestApi deployment id: e838608f2f6897932f7883ba5afaa855145e38f5", + "StageName": "Stage" + } + }, + "MyFnCognitoPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", { - "__Stage__": "*", + "__Stage__": "Prod", "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithCognitoAuth" } } ] } } - }, - "MyFnLambdaTokenPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "MyFn" - }, + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" + "Ref": "MyApiWithLambdaRequestAuth" } } ] } } - }, - "MyFnCognitoPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaTokenPermissionProd": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { - "__Stage__": "*", + "__Stage__": "Prod", "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" + "Ref": "MyApiWithLambdaTokenAuth" } } ] } } - }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + }, + "MyApiWithLambdaRequestAuthDeployment93e0147508": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "Description": "RestApi deployment id: 93e01475088ff4675852021a99279d60fc93cd6a", + "StageName": "Stage" + } + }, + "MyApiWithLambdaTokenAuth": { + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { - "/lambda-request": { + "/lambda-token": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + }, "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + "MyLambdaTokenAuth": { + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", + "type": "token", "authorizerUri": { "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] } } ] } - }, + }, "x-amazon-apigateway-authtype": "custom" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } } - }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } - ] - } + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] } - }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyFn": { + "Type": "AWS::Lambda::Function", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { "Fn::GetAtt": [ - "MyAuthFn", + "MyFnRole", "Arn" ] - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } - } - ] - } + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", + }, + "MyAuthFnRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - }] + ] } } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment6a169547ee" - }, + "Ref": "MyApiWithLambdaTokenAuthDeploymente838608f2f" + }, "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, + "Ref": "MyApiWithLambdaTokenAuth" + }, "StageName": "Prod" } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", + }, + "MyApiWithLambdaRequestAuth": { + "Type": "AWS::ApiGateway::RestApi", "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/lambda-request": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + }, + "responses": {} + } + } + }, + "swagger": "2.0", + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "type": "apiKey", + "name": "Unused", + "x-amazon-apigateway-authorizer": { + "type": "request", + "identitySource": "method.request.header.Authorization1", + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + } + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] - }, - "Runtime": "nodejs8.10", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } - }, - "MyApiWithLambdaTokenAuthDeploymente838608f2f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "Description": "RestApi deployment id: e838608f2f6897932f7883ba5afaa855145e38f5", - "StageName": "Stage" + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } } } } diff --git a/tests/translator/output/aws-cn/api_with_cors.json b/tests/translator/output/aws-cn/api_with_cors.json index 9bdba9200..1f1da1105 100644 --- a/tests/translator/output/aws-cn/api_with_cors.json +++ b/tests/translator/output/aws-cn/api_with_cors.json @@ -3,11 +3,11 @@ "ImplicitApiFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -124,9 +124,9 @@ "application/json": "{}\n" }, "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Origin": "origins", "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Credentials": "'true'" } } @@ -147,7 +147,7 @@ }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, "Access-Control-Allow-Credentials": { "type": "string" } @@ -174,9 +174,9 @@ "application/json": "{}\n" }, "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Origin": "origins", "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Credentials": "'true'" } } @@ -197,7 +197,7 @@ }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, "Access-Control-Allow-Credentials": { "type": "string" } @@ -233,6 +233,30 @@ } } }, + "GetHtmlFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "ServerlessRestApiProdStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { @@ -257,6 +281,30 @@ "StageName": "Prod" } }, + "RestApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "ImplicitApiFunctionGetHtmlPermissionProd": { "Type": "AWS::Lambda::Permission", "Properties": { @@ -284,10 +332,33 @@ "RestApiId": { "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", + "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", "StageName": "Stage" } }, + "RestApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, "ServerlessRestApiDeploymentdb43b8746d": { "Type": "AWS::ApiGateway::Deployment", "Properties": { @@ -442,6 +513,29 @@ } } }, + "GetHtmlFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, "ImplicitApiFunctionAnyApiPermissionTest": { "Type": "AWS::Lambda::Permission", "Properties": { diff --git a/tests/translator/output/aws-cn/api_with_cors_and_only_credentials_false.json b/tests/translator/output/aws-cn/api_with_cors_and_only_credentials_false.json index 06e79c17a..f486d5215 100644 --- a/tests/translator/output/aws-cn/api_with_cors_and_only_credentials_false.json +++ b/tests/translator/output/aws-cn/api_with_cors_and_only_credentials_false.json @@ -1,13 +1,50 @@ { "Resources": { - "ExplicitApiDeployment398246867a": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunction": { + "Type": "AWS::Lambda::Function", "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" }, - "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", - "StageName": "Stage" + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ImplicitApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } } }, "ExplicitApiProdStage": { @@ -22,6 +59,16 @@ "StageName": "Prod" } }, + "ExplicitApiDeployment398246867a": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", + "StageName": "Stage" + } + }, "ExplicitApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { diff --git a/tests/translator/output/aws-cn/api_with_cors_and_only_maxage.json b/tests/translator/output/aws-cn/api_with_cors_and_only_maxage.json index 6b05e51fb..5a033f269 100644 --- a/tests/translator/output/aws-cn/api_with_cors_and_only_maxage.json +++ b/tests/translator/output/aws-cn/api_with_cors_and_only_maxage.json @@ -1,5 +1,52 @@ { "Resources": { + "ImplicitApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ImplicitApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "ExplicitApiDeploymentb61cfb7d60": { "Type": "AWS::ApiGateway::Deployment", "Properties": { diff --git a/tests/translator/output/aws-cn/api_with_resource_refs.json b/tests/translator/output/aws-cn/api_with_resource_refs.json index 4bc36f94f..74efe89c9 100644 --- a/tests/translator/output/aws-cn/api_with_resource_refs.json +++ b/tests/translator/output/aws-cn/api_with_resource_refs.json @@ -1,27 +1,35 @@ { "Outputs": { "ImplicitApiDeployment": { - "Ref": "ServerlessRestApiDeployment8b5ecabf9b" + "Value": { + "Ref": "ServerlessRestApiDeployment8b5ecabf9b" + } }, "ExplicitApiDeployment": { - "Ref": "MyApiDeployment359f256a3b" + "Value": { + "Ref": "MyApiDeployment359f256a3b" + } }, "ExplicitApiStage": { - "Ref": "MyApifooStage" + "Value": { + "Ref": "MyApifooStage" + } }, "ImplicitApiStage": { - "Ref": "ServerlessRestApiProdStage" + "Value": { + "Ref": "ServerlessRestApiProdStage" + } } }, "Resources": { "MyFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyFunctionRole", diff --git a/tests/translator/output/aws-cn/basic_application.json b/tests/translator/output/aws-cn/basic_application.json index e2056aaca..058e8037e 100644 --- a/tests/translator/output/aws-cn/basic_application.json +++ b/tests/translator/output/aws-cn/basic_application.json @@ -1,94 +1,100 @@ { + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, "Resources": { - "BasicApplication": { - "Type": "AWS::CloudFormation::Stack", + "NormalApplication": { + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "NotificationARNs": [ + "arn:aws:sns:us-east-1:123456789012:sns-arn" + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TimeoutInMinutes": 15, + "Parameters": { + "IdentityNameParameter": "IdentityName" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", "Key": "serverlessrepo:applicationId" - }, + }, { - "Value": "1.0.2", + "Value": "1.0.2", "Key": "serverlessrepo:semanticVersion" + }, + { + "Value": "TagValue", + "Key": "TagName" } ] } - }, - "NormalApplication": { - "Type": "AWS::CloudFormation::Stack", + }, + "BasicApplication": { + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", "Key": "serverlessrepo:applicationId" - }, + }, { - "Value": "1.0.2", + "Value": "1.0.2", "Key": "serverlessrepo:semanticVersion" - }, - { - "Value": "TagValue", - "Key": "TagName" } - ], - "Parameters": - { - "IdentityNameParameter": "IdentityName" - }, - "NotificationArns": - [ - "arn:aws:sns:us-east-1:123456789012:sns-arn" - ], - "TimeoutInMinutes": 15 + ] } - }, + }, "ApplicationWithLocationUrl": { - "Type": "AWS::CloudFormation::Stack", + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml", + "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "TagValue2", + "Value": "TagValue2", "Key": "TagName2" } ] } - }, + }, "ApplicationWithCondition": { - "Type": "AWS::CloudFormation::Stack", + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", "Key": "serverlessrepo:applicationId" - }, + }, { - "Value": "1.0.2", + "Value": "1.0.2", "Key": "serverlessrepo:semanticVersion" } ] - }, - "Condition": "this is a test" + }, + "Condition": "TestCondition" } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/basic_function.json b/tests/translator/output/aws-cn/basic_function.json index 4bae8d576..d96a640f0 100644 --- a/tests/translator/output/aws-cn/basic_function.json +++ b/tests/translator/output/aws-cn/basic_function.json @@ -1,56 +1,40 @@ { + "Parameters": { + "SomeParameter": { + "Default": "param", + "Type": "String" + }, + "SomeOtherParameter": { + "Default": "otherparam", + "Type": "String" + } + }, "Resources": { - "FunctionWithTracingRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "FunctionWithTracing": { - "Type": "AWS::Lambda::Function", + "FunctionWithInlineCode": { + "Type": "AWS::Lambda::Function", "Properties": { + "TracingConfig": { + "Mode": "Active" + }, "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithTracingRole", - "Arn" - ] - }, - "Runtime": "python2.7", + "ZipFile": "hello world" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "TracingConfig": { - "Mode": "Active" - } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithInlineCodeRole", + "Arn" + ] + }, + "Runtime": "python2.7" } - }, + }, "MinimalFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { @@ -78,11 +62,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", @@ -101,11 +85,11 @@ "FunctionWithPolicyDocument": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionWithPolicyDocumentRole", @@ -124,11 +108,11 @@ "FunctionWithPolicies": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionWithPoliciesRole", @@ -209,16 +193,14 @@ "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "FunctionName": "MyAwesomeFunction", + "Description": "Starter Lambda Function", "VpcConfig": { "SubnetIds": [ "subnet-9d4a7b6c", - "subnet-65ea5f08" - ], - "SubnetIdsUsingRef": [ + "subnet-65ea5f08", { "Ref": "SomeParameter" }, @@ -243,21 +225,21 @@ } }, "Handler": "hello.handler", - "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", + "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", "Timeout": 60, "Runtime": "python2.7", - "Description": "Starter Lambda Function" + "FunctionName": "MyAwesomeFunction" } }, "FunctionWithCodeUriObject": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "somebucket", "S3Key": "somekey", - "S3ObjectVersion": 1 + "S3ObjectVersion": "1" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionWithCodeUriObjectRole", @@ -277,8 +259,58 @@ "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "FunctionWithInlineCodeRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "FunctionWithTracingRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess" ], "AssumeRolePolicyDocument": { "Version": "2012-10-17", @@ -301,11 +333,11 @@ "FunctionWithRoleRef": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyFunctionRole", @@ -321,6 +353,32 @@ ] } }, + "FunctionWithTracing": { + "Type": "AWS::Lambda::Function", + "Properties": { + "TracingConfig": { + "Mode": "Active" + }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithTracingRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, "FunctionWithPolicyDocumentRole": { "Type": "AWS::IAM::Role", "Properties": { @@ -360,56 +418,6 @@ ] } } - }, - "FunctionWithInlineCodeRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "FunctionWithInlineCode": { - "Type": "AWS::Lambda::Function", - "Properties": { - "TracingConfig": { - "Mode": "Active" - }, - "Code": { - "ZipFile": "hello world" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithInlineCodeRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/basic_function_with_tags.json b/tests/translator/output/aws-cn/basic_function_with_tags.json index e145de80d..c3bd6c0ea 100644 --- a/tests/translator/output/aws-cn/basic_function_with_tags.json +++ b/tests/translator/output/aws-cn/basic_function_with_tags.json @@ -69,7 +69,7 @@ "Key": "TagKey3" }, { - "Value": 123, + "Value": "123", "Key": "TagKey4" } ], diff --git a/tests/translator/output/aws-cn/basic_layer.json b/tests/translator/output/aws-cn/basic_layer.json index 0b0a67400..d373bd19c 100644 --- a/tests/translator/output/aws-cn/basic_layer.json +++ b/tests/translator/output/aws-cn/basic_layer.json @@ -1,56 +1,64 @@ { + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + "beta", + "beta" + ] + } + }, "Resources": { + "LayerWithCondition7c655e10ea": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "LayerWithCondition" + }, + "Condition": "TestCondition" + }, "MinimalLayer0c7f96cce7": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { - "LayerName": "MinimalLayer", "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - } + }, + "LayerName": "MinimalLayer" } - }, + }, "CompleteLayer5d71a60e81": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "MyAwesomeLayer", - "Description": "Starter Lambda Layer", + }, + "LayerName": "MyAwesomeLayer", + "Description": "Starter Lambda Layer", + "LicenseInfo": "License information", "CompatibleRuntimes": [ - "python3.6", + "python3.6", "python2.7" - ], - "LicenseInfo": "License information" + ] } - }, - "LayerWithContentUriObjectac002ba767": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Delete", + }, + "LayerWithContentUriObjectbdbf1b82ac": { + "DeletionPolicy": "Delete", + "Type": "AWS::Lambda::LayerVersion", "Properties": { - "LayerName": "LayerWithContentUriObject", "Content": { - "S3Bucket": "somebucket", - "S3Key": "somekey", - "S3ObjectVersion": 1 - } + "S3Bucket": "somebucket", + "S3Key": "somekey", + "S3ObjectVersion": "v1" + }, + "LayerName": "LayerWithContentUriObject" } - }, - "LayerWithCondition93cfa80b64": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "LayerWithCondition" - }, - "Condition": "this is a test" } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/depends_on.json b/tests/translator/output/aws-cn/depends_on.json index a5c0a9840..70f9e6abf 100644 --- a/tests/translator/output/aws-cn/depends_on.json +++ b/tests/translator/output/aws-cn/depends_on.json @@ -74,8 +74,8 @@ } ], "ProvisionedThroughput": { - "WriteCapacityUnits": "5", - "ReadCapacityUnits": "5" + "WriteCapacityUnits": 5, + "ReadCapacityUnits": 5 } }, "DependsOn": "MySamTable" diff --git a/tests/translator/output/aws-cn/error_missing_queue.json b/tests/translator/output/aws-cn/error_missing_queue.json deleted file mode 100644 index f92bbf80e..000000000 --- a/tests/translator/output/aws-cn/error_missing_queue.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "errors": [{ - "errorMessage": "Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided." -} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/error_missing_stream.json b/tests/translator/output/aws-cn/error_missing_stream.json deleted file mode 100644 index d8925a773..000000000 --- a/tests/translator/output/aws-cn/error_missing_stream.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "errors": [{ - "errorMessage": "Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided." -} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/existing_event_logical_id.json b/tests/translator/output/aws-cn/existing_event_logical_id.json deleted file mode 100644 index ca678a896..000000000 --- a/tests/translator/output/aws-cn/existing_event_logical_id.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "errors": [ - { - "errorMessage": "Transforming resource with id [IoTRuleFunc] attempts to create a new resource with id [IoTRuleFuncMyIoTRule] and type \"AWS::IoT::TopicRule\". A resource with that id already exists within this template. Please use a different id for that resource." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [IoTRuleFunc] attempts to create a new resource with id [IoTRuleFuncMyIoTRule] and type \"AWS::IoT::TopicRule\". A resource with that id already exists within this template. Please use a different id for that resource." -} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/existing_permission_logical_id.json b/tests/translator/output/aws-cn/existing_permission_logical_id.json deleted file mode 100644 index c41d0abd0..000000000 --- a/tests/translator/output/aws-cn/existing_permission_logical_id.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "errors": [ - { - "errorMessage": "Transforming resource with id [AlexaSkillFunc] attempts to create a new resource with id [AlexaSkillFuncAlexaSkillEventPermission] and type \"AWS::Lambda::Permission\". A resource with that id already exists within this template. Please use a different id for that resource." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [AlexaSkillFunc] attempts to create a new resource with id [AlexaSkillFuncAlexaSkillEventPermission] and type \"AWS::Lambda::Permission\". A resource with that id already exists within this template. Please use a different id for that resource." -} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/existing_role_logical_id.json b/tests/translator/output/aws-cn/existing_role_logical_id.json deleted file mode 100644 index b01da1048..000000000 --- a/tests/translator/output/aws-cn/existing_role_logical_id.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "errors": [ - { - "errorMessage": "Transforming resource with id [RestApiFunction] attempts to create a new resource with id [RestApiFunctionRole] and type \"AWS::IAM::Role\". A resource with that id already exists within this template. Please use a different id for that resource." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [RestApiFunction] attempts to create a new resource with id [RestApiFunctionRole] and type \"AWS::IAM::Role\". A resource with that id already exists within this template. Please use a different id for that resource." -} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/explicit_api.json b/tests/translator/output/aws-cn/explicit_api.json index 351787e67..a593b9f32 100644 --- a/tests/translator/output/aws-cn/explicit_api.json +++ b/tests/translator/output/aws-cn/explicit_api.json @@ -1,5 +1,9 @@ { "Parameters": { + "something": { + "Default": "something", + "Type": "String" + }, "MyStageName": { "Default": "Production", "Type": "String" @@ -9,11 +13,11 @@ "GetHtmlFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "webpage.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "GetHtmlFunctionRole", @@ -160,18 +164,18 @@ "GetHtmlApiStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "GetHtmlApi" + }, "Variables": { "EndpointUri": { "Ref": "something" }, "EndpointUri2": "http://example.com" }, - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, "StageName": { "Ref": "MyStageName" } diff --git a/tests/translator/output/aws-cn/function_managed_inline_policy.json b/tests/translator/output/aws-cn/function_managed_inline_policy.json index d80ec2efc..3e7979c7d 100644 --- a/tests/translator/output/aws-cn/function_managed_inline_policy.json +++ b/tests/translator/output/aws-cn/function_managed_inline_policy.json @@ -1,13 +1,19 @@ { + "Parameters": { + "SomeManagedPolicyArn": { + "Default": "arn:aws:iam::aws:policy/OtherPolicy", + "Type": "String" + } + }, "Resources": { "Function": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionRole", @@ -27,11 +33,13 @@ "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - {"Ref": "SomeManagedPolicyArn"}, - "arn:aws:1234:iam:policy/CustomerCreatedManagedPolicy" + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaRole", + { + "Ref": "SomeManagedPolicyArn" + }, + "arn:aws:iam::123456789012:policy/CustomerCreatedManagedPolicy" ], "Policies": [ { diff --git a/tests/translator/output/aws-cn/function_with_alias_and_event_sources.json b/tests/translator/output/aws-cn/function_with_alias_and_event_sources.json index fbd97684b..8932fa573 100644 --- a/tests/translator/output/aws-cn/function_with_alias_and_event_sources.json +++ b/tests/translator/output/aws-cn/function_with_alias_and_event_sources.json @@ -1,4 +1,10 @@ { + "Parameters": { + "MyStageName": { + "Default": "beta", + "Type": "String" + } + }, "Resources": { "MyAwesomeFunctionAliasLive": { "Type": "AWS::Lambda::Alias", @@ -310,11 +316,11 @@ "MyAwesomeFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyAwesomeFunctionRole", @@ -435,19 +441,16 @@ "GetHtmlApiStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { - "Variables": { - "LambdaFunction": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAliasLive", - "Arn" - ] - } + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" }, "RestApiId": { "Ref": "GetHtmlApi" }, - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" + "Variables": { + "LambdaFunction": { + "Ref": "MyAwesomeFunction" + } }, "StageName": { "Ref": "MyStageName" diff --git a/tests/translator/output/aws-cn/function_with_condition.json b/tests/translator/output/aws-cn/function_with_condition.json index 543e1445c..4f2d5ccb7 100644 --- a/tests/translator/output/aws-cn/function_with_condition.json +++ b/tests/translator/output/aws-cn/function_with_condition.json @@ -1,14 +1,21 @@ { + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + "test", + "test" + ] + } + }, "Resources": { "ConditionFunction": { "Type": "AWS::Lambda::Function", - "Condition": "this is a test", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "ConditionFunctionRole", @@ -22,11 +29,11 @@ "Key": "lambda:createdBy" } ] - } - }, + }, + "Condition": "TestCondition" + }, "ConditionFunctionRole": { "Type": "AWS::IAM::Role", - "Condition": "this is a test", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -47,7 +54,8 @@ } ] } - } + }, + "Condition": "TestCondition" } } } \ No newline at end of file diff --git a/tests/translator/output/aws-cn/function_with_deployment_and_custom_role.json b/tests/translator/output/aws-cn/function_with_deployment_and_custom_role.json index 933c9879a..fccf8a8a2 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_and_custom_role.json +++ b/tests/translator/output/aws-cn/function_with_deployment_and_custom_role.json @@ -3,13 +3,16 @@ "FunctionWithRole": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { - "Ref": "DeploymentRole" + "Fn::GetAtt": [ + "DeploymentRole", + "Arn" + ] }, "Runtime": "python2.7", "Tags": [ @@ -23,11 +26,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", diff --git a/tests/translator/output/aws-cn/function_with_layers.json b/tests/translator/output/aws-cn/function_with_layers.json index 5d26c87e0..3f349ecfe 100644 --- a/tests/translator/output/aws-cn/function_with_layers.json +++ b/tests/translator/output/aws-cn/function_with_layers.json @@ -1,19 +1,84 @@ { "Resources": { + "MinimalLayerFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalLayerFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + } + }, + "FunctionReferencesLayer": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Layers": [ + { + "Ref": "MyLayera5167acaba" + } + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionReferencesLayerRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, "MinimalLayerFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -23,194 +88,135 @@ ] } } - }, - "MinimalLayerFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalLayerFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ] - } - }, - "FunctionNoLayerVersionRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionReferencesLayerRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ] } } - }, - "FunctionNoLayerVersion": { - "Type": "AWS::Lambda::Function", + }, + "FunctionLayerWithSubIntrinsic": { + "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpXLayer:1" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpYLayer:1" + } + ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionNoLayerVersionRole", + "FunctionLayerWithSubIntrinsicRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7" + } + }, + "FunctionNoLayerVersion": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ] + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionNoLayerVersionRole", + "Arn" + ] + }, + "Runtime": "python2.7" } - }, - "FunctionLayerWithSubIntrinsicRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionNoLayerVersionRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ] } } - }, - "FunctionLayerWithSubIntrinsic": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionLayerWithSubIntrinsicRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Layers": [ - {"Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:CorpXLayer:1"}, - {"Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:CorpYLayer:1"} - ] - } - }, - "MyLayera5167acaba": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", - "Properties": { - "LayerName": "MyLayer", - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - } - } - }, - "FunctionReferencesLayerRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionLayerWithSubIntrinsicRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ] } } - }, - "FunctionReferencesLayer": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionReferencesLayerRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Layers": [ - { "Ref": "MyLayera5167acaba" } - ] - } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/function_with_many_layers.json b/tests/translator/output/aws-cn/function_with_many_layers.json index a839dd5af..d95a35d8e 100644 --- a/tests/translator/output/aws-cn/function_with_many_layers.json +++ b/tests/translator/output/aws-cn/function_with_many_layers.json @@ -1,19 +1,30 @@ { "Resources": { + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + } + }, "ManyLayersFuncRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -23,46 +34,41 @@ ] } } - }, + }, "ManyLayersFunc": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:z:1", + { + "Fn::Sub": "arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1" + }, + "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1" + }, + { + "Ref": "MyLayera5167acaba" + } + ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ManyLayersFuncRole", - "Arn" - ] - }, - "Runtime": "python2.7", + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:z:1", - { "Fn::Sub": "arn:aws:lambda:${AWS:Region}:123456789101:layer:a:1" }, - "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:123456789101:layer:c:1" }, - { "Ref": "MyLayera5167acaba" } - ] - } - }, - "MyLayera5167acaba": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", - "Properties": { - "LayerName": "MyLayer", - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ManyLayersFuncRole", + "Arn" + ] + }, + "Runtime": "python2.7" } } } diff --git a/tests/translator/output/aws-cn/function_with_resource_refs.json b/tests/translator/output/aws-cn/function_with_resource_refs.json index c75603b91..566193806 100644 --- a/tests/translator/output/aws-cn/function_with_resource_refs.json +++ b/tests/translator/output/aws-cn/function_with_resource_refs.json @@ -1,50 +1,64 @@ { "Outputs": { "AliasArn": { - "Ref": "MinimalFunctionAliaslive" + "Value": { + "Ref": "MinimalFunctionAliaslive" + } }, "VersionArn": { - "Ref": "MinimalFunctionVersion640128d35d" + "Value": { + "Ref": "MinimalFunctionVersion640128d35d" + } }, "VersionNumber": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] + "Value": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + } }, "AliasName": { - "Fn::GetAtt": [ - "MinimalFunctionAliaslive", - "Name" - ] + "Value": { + "Fn::GetAtt": [ + "MinimalFunctionAliaslive", + "Name" + ] + } }, "UnResolvedVersion": { - "Ref": "FunctionWithoutAlias.Version" + "Value": { + "Ref": "FunctionWithoutAlias.Version" + } }, "AliasInSub": { - "Fn::Sub": [ - "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", - { - "SomeValue": "World" - } - ] + "Value": { + "Fn::Sub": [ + "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", + { + "SomeValue": "World" + } + ] + } }, "MustNotResolve": { - "Fn::GetAtt": [ - "FunctionWithoutAlias", - "Alias.Name" - ] + "Value": { + "Fn::GetAtt": [ + "FunctionWithoutAlias", + "Alias.Name" + ] + } } }, "Resources": { "FunctionWithoutAlias": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionWithoutAliasRole", @@ -87,11 +101,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", diff --git a/tests/translator/output/aws-cn/globals_for_api.json b/tests/translator/output/aws-cn/globals_for_api.json index 415765aba..bcfdd57ca 100644 --- a/tests/translator/output/aws-cn/globals_for_api.json +++ b/tests/translator/output/aws-cn/globals_for_api.json @@ -3,11 +3,11 @@ "ImplicitApiFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -68,77 +68,56 @@ } } }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "Prod", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, "ExplicitApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {}, + }, "security": [ { "MyCognitoAuth": [] } - ] + ], + "responses": {} } } - }, - "swagger": 2.0, + }, + "swagger": 2.0, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" @@ -177,6 +156,44 @@ "StageName": "Stage" } }, + "ExplicitApiSomeStageStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "SomeStage", + "CacheClusterSize": "1.6", + "Variables": { + "SomeVar": "Value" + }, + "CacheClusterEnabled": true, + "DeploymentId": { + "Ref": "ExplicitApiDeploymentd5fa0145e9" + } + } + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, "ExplicitApiDeploymentd5fa0145e9": { "Type": "AWS::ApiGateway::Deployment", "Properties": { @@ -187,6 +204,27 @@ "StageName": "Stage" } }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", + "Properties": { + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] + } + }, "ServerlessRestApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { @@ -207,36 +245,36 @@ "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } }, - "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] + ], + "responses": {} } } }, - "swagger": "2.0", + "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" @@ -247,23 +285,6 @@ "endpointConfigurationTypes": "REGIONAL" } } - }, - "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "SomeStage", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentd5fa0145e9" - } - } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/globals_for_function.json b/tests/translator/output/aws-cn/globals_for_function.json index a84c1d288..68cb93e88 100644 --- a/tests/translator/output/aws-cn/globals_for_function.json +++ b/tests/translator/output/aws-cn/globals_for_function.json @@ -7,7 +7,7 @@ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess" ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", + "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -29,6 +29,14 @@ "FunctionWithOverrides": { "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2" + } + ], "TracingConfig": { "Mode": "PassThrough" }, @@ -37,6 +45,9 @@ "S3Key": "hello.zip" }, "VpcConfig": { + "SubnetIds": [ + "sub-id-2" + ], "SecurityGroupIds": [ "sg-edcd9784", "sg-123" @@ -56,8 +67,8 @@ "Key": "tag1" } ], - "MemorySize": 512, "ReservedConcurrentExecutions": 100, + "MemorySize": 512, "Environment": { "Variables": { "Var1": "value1", @@ -73,11 +84,7 @@ ] }, "Timeout": 100, - "Runtime": "nodejs4.3", - "Layers": [ - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer:1" }, - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer2:2" } - ] + "Runtime": "nodejs4.3" } }, "MinimalFunctionRole": { @@ -87,7 +94,7 @@ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess" ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -124,6 +131,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" + } + ], "TracingConfig": { "Mode": "Active" }, @@ -132,6 +144,9 @@ "S3Key": "global.zip" }, "VpcConfig": { + "SubnetIds": [ + "sub-id-2" + ], "SecurityGroupIds": [ "sg-edcd9784" ] @@ -146,8 +161,8 @@ "Key": "tag1" } ], - "MemorySize": 1024, "ReservedConcurrentExecutions": 50, + "MemorySize": 1024, "Environment": { "Variables": { "Var1": "value1", @@ -162,10 +177,7 @@ ] }, "Timeout": 30, - "Runtime": "python2.7", - "Layers": [ - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer:1" } - ] + "Runtime": "python2.7" } }, "MinimalFunctionAliaslive": { @@ -202,4 +214,4 @@ } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/intrinsic_functions.json b/tests/translator/output/aws-cn/intrinsic_functions.json index 7953f8f44..eb55eab1c 100644 --- a/tests/translator/output/aws-cn/intrinsic_functions.json +++ b/tests/translator/output/aws-cn/intrinsic_functions.json @@ -1,5 +1,17 @@ { + "Conditions": { + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, "Parameters": { + "CodeKey": { + "Default": "key", + "Type": "String" + }, "CodeBucket": { "Default": "sam-demo-bucket", "Type": "String" @@ -16,16 +28,183 @@ "Default": "PassThrough", "Type": "String" } - }, - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - } - }, + }, "Resources": { + "MyExplicitApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "swagger.yaml" + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + }, + "Name": { + "Ref": "MyExplicitApiName" + } + } + }, + "MyTable": { + "Type": "AWS::DynamoDB::Table", + "Properties": { + "KeySchema": [ + { + "KeyType": "HASH", + "AttributeName": "id" + } + ], + "StreamSpecification": { + "StreamViewType": "NEW_IMAGE" + }, + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "ProvisionedThroughput": { + "WriteCapacityUnits": 5, + "ReadCapacityUnits": 5 + } + } + }, + "SnsDlqQueue": { + "Type": "AWS::SNS::Topic" + }, + "MySqsDlqLambdaFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "DeadLetterConfig": { + "TargetArn": { + "Fn::GetAtt": [ + "SqsDlqQueue", + "Arn" + ] + } + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MySqsDlqLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, + "SqsDlqQueue": { + "Type": "AWS::SQS::Queue" + }, + "ApiWithExplicitS3Uri": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "BodyS3Location": { + "Version": "myversion", + "Bucket": "mybucket", + "Key": "mykey" + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Condition": "TrueCondition" + }, + "MyExplicitApiDeployment31ec20c228": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "Description": "RestApi deployment id: 31ec20c2288b273d15235777b0b90f3c0e2f9d52", + "StageName": "Stage" + } + }, + "FunctionWithExplicitS3Uri": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "stream.ddb_handler", + "Code": { + "S3Bucket": "mybucket", + "S3Key": "mykey", + "S3ObjectVersion": "MyVersion" + }, + "Role": { + "Fn::GetAtt": [ + "FunctionWithExplicitS3UriRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MySnsDlqLambdaFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Policies": [ + { + "PolicyName": "DeadLetterQueuePolicy", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sns:Publish", + "Resource": { + "Ref": "SnsDlqQueue" + }, + "Effect": "Allow" + } + ] + } + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "MyFunction": { "Type": "AWS::Lambda::Function", "Properties": { @@ -39,9 +218,7 @@ "Ref": "CodeBucket" }, "S3Key": { - "Fn::Sub": [ - "code.zip" - ] + "Fn::Sub": "code.zip.${CodeKey}" }, "S3ObjectVersion": { "Fn::Join": [ @@ -111,19 +288,6 @@ } } }, - "ApiWithExplicitS3UridevStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "TrueCondition", - "Properties": { - "DeploymentId": { - "Ref": "ApiWithExplicitS3UriDeploymenta227798f00" - }, - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" - }, - "StageName": "dev" - } - }, "DynamoDBFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { @@ -158,10 +322,7 @@ }, "DeadLetterConfig": { "TargetArn": { - "Fn::GetAtt": [ - "SnsDlqQueue", - "Arn" - ] + "Ref": "SnsDlqQueue" } }, "Tags": [ @@ -180,37 +341,6 @@ "Runtime": "python2.7" } }, - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "swagger.yaml" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "Name": { - "Ref": "MyExplicitApiName" - } - } - }, - "ApiWithExplicitS3UriDeploymenta227798f00": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "TrueCondition", - "Properties": { - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" - }, - "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", - "StageName": "Stage" - } - }, "MyFunctionMyApiPermissionTest": { "Type": "AWS::Lambda::Permission", "Properties": { @@ -232,41 +362,53 @@ } } }, - "MyTable": { - "Type": "AWS::DynamoDB::Table", + "MyNewRole": { + "Type": "AWS::IAM::Role", "Properties": { - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ + "Policies": [ { - "AttributeName": "id", - "AttributeType": "S" + "PolicyName": "lambdaRole", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "cloudwatch:*", + "logs:*" + ], + "Resource": "*", + "Effect": "Allow" + } + ] + } } ], - "ProvisionedThroughput": { - "WriteCapacityUnits": "5", - "ReadCapacityUnits": "5" + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] } } }, - "SnsDlqQueue": { - "Type": "AWS::SNS::Topic" - }, "DynamoDBFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "stream.ddb_handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "streams.zip" }, - "Handler": "stream.ddb_handler", "Role": { "Fn::GetAtt": [ "DynamoDBFunctionRole", @@ -282,62 +424,18 @@ ] } }, - "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "DeadLetterConfig": { - "TargetArn": { - "Fn::GetAtt": [ - "SqsDlqQueue", - "Arn" - ] - } - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MySqsDlqLambdaFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "MyExplicitApidevStage": { + "ApiWithExplicitS3UridevStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { - "Variables": { - "FunctionName": { - "Fn::Sub": "${MyFunction}" - }, - "Var2": { - "Fn::Join": [ - "join ", - [ - "some value ", - "with some other value" - ] - ] - } + "DeploymentId": { + "Ref": "ApiWithExplicitS3UriDeploymenta227798f00" }, "RestApiId": { - "Ref": "MyExplicitApi" - }, - "DeploymentId": { - "Ref": "MyExplicitApiDeployment31ec20c228" + "Ref": "ApiWithExplicitS3Uri" }, "StageName": "dev" - } + }, + "Condition": "TrueCondition" }, "DynamoDBFunctionMyDDBStream": { "Type": "AWS::Lambda::EventSourceMapping", @@ -355,37 +453,16 @@ "StartingPosition": "LATEST" } }, - "SqsDlqQueue": { - "Type": "AWS::SQS::Queue" - }, - "MyExplicitApiDeployment31ec20c228": { + "ApiWithExplicitS3UriDeploymenta227798f00": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { - "Ref": "MyExplicitApi" + "Ref": "ApiWithExplicitS3Uri" }, - "Description": "RestApi deployment id: 31ec20c2288b273d15235777b0b90f3c0e2f9d52", + "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", "StageName": "Stage" - } - }, - "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", - "Condition": "TrueCondition", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Version": "myversion", - "Bucket": "mybucket", - "Key": "mykey" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + }, + "Condition": "TrueCondition" }, "MySqsDlqLambdaFunctionRole": { "Type": "AWS::IAM::Role", @@ -431,72 +508,30 @@ } } }, - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ - { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": { - "Fn::GetAtt": [ - "SnsDlqQueue", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", + "MyExplicitApidevStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { - "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", - "S3ObjectVersion": "MyVersion" + "DeploymentId": { + "Ref": "MyExplicitApiDeployment31ec20c228" }, - "Handler": "stream.ddb_handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", - "Arn" - ] + "RestApiId": { + "Ref": "MyExplicitApi" }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Variables": { + "FunctionName": { + "Fn::Sub": "${MyFunction}" + }, + "Var2": { + "Fn::Join": [ + "join ", + [ + "some value ", + "with some other value" + ] + ] } - ] + }, + "StageName": "dev" } }, "MyFunctionMyApiPermissiondev": { diff --git a/tests/translator/output/aws-cn/layers_all_properties.json b/tests/translator/output/aws-cn/layers_all_properties.json index 72b43d607..4cebed47b 100644 --- a/tests/translator/output/aws-cn/layers_all_properties.json +++ b/tests/translator/output/aws-cn/layers_all_properties.json @@ -1,50 +1,105 @@ { + "Outputs": { + "LayerSub": { + "Value": { + "Fn::Sub": "${MyLayerd04062b365}" + } + }, + "FunctionAtt": { + "Value": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + }, + "LayerName": { + "Value": { + "Ref": "MyLayerd04062b365" + } + }, + "FunctionSub": { + "Value": { + "Fn::Sub": "${MyFunction}" + } + }, + "FunctionName": { + "Value": { + "Ref": "MyFunction" + } + } + }, "Parameters": { "LayerDeleteParam": { "Default": "Delete", "Type": "String" } - }, + }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Ref": "MyLayerd04062b365" + } + ], "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, - "Handler": "app.handler", + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "app.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python3.6", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], - "Layers": [ - { - "Ref": "MyLayerd04062b365" - } - ] + }, + "Runtime": "python3.6" + } + }, + "MyLayerd04062b365": { + "DeletionPolicy": "Delete", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "MyLayer" } - }, + }, + "MyLayerWithANamefda8c9ec8c": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "DifferentLayerName" + } + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -52,71 +107,8 @@ } } ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ] - } - }, - "MyLayerd04062b365": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Delete", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "MyLayer" - } - }, - "MyLayerWithANamefda8c9ec8c": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "DifferentLayerName" - } - } - }, - "Outputs": { - "LayerName": { - "Value": { - "Ref": "MyLayerd04062b365" - } - }, - "FunctionName": { - "Value": { - "Ref": "MyFunction" - } - }, - "LayerAtt": { - "Value": { - "Fn::GetAtt": [ - "MyLayerd04062b365", - "Arn" - ] - } - }, - "FunctionAtt": { - "Value": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - } - }, - "LayerSub": { - "Value": { - "Fn::Sub": "${MyLayerd04062b365}" - } - }, - "FunctionSub": { - "Value": { - "Fn::Sub": "${MyFunction}" + } } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/no_implicit_api_with_serverless_rest_api_resource.json b/tests/translator/output/aws-cn/no_implicit_api_with_serverless_rest_api_resource.json index 4cc3a9353..68e16942b 100644 --- a/tests/translator/output/aws-cn/no_implicit_api_with_serverless_rest_api_resource.json +++ b/tests/translator/output/aws-cn/no_implicit_api_with_serverless_rest_api_resource.json @@ -1,25 +1,29 @@ { "Resources": { - "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "GetHtmlFunction": { + "Type": "AWS::Lambda::Function", "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" ] - } + }, + "Runtime": "python3.6", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] } }, - "ThumbnailFunctionRole": { + "GetHtmlFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ @@ -55,15 +59,107 @@ }, "Principal": "s3.amazonaws.com" } - }, + }, + "RestApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "RestApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.6", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ThumbnailFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "Images": { + "Type": "AWS::S3::Bucket", + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + }, + "Event": "s3:ObjectCreated:*" + } + ] + } + }, + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ] + }, "ThumbnailFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.generate_thumbails", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ "ThumbnailFunctionRole", @@ -78,9 +174,6 @@ } ] } - - - }, "ServerlessRestApi": { "Type": "AWS::ApiGateway::RestApi", diff --git a/tests/translator/output/aws-cn/s3_existing_other_notification_configuration.json b/tests/translator/output/aws-cn/s3_existing_other_notification_configuration.json index 285eda70c..c8e2fe1fd 100644 --- a/tests/translator/output/aws-cn/s3_existing_other_notification_configuration.json +++ b/tests/translator/output/aws-cn/s3_existing_other_notification_configuration.json @@ -1,8 +1,7 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "Type": "AWS::S3::Bucket", "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ @@ -18,11 +17,15 @@ ], "TopicConfigurations": [ { - "Topic": "my-super-awesome-topic" + "Topic": "my-super-awesome-topic", + "Event": "s3:ObjectRemoved:*" } ] } - } + }, + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ] }, "ThumbnailFunctionRole": { "Type": "AWS::IAM::Role", @@ -64,11 +67,11 @@ "ThumbnailFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.generate_thumbails", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ "ThumbnailFunctionRole", diff --git a/tests/translator/output/aws-cn/s3_with_condition.json b/tests/translator/output/aws-cn/s3_with_condition.json index a4d06271c..6b8e7f8d9 100644 --- a/tests/translator/output/aws-cn/s3_with_condition.json +++ b/tests/translator/output/aws-cn/s3_with_condition.json @@ -1,48 +1,55 @@ { + "Conditions": { + "MyCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, "Resources": { "Images": { - "Type": "AWS::S3::Bucket", + "Type": "AWS::S3::Bucket", "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { "Fn::If": [ - "MyCondition", + "MyCondition", { "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, + }, "Event": "s3:ObjectCreated:*" - }, + }, { "Ref": "AWS::NoValue" } ] } ] - }, + }, "Tags": [ { "Value": { "Fn::If": [ - "MyCondition", + "MyCondition", { "Ref": "ThumbnailFunctionImageBucketPermission" - }, + }, "no dependency" ] - }, + }, "Key": "sam:ConditionalDependsOn:ThumbnailFunctionImageBucketPermission" } - ] + ] } }, "ThumbnailFunctionRole": { "Type": "AWS::IAM::Role", - "Condition": "MyCondition", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -63,11 +70,11 @@ } ] } - } + }, + "Condition": "MyCondition" }, "ThumbnailFunctionImageBucketPermission": { "Type": "AWS::Lambda::Permission", - "Condition": "MyCondition", "Properties": { "Action": "lambda:invokeFunction", "SourceAccount": { @@ -77,17 +84,17 @@ "Ref": "ThumbnailFunction" }, "Principal": "s3.amazonaws.com" - } + }, + "Condition": "MyCondition" }, "ThumbnailFunction": { "Type": "AWS::Lambda::Function", - "Condition": "MyCondition", "Properties": { + "Handler": "index.generate_thumbails", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ "ThumbnailFunctionRole", @@ -101,7 +108,8 @@ "Key": "lambda:createdBy" } ] - } + }, + "Condition": "MyCondition" } } } \ No newline at end of file diff --git a/tests/translator/output/aws-cn/simple_table_ref_parameter_intrinsic.json b/tests/translator/output/aws-cn/simple_table_ref_parameter_intrinsic.json index d158adc9f..cd79e4bc1 100644 --- a/tests/translator/output/aws-cn/simple_table_ref_parameter_intrinsic.json +++ b/tests/translator/output/aws-cn/simple_table_ref_parameter_intrinsic.json @@ -1,4 +1,18 @@ { + "Parameters": { + "ReadCapacity": { + "Default": 15, + "Type": "Number" + }, + "WriteCapacity": { + "Default": 15, + "Type": "Number" + }, + "EnableSSE": { + "Default": true, + "Type": "String" + } + }, "Resources": { "MinimalTableRefParamLongForm": { "Type": "AWS::DynamoDB::Table", diff --git a/tests/translator/output/aws-cn/simple_table_with_extra_tags.json b/tests/translator/output/aws-cn/simple_table_with_extra_tags.json index 23d2f3fb6..a02e088cd 100644 --- a/tests/translator/output/aws-cn/simple_table_with_extra_tags.json +++ b/tests/translator/output/aws-cn/simple_table_with_extra_tags.json @@ -1,4 +1,10 @@ { + "Parameters": { + "TagValueParam": { + "Default": "value", + "Type": "String" + } + }, "Resources": { "MinimalTableWithTags": { "Type": "AWS::DynamoDB::Table", @@ -32,7 +38,7 @@ "Key": "TagKey3" }, { - "Value": 123, + "Value": "123", "Key": "TagKey4" } ] diff --git a/tests/translator/output/aws-cn/simple_table_with_table_name.json b/tests/translator/output/aws-cn/simple_table_with_table_name.json index 215960a56..f70cdcc4e 100644 --- a/tests/translator/output/aws-cn/simple_table_with_table_name.json +++ b/tests/translator/output/aws-cn/simple_table_with_table_name.json @@ -1,4 +1,10 @@ { + "Parameters": { + "MySimpleTableParameter": { + "Default": "TableName", + "Type": "String" + } + }, "Resources": { "MinimalTableWithTableName": { "Type": "AWS::DynamoDB::Table", diff --git a/tests/translator/output/aws-us-gov/api_endpoint_configuration.json b/tests/translator/output/aws-us-gov/api_endpoint_configuration.json index 39da0993d..e892e6107 100644 --- a/tests/translator/output/aws-us-gov/api_endpoint_configuration.json +++ b/tests/translator/output/aws-us-gov/api_endpoint_configuration.json @@ -1,5 +1,5 @@ { - "Properties": { + "Parameters": { "EndpointConfig": { "Type": "String" } @@ -8,11 +8,11 @@ "ImplicitApiFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", diff --git a/tests/translator/output/aws-us-gov/api_with_auth_all_minimum.json b/tests/translator/output/aws-us-gov/api_with_auth_all_minimum.json index 999138fa0..494ceb190 100644 --- a/tests/translator/output/aws-us-gov/api_with_auth_all_minimum.json +++ b/tests/translator/output/aws-us-gov/api_with_auth_all_minimum.json @@ -1,130 +1,134 @@ { "Resources": { - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__Stage__": "Prod", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/cognito": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [{ - "MyCognitoAuth": [] - }], + }, + "security": [ + { + "MyCognitoAuth": [] + } + ], "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "providerARNs": [{ - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - }], + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } } - }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeploymentca86749bcd" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + } + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithLambdaTokenAuth" } } ] } } - }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyFnLambdaRequestPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeploymentca86749bcd" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "StageName": "Prod" + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaTokenPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { - "__Stage__": "Prod", + "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } @@ -132,116 +136,133 @@ ] } } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnCognitoPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", { - "__Stage__": "Prod", + "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithCognitoAuth" } } ] } } - }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + }, + "MyAuthFn": { + "Type": "AWS::Lambda::Function", "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/lambda-token": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "security": [{ - "MyLambdaTokenAuth": [] - }], - "responses": {} + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyApiWithLambdaTokenAuthDeployment5192789870": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "Description": "RestApi deployment id: 5192789870157c12b0fb5a78c7e570d22c4e46f5", + "StageName": "Stage" + } + }, + "MyFnRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" } } - }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyApiWithCognitoAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment5192789870" - }, + "Ref": "MyApiWithCognitoAuthDeployment9b695a6dd5" + }, "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, + "Ref": "MyApiWithCognitoAuth" + }, "StageName": "Prod" } - }, - "MyFnLambdaRequestPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnCognitoPermissionProd": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + } + } + ] + } + } + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } @@ -249,20 +270,20 @@ ] } } - }, - "MyFnLambdaTokenPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaTokenPermissionProd": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { - "__Stage__": "*", + "__Stage__": "Prod", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } @@ -270,198 +291,257 @@ ] } } - }, - "MyFnCognitoPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaRequestPermissionProd": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", { - "__Stage__": "*", + "__Stage__": "Prod", "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" + "Ref": "MyApiWithLambdaRequestAuth" } } ] } } - }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + }, + "MyApiWithLambdaTokenAuth": { + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { - "/lambda-request": { + "/lambda-token": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [{ - "MyLambdaRequestAuth": [] - }], + }, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + "MyLambdaTokenAuth": { + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", + "type": "token", "authorizerUri": { "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] } } ] } - }, + }, "x-amazon-apigateway-authtype": "custom" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } } - }, + }, "MyApiWithLambdaRequestAuthDeploymentca86749bcd": { - "Type": "AWS::ApiGateway::Deployment", + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyApiWithLambdaRequestAuth" - }, - "Description": "RestApi deployment id: ca86749bcd339b4d6564954e2e12b20ebf9fb2ff", + }, + "Description": "RestApi deployment id: ca86749bcd339b4d6564954e2e12b20ebf9fb2ff", "StageName": "Stage" } - }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] + } + }, + "MyFn": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { "Fn::GetAtt": [ - "MyAuthFn", + "MyFnRole", "Arn" ] - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyAuthFnRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } ] } } - }, - "MyApiWithLambdaTokenAuthDeployment5192789870": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment5192789870" + }, "RestApiId": { "Ref": "MyApiWithLambdaTokenAuth" - }, - "Description": "RestApi deployment id: 5192789870157c12b0fb5a78c7e570d22c4e46f5", - "StageName": "Stage" - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } + }, + "StageName": "Prod" } - }, + }, "MyApiWithCognitoAuthDeployment9b695a6dd5": { - "Type": "AWS::ApiGateway::Deployment", + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 9b695a6dd5c12bb346b4163227f398c34128a49a", + }, + "Description": "RestApi deployment id: 9b695a6dd5c12bb346b4163227f398c34128a49a", "StageName": "Stage" } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment9b695a6dd5" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", + }, + "MyApiWithLambdaRequestAuth": { + "Type": "AWS::ApiGateway::RestApi", "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/lambda-request": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + }, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], + "responses": {} + } + } + }, + "swagger": "2.0", + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "type": "apiKey", + "name": "Unused", + "x-amazon-apigateway-authorizer": { + "type": "request", + "identitySource": "method.request.header.Authorization1", + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + } + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] - }, - "Runtime": "nodejs8.10", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } } } } diff --git a/tests/translator/output/aws-us-gov/api_with_auth_no_default.json b/tests/translator/output/aws-us-gov/api_with_auth_no_default.json index 2f19c769a..98704d414 100644 --- a/tests/translator/output/aws-us-gov/api_with_auth_no_default.json +++ b/tests/translator/output/aws-us-gov/api_with_auth_no_default.json @@ -1,147 +1,129 @@ { "Resources": { - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__Stage__": "Prod", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/cognito": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + }, "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "providerARNs": [{ - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - }], + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } } - }, - "MyApiWithCognitoAuthDeployment2da3114321": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeployment9a21d88fe2" + }, "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 2da3114321f3a31e83ea7029e5b167e14f36e7fb", - "StageName": "Stage" + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" } - }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithLambdaTokenAuth" } } ] } } - }, - "MyApiWithLambdaTokenAuthDeployment613e605d96": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "Description": "RestApi deployment id: 613e605d962dfc3e8ac8e456357d807af4264223", - "StageName": "Stage" - } - }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyFnLambdaRequestPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment9a21d88fe2" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "StageName": "Prod" + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFn" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaTokenPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { - "__Stage__": "Prod", + "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } @@ -149,113 +131,133 @@ ] } } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnCognitoPermissionTest": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", { - "__Stage__": "Prod", + "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithCognitoAuth" } } ] } } - }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + }, + "MyAuthFn": { + "Type": "AWS::Lambda::Function", "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/lambda-token": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {} + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyFnRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" } } - }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyApiWithCognitoAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment613e605d96" - }, + "Ref": "MyApiWithCognitoAuthDeployment2da3114321" + }, "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, + "Ref": "MyApiWithCognitoAuth" + }, "StageName": "Prod" } - }, - "MyFnLambdaRequestPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnCognitoPermissionProd": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + } + } + ] + } + } + }, + "MyApiWithCognitoAuthDeployment2da3114321": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "Description": "RestApi deployment id: 2da3114321f3a31e83ea7029e5b167e14f36e7fb", + "StageName": "Stage" + } + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } @@ -263,20 +265,30 @@ ] } } - }, - "MyFnLambdaTokenPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyApiWithLambdaTokenAuthDeployment613e605d96": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "Description": "RestApi deployment id: 613e605d962dfc3e8ac8e456357d807af4264223", + "StageName": "Stage" + } + }, + "MyFnLambdaTokenPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { - "__Stage__": "*", + "__Stage__": "Prod", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } @@ -284,175 +296,237 @@ ] } } - }, - "MyFnCognitoPermissionTest": { - "Type": "AWS::Lambda::Permission", + }, + "MyFnLambdaRequestPermissionProd": { + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", { - "__Stage__": "*", + "__Stage__": "Prod", "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" + "Ref": "MyApiWithLambdaRequestAuth" } } ] } } - }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + }, + "MyApiWithLambdaTokenAuth": { + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { - "/lambda-request": { + "/lambda-token": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + }, "responses": {} } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "securityDefinitions": { - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + "MyLambdaTokenAuth": { + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", + "type": "token", "authorizerUri": { "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] } } ] } - }, + }, "x-amazon-apigateway-authtype": "custom" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } } - }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] + } + }, + "MyFn": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { "Fn::GetAtt": [ - "MyAuthFn", + "MyFnRole", "Arn" ] - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyAuthFnRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } ] } } - }, + }, "MyApiWithLambdaRequestAuthDeployment9a21d88fe2": { - "Type": "AWS::ApiGateway::Deployment", + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyApiWithLambdaRequestAuth" - }, - "Description": "RestApi deployment id: 9a21d88fe25a74e9f2ca61175f4dd4d281b61d12", + }, + "Description": "RestApi deployment id: 9a21d88fe25a74e9f2ca61175f4dd4d281b61d12", "StageName": "Stage" } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment2da3114321" - }, + "Ref": "MyApiWithLambdaTokenAuthDeployment613e605d96" + }, "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, + "Ref": "MyApiWithLambdaTokenAuth" + }, "StageName": "Prod" } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", + }, + "MyApiWithLambdaRequestAuth": { + "Type": "AWS::ApiGateway::RestApi", "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/lambda-request": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + }, + "responses": {} + } + } + }, + "swagger": "2.0", + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "type": "apiKey", + "name": "Unused", + "x-amazon-apigateway-authorizer": { + "type": "request", + "identitySource": "method.request.header.Authorization1", + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + } + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] - }, - "Runtime": "nodejs8.10", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } } } } diff --git a/tests/translator/output/aws-us-gov/api_with_cors.json b/tests/translator/output/aws-us-gov/api_with_cors.json index ccc64a158..080bb844a 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors.json +++ b/tests/translator/output/aws-us-gov/api_with_cors.json @@ -3,11 +3,11 @@ "ImplicitApiFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -134,9 +134,9 @@ "application/json": "{}\n" }, "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Origin": "origins", "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Credentials": "'true'" } } @@ -157,7 +157,7 @@ }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, "Access-Control-Allow-Credentials": { "type": "string" } @@ -184,9 +184,9 @@ "application/json": "{}\n" }, "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Origin": "origins", "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Headers": "headers", "method.response.header.Access-Control-Allow-Credentials": "'true'" } } @@ -207,7 +207,7 @@ }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, "Access-Control-Allow-Credentials": { "type": "string" } @@ -243,6 +243,30 @@ } } }, + "GetHtmlFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "ServerlessRestApiProdStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { @@ -267,6 +291,30 @@ "StageName": "Prod" } }, + "RestApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "ImplicitApiFunctionGetHtmlPermissionProd": { "Type": "AWS::Lambda::Permission", "Properties": { @@ -294,10 +342,33 @@ "RestApiId": { "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", + "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", "StageName": "Stage" } }, + "RestApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, "ServerlessRestApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { @@ -442,6 +513,29 @@ } } }, + "GetHtmlFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, "ImplicitApiFunctionAnyApiPermissionTest": { "Type": "AWS::Lambda::Permission", "Properties": { diff --git a/tests/translator/output/aws-us-gov/api_with_cors_and_only_credentials_false.json b/tests/translator/output/aws-us-gov/api_with_cors_and_only_credentials_false.json index 06e79c17a..61b81d0e0 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_and_only_credentials_false.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_and_only_credentials_false.json @@ -1,13 +1,50 @@ { "Resources": { - "ExplicitApiDeployment398246867a": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunction": { + "Type": "AWS::Lambda::Function", "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" }, - "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", - "StageName": "Stage" + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ImplicitApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } } }, "ExplicitApiProdStage": { @@ -22,6 +59,16 @@ "StageName": "Prod" } }, + "ExplicitApiDeployment398246867a": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", + "StageName": "Stage" + } + }, "ExplicitApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { diff --git a/tests/translator/output/aws-us-gov/api_with_cors_and_only_maxage.json b/tests/translator/output/aws-us-gov/api_with_cors_and_only_maxage.json index 6b05e51fb..e1d3268bf 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_and_only_maxage.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_and_only_maxage.json @@ -1,5 +1,52 @@ { "Resources": { + "ImplicitApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ImplicitApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "ExplicitApiDeploymentb61cfb7d60": { "Type": "AWS::ApiGateway::Deployment", "Properties": { diff --git a/tests/translator/output/aws-us-gov/api_with_resource_refs.json b/tests/translator/output/aws-us-gov/api_with_resource_refs.json index c3244fb77..4e54827c7 100644 --- a/tests/translator/output/aws-us-gov/api_with_resource_refs.json +++ b/tests/translator/output/aws-us-gov/api_with_resource_refs.json @@ -1,27 +1,35 @@ { "Outputs": { "ImplicitApiDeployment": { - "Ref": "ServerlessRestApiDeployment2657ea030d" + "Value": { + "Ref": "ServerlessRestApiDeployment2657ea030d" + } }, "ExplicitApiDeployment": { - "Ref": "MyApiDeployment359f256a3b" + "Value": { + "Ref": "MyApiDeployment359f256a3b" + } }, "ExplicitApiStage": { - "Ref": "MyApifooStage" + "Value": { + "Ref": "MyApifooStage" + } }, "ImplicitApiStage": { - "Ref": "ServerlessRestApiProdStage" + "Value": { + "Ref": "ServerlessRestApiProdStage" + } } }, "Resources": { "MyFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyFunctionRole", diff --git a/tests/translator/output/aws-us-gov/basic_application.json b/tests/translator/output/aws-us-gov/basic_application.json index e2056aaca..058e8037e 100644 --- a/tests/translator/output/aws-us-gov/basic_application.json +++ b/tests/translator/output/aws-us-gov/basic_application.json @@ -1,94 +1,100 @@ { + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, "Resources": { - "BasicApplication": { - "Type": "AWS::CloudFormation::Stack", + "NormalApplication": { + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "NotificationARNs": [ + "arn:aws:sns:us-east-1:123456789012:sns-arn" + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TimeoutInMinutes": 15, + "Parameters": { + "IdentityNameParameter": "IdentityName" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", "Key": "serverlessrepo:applicationId" - }, + }, { - "Value": "1.0.2", + "Value": "1.0.2", "Key": "serverlessrepo:semanticVersion" + }, + { + "Value": "TagValue", + "Key": "TagName" } ] } - }, - "NormalApplication": { - "Type": "AWS::CloudFormation::Stack", + }, + "BasicApplication": { + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", "Key": "serverlessrepo:applicationId" - }, + }, { - "Value": "1.0.2", + "Value": "1.0.2", "Key": "serverlessrepo:semanticVersion" - }, - { - "Value": "TagValue", - "Key": "TagName" } - ], - "Parameters": - { - "IdentityNameParameter": "IdentityName" - }, - "NotificationArns": - [ - "arn:aws:sns:us-east-1:123456789012:sns-arn" - ], - "TimeoutInMinutes": 15 + ] } - }, + }, "ApplicationWithLocationUrl": { - "Type": "AWS::CloudFormation::Stack", + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml", + "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "TagValue2", + "Value": "TagValue2", "Key": "TagName2" } ] } - }, + }, "ApplicationWithCondition": { - "Type": "AWS::CloudFormation::Stack", + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", "Key": "serverlessrepo:applicationId" - }, + }, { - "Value": "1.0.2", + "Value": "1.0.2", "Key": "serverlessrepo:semanticVersion" } ] - }, - "Condition": "this is a test" + }, + "Condition": "TestCondition" } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/basic_function.json b/tests/translator/output/aws-us-gov/basic_function.json index 2e2e48f7c..b386270b2 100644 --- a/tests/translator/output/aws-us-gov/basic_function.json +++ b/tests/translator/output/aws-us-gov/basic_function.json @@ -1,70 +1,54 @@ { + "Parameters": { + "SomeParameter": { + "Default": "param", + "Type": "String" + }, + "SomeOtherParameter": { + "Default": "otherparam", + "Type": "String" + } + }, "Resources": { - "FunctionWithTracingRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AWSXrayWriteOnlyAccess" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "FunctionWithTracing": { - "Type": "AWS::Lambda::Function", + "FunctionWithInlineCode": { + "Type": "AWS::Lambda::Function", "Properties": { + "TracingConfig": { + "Mode": "Active" + }, "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithTracingRole", - "Arn" - ] - }, - "Runtime": "python2.7", + "ZipFile": "hello world" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "TracingConfig": { - "Mode": "Active" - } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithInlineCodeRole", + "Arn" + ] + }, + "Runtime": "python2.7" } - }, + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -74,90 +58,90 @@ ] } } - }, + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "FunctionWithPolicyDocument": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, "Role": { "Fn::GetAtt": [ - "FunctionWithPolicyDocumentRole", + "FunctionWithPolicyDocumentRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "FunctionWithPolicies": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, "Role": { "Fn::GetAtt": [ - "FunctionWithPoliciesRole", + "FunctionWithPoliciesRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "FunctionWithCodeUriObjectRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -167,34 +151,34 @@ ] } } - }, + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { - "Path": "/", + "Path": "/", "Policies": [ { - "PolicyName": "root", + "PolicyName": "root", "PolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { - "Action": "*", - "Resource": "*", + "Action": "*", + "Resource": "*", "Effect": "Allow" } ] } } - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "ec2.amazonaws.com" @@ -204,90 +188,88 @@ ] } } - }, + }, "CompleteFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "FunctionName": "MyAwesomeFunction", + }, + "Description": "Starter Lambda Function", "VpcConfig": { "SubnetIds": [ - "subnet-9d4a7b6c", - "subnet-65ea5f08" - ], - "SubnetIdsUsingRef": [ + "subnet-9d4a7b6c", + "subnet-65ea5f08", { "Ref": "SomeParameter" - }, + }, { "Ref": "SomeOtherParameter" } - ], + ], "SecurityGroupIds": [ "sg-edcd9784" ] - }, + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], + ], "Environment": { "Variables": { - "Name2": "Value2", + "Name2": "Value2", "Name": "Value" } - }, - "Handler": "hello.handler", - "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", - "Timeout": 60, - "Runtime": "python2.7", - "Description": "Starter Lambda Function" + }, + "Handler": "hello.handler", + "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", + "Timeout": 60, + "Runtime": "python2.7", + "FunctionName": "MyAwesomeFunction" } - }, + }, "FunctionWithCodeUriObject": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "somebucket", - "S3Key": "somekey", - "S3ObjectVersion": 1 - }, - "Handler": "hello.handler", + "S3Bucket": "somebucket", + "S3Key": "somekey", + "S3ObjectVersion": "1" + }, "Role": { "Fn::GetAtt": [ - "FunctionWithCodeUriObjectRole", + "FunctionWithCodeUriObjectRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "FunctionWithPoliciesRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -297,60 +279,22 @@ ] } } - }, - "FunctionWithRoleRef": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionWithPolicyDocumentRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionWithInlineCodeRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ - { - "PolicyName": "FunctionWithPolicyDocumentRolePolicy0", - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "dynamodb:*" - ], - "Resource": "*", - "Effect": "Allow" - } - ] - } - } - ], + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AWSXrayWriteOnlyAccess" + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -360,22 +304,22 @@ ] } } - }, - "FunctionWithInlineCodeRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionWithTracingRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/AWSXrayWriteOnlyAccess" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -385,31 +329,95 @@ ] } } - }, - "FunctionWithInlineCode": { - "Type": "AWS::Lambda::Function", + }, + "FunctionWithRoleRef": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "FunctionWithTracing": { + "Type": "AWS::Lambda::Function", "Properties": { "TracingConfig": { "Mode": "Active" - }, + }, "Code": { - "ZipFile": "hello world" - }, + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Handler": "hello.handler", + ], + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithInlineCodeRole", + "FunctionWithTracingRole", "Arn" ] - }, + }, "Runtime": "python2.7" } + }, + "FunctionWithPolicyDocumentRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Policies": [ + { + "PolicyName": "FunctionWithPolicyDocumentRolePolicy0", + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:*" + ], + "Resource": "*", + "Effect": "Allow" + } + ] + } + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/basic_function_with_tags.json b/tests/translator/output/aws-us-gov/basic_function_with_tags.json index 044d0967a..c7e48394b 100644 --- a/tests/translator/output/aws-us-gov/basic_function_with_tags.json +++ b/tests/translator/output/aws-us-gov/basic_function_with_tags.json @@ -69,7 +69,7 @@ "Key": "TagKey3" }, { - "Value": 123, + "Value": "123", "Key": "TagKey4" } ], diff --git a/tests/translator/output/aws-us-gov/basic_layer.json b/tests/translator/output/aws-us-gov/basic_layer.json index 0b0a67400..d373bd19c 100644 --- a/tests/translator/output/aws-us-gov/basic_layer.json +++ b/tests/translator/output/aws-us-gov/basic_layer.json @@ -1,56 +1,64 @@ { + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + "beta", + "beta" + ] + } + }, "Resources": { + "LayerWithCondition7c655e10ea": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "LayerWithCondition" + }, + "Condition": "TestCondition" + }, "MinimalLayer0c7f96cce7": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { - "LayerName": "MinimalLayer", "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - } + }, + "LayerName": "MinimalLayer" } - }, + }, "CompleteLayer5d71a60e81": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "MyAwesomeLayer", - "Description": "Starter Lambda Layer", + }, + "LayerName": "MyAwesomeLayer", + "Description": "Starter Lambda Layer", + "LicenseInfo": "License information", "CompatibleRuntimes": [ - "python3.6", + "python3.6", "python2.7" - ], - "LicenseInfo": "License information" + ] } - }, - "LayerWithContentUriObjectac002ba767": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Delete", + }, + "LayerWithContentUriObjectbdbf1b82ac": { + "DeletionPolicy": "Delete", + "Type": "AWS::Lambda::LayerVersion", "Properties": { - "LayerName": "LayerWithContentUriObject", "Content": { - "S3Bucket": "somebucket", - "S3Key": "somekey", - "S3ObjectVersion": 1 - } + "S3Bucket": "somebucket", + "S3Key": "somekey", + "S3ObjectVersion": "v1" + }, + "LayerName": "LayerWithContentUriObject" } - }, - "LayerWithCondition93cfa80b64": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "LayerWithCondition" - }, - "Condition": "this is a test" } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/depends_on.json b/tests/translator/output/aws-us-gov/depends_on.json index 3008eaeee..3c12f5852 100644 --- a/tests/translator/output/aws-us-gov/depends_on.json +++ b/tests/translator/output/aws-us-gov/depends_on.json @@ -74,8 +74,8 @@ } ], "ProvisionedThroughput": { - "WriteCapacityUnits": "5", - "ReadCapacityUnits": "5" + "WriteCapacityUnits": 5, + "ReadCapacityUnits": 5 } }, "DependsOn": "MySamTable" diff --git a/tests/translator/output/aws-us-gov/error_missing_queue.json b/tests/translator/output/aws-us-gov/error_missing_queue.json deleted file mode 100644 index f92bbf80e..000000000 --- a/tests/translator/output/aws-us-gov/error_missing_queue.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "errors": [{ - "errorMessage": "Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided." -} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/error_missing_stream.json b/tests/translator/output/aws-us-gov/error_missing_stream.json deleted file mode 100644 index d8925a773..000000000 --- a/tests/translator/output/aws-us-gov/error_missing_stream.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "errors": [{ - "errorMessage": "Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided." -} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/existing_event_logical_id.json b/tests/translator/output/aws-us-gov/existing_event_logical_id.json deleted file mode 100644 index 4715c2db3..000000000 --- a/tests/translator/output/aws-us-gov/existing_event_logical_id.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "errors": [ - { - "errorMessage": "Transforming resource with id [IoTRuleFunc] attempts to create a new resource with id [IoTRuleFuncMyIoTRule] and type \"AWS::IoT::TopicRule\". A resource with that id already exists within this template. Please use a different id for that resource." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [IoTRuleFunc] attempts to create a new resource with id [IoTRuleFuncMyIoTRule] and type \"AWS::IoT::TopicRule\". A resource with that id already exists within this template. Please use a different id for that resource.", -} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/existing_permission_logical_id.json b/tests/translator/output/aws-us-gov/existing_permission_logical_id.json deleted file mode 100644 index c41d0abd0..000000000 --- a/tests/translator/output/aws-us-gov/existing_permission_logical_id.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "errors": [ - { - "errorMessage": "Transforming resource with id [AlexaSkillFunc] attempts to create a new resource with id [AlexaSkillFuncAlexaSkillEventPermission] and type \"AWS::Lambda::Permission\". A resource with that id already exists within this template. Please use a different id for that resource." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [AlexaSkillFunc] attempts to create a new resource with id [AlexaSkillFuncAlexaSkillEventPermission] and type \"AWS::Lambda::Permission\". A resource with that id already exists within this template. Please use a different id for that resource." -} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/existing_role_logical_id.json b/tests/translator/output/aws-us-gov/existing_role_logical_id.json deleted file mode 100644 index b01da1048..000000000 --- a/tests/translator/output/aws-us-gov/existing_role_logical_id.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "errors": [ - { - "errorMessage": "Transforming resource with id [RestApiFunction] attempts to create a new resource with id [RestApiFunctionRole] and type \"AWS::IAM::Role\". A resource with that id already exists within this template. Please use a different id for that resource." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [RestApiFunction] attempts to create a new resource with id [RestApiFunctionRole] and type \"AWS::IAM::Role\". A resource with that id already exists within this template. Please use a different id for that resource." -} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/explicit_api.json b/tests/translator/output/aws-us-gov/explicit_api.json index 80f82c643..ef0a7a7d5 100644 --- a/tests/translator/output/aws-us-gov/explicit_api.json +++ b/tests/translator/output/aws-us-gov/explicit_api.json @@ -1,5 +1,9 @@ { "Parameters": { + "something": { + "Default": "something", + "Type": "String" + }, "MyStageName": { "Default": "Production", "Type": "String" @@ -9,11 +13,11 @@ "GetHtmlFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "webpage.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "GetHtmlFunctionRole", @@ -160,18 +164,18 @@ "GetHtmlApiStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "GetHtmlApi" + }, "Variables": { "EndpointUri": { "Ref": "something" }, "EndpointUri2": "http://example.com" }, - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, "StageName": { "Ref": "MyStageName" } diff --git a/tests/translator/output/aws-us-gov/function_managed_inline_policy.json b/tests/translator/output/aws-us-gov/function_managed_inline_policy.json index b46506bfb..57f79af68 100644 --- a/tests/translator/output/aws-us-gov/function_managed_inline_policy.json +++ b/tests/translator/output/aws-us-gov/function_managed_inline_policy.json @@ -1,13 +1,19 @@ { + "Parameters": { + "SomeManagedPolicyArn": { + "Default": "arn:aws:iam::aws:policy/OtherPolicy", + "Type": "String" + } + }, "Resources": { "Function": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionRole", @@ -27,11 +33,13 @@ "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - {"Ref": "SomeManagedPolicyArn"}, - "arn:aws:1234:iam:policy/CustomerCreatedManagedPolicy" + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaRole", + { + "Ref": "SomeManagedPolicyArn" + }, + "arn:aws:iam::123456789012:policy/CustomerCreatedManagedPolicy" ], "Policies": [ { diff --git a/tests/translator/output/aws-us-gov/function_with_alias_and_event_sources.json b/tests/translator/output/aws-us-gov/function_with_alias_and_event_sources.json index b556e3a2e..44be1d312 100644 --- a/tests/translator/output/aws-us-gov/function_with_alias_and_event_sources.json +++ b/tests/translator/output/aws-us-gov/function_with_alias_and_event_sources.json @@ -1,4 +1,10 @@ { + "Parameters": { + "MyStageName": { + "Default": "beta", + "Type": "String" + } + }, "Resources": { "MyAwesomeFunctionAliasLive": { "Type": "AWS::Lambda::Alias", @@ -320,11 +326,11 @@ "MyAwesomeFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyAwesomeFunctionRole", @@ -445,19 +451,16 @@ "GetHtmlApiStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { - "Variables": { - "LambdaFunction": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAliasLive", - "Arn" - ] - } + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" }, "RestApiId": { "Ref": "GetHtmlApi" }, - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" + "Variables": { + "LambdaFunction": { + "Ref": "MyAwesomeFunction" + } }, "StageName": { "Ref": "MyStageName" diff --git a/tests/translator/output/aws-us-gov/function_with_condition.json b/tests/translator/output/aws-us-gov/function_with_condition.json index 7f7c2858d..b6acc14f8 100644 --- a/tests/translator/output/aws-us-gov/function_with_condition.json +++ b/tests/translator/output/aws-us-gov/function_with_condition.json @@ -1,14 +1,21 @@ { + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + "test", + "test" + ] + } + }, "Resources": { "ConditionFunction": { "Type": "AWS::Lambda::Function", - "Condition": "this is a test", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "ConditionFunctionRole", @@ -22,11 +29,11 @@ "Key": "lambda:createdBy" } ] - } - }, + }, + "Condition": "TestCondition" + }, "ConditionFunctionRole": { "Type": "AWS::IAM::Role", - "Condition": "this is a test", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -47,7 +54,8 @@ } ] } - } + }, + "Condition": "TestCondition" } } } \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_and_custom_role.json b/tests/translator/output/aws-us-gov/function_with_deployment_and_custom_role.json index 9d5af98c6..802967b9a 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_and_custom_role.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_and_custom_role.json @@ -3,13 +3,16 @@ "FunctionWithRole": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { - "Ref": "DeploymentRole" + "Fn::GetAtt": [ + "DeploymentRole", + "Arn" + ] }, "Runtime": "python2.7", "Tags": [ @@ -23,11 +26,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", diff --git a/tests/translator/output/aws-us-gov/function_with_layers.json b/tests/translator/output/aws-us-gov/function_with_layers.json index 763b6670a..ecc80c5f7 100644 --- a/tests/translator/output/aws-us-gov/function_with_layers.json +++ b/tests/translator/output/aws-us-gov/function_with_layers.json @@ -1,19 +1,84 @@ { "Resources": { + "MinimalLayerFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalLayerFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + } + }, + "FunctionReferencesLayer": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Layers": [ + { + "Ref": "MyLayera5167acaba" + } + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionReferencesLayerRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, "MinimalLayerFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -23,194 +88,135 @@ ] } } - }, - "MinimalLayerFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalLayerFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ] - } - }, - "FunctionNoLayerVersionRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionReferencesLayerRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ] } } - }, - "FunctionNoLayerVersion": { - "Type": "AWS::Lambda::Function", + }, + "FunctionLayerWithSubIntrinsic": { + "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpXLayer:1" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpYLayer:1" + } + ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionNoLayerVersionRole", + "FunctionLayerWithSubIntrinsicRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7" + } + }, + "FunctionNoLayerVersion": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ] + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionNoLayerVersionRole", + "Arn" + ] + }, + "Runtime": "python2.7" } - }, - "FunctionLayerWithSubIntrinsicRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionNoLayerVersionRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ] } } - }, - "FunctionLayerWithSubIntrinsic": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionLayerWithSubIntrinsicRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Layers": [ - {"Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:CorpXLayer:1"}, - {"Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:CorpYLayer:1"} - ] - } - }, - "MyLayera5167acaba": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", - "Properties": { - "LayerName": "MyLayer", - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - } - } - }, - "FunctionReferencesLayerRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionLayerWithSubIntrinsicRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ] } } - }, - "FunctionReferencesLayer": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionReferencesLayerRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Layers": [ - { "Ref": "MyLayera5167acaba" } - ] - } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/function_with_many_layers.json b/tests/translator/output/aws-us-gov/function_with_many_layers.json index 4e2fbf402..f6c15275a 100644 --- a/tests/translator/output/aws-us-gov/function_with_many_layers.json +++ b/tests/translator/output/aws-us-gov/function_with_many_layers.json @@ -1,19 +1,30 @@ { "Resources": { + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + } + }, "ManyLayersFuncRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -23,46 +34,41 @@ ] } } - }, + }, "ManyLayersFunc": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:z:1", + { + "Fn::Sub": "arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1" + }, + "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1" + }, + { + "Ref": "MyLayera5167acaba" + } + ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ManyLayersFuncRole", - "Arn" - ] - }, - "Runtime": "python2.7", + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:z:1", - { "Fn::Sub": "arn:aws:lambda:${AWS:Region}:123456789101:layer:a:1" }, - "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:123456789101:layer:c:1" }, - { "Ref": "MyLayera5167acaba" } - ] - } - }, - "MyLayera5167acaba": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", - "Properties": { - "LayerName": "MyLayer", - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ManyLayersFuncRole", + "Arn" + ] + }, + "Runtime": "python2.7" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_resource_refs.json b/tests/translator/output/aws-us-gov/function_with_resource_refs.json index 2d72088bd..ab8c74611 100644 --- a/tests/translator/output/aws-us-gov/function_with_resource_refs.json +++ b/tests/translator/output/aws-us-gov/function_with_resource_refs.json @@ -1,50 +1,64 @@ { "Outputs": { "AliasArn": { - "Ref": "MinimalFunctionAliaslive" + "Value": { + "Ref": "MinimalFunctionAliaslive" + } }, "VersionArn": { - "Ref": "MinimalFunctionVersion640128d35d" + "Value": { + "Ref": "MinimalFunctionVersion640128d35d" + } }, "VersionNumber": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] + "Value": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + } }, "AliasName": { - "Fn::GetAtt": [ - "MinimalFunctionAliaslive", - "Name" - ] + "Value": { + "Fn::GetAtt": [ + "MinimalFunctionAliaslive", + "Name" + ] + } }, "UnResolvedVersion": { - "Ref": "FunctionWithoutAlias.Version" + "Value": { + "Ref": "FunctionWithoutAlias.Version" + } }, "AliasInSub": { - "Fn::Sub": [ - "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", - { - "SomeValue": "World" - } - ] + "Value": { + "Fn::Sub": [ + "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", + { + "SomeValue": "World" + } + ] + } }, "MustNotResolve": { - "Fn::GetAtt": [ - "FunctionWithoutAlias", - "Alias.Name" - ] + "Value": { + "Fn::GetAtt": [ + "FunctionWithoutAlias", + "Alias.Name" + ] + } } }, "Resources": { "FunctionWithoutAlias": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionWithoutAliasRole", @@ -87,11 +101,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", diff --git a/tests/translator/output/aws-us-gov/globals_for_api.json b/tests/translator/output/aws-us-gov/globals_for_api.json index d03debdac..138c62aed 100644 --- a/tests/translator/output/aws-us-gov/globals_for_api.json +++ b/tests/translator/output/aws-us-gov/globals_for_api.json @@ -3,11 +3,11 @@ "ImplicitApiFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -68,77 +68,56 @@ } } }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "Prod", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, "ExplicitApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/": { "get": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {}, + }, "security": [ { "MyCognitoAuth": [] } - ] + ], + "responses": {} } } - }, - "swagger": 2.0, + }, + "swagger": 2.0, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" @@ -150,14 +129,21 @@ } } }, - "ServerlessRestApiDeploymentc969c99f9d": { - "Type": "AWS::ApiGateway::Deployment", + "ServerlessRestApiProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { "RestApiId": { "Ref": "ServerlessRestApi" }, - "Description": "RestApi deployment id: c969c99f9d6b6921dff605a206e8989bdb7d1bc7", - "StageName": "Stage" + "StageName": "Prod", + "CacheClusterSize": "1.6", + "Variables": { + "SomeVar": "Value" + }, + "CacheClusterEnabled": true, + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentc969c99f9d" + } } }, "ExplicitApiSomeStageStage": { @@ -177,21 +163,66 @@ } } }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "ServerlessRestApiDeploymentc969c99f9d": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "ServerlessRestApi" }, - "StageName": "Prod", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" + "Description": "RestApi deployment id: c969c99f9d6b6921dff605a206e8989bdb7d1bc7", + "StageName": "Stage" + } + }, + "ExplicitApiDeploymentd5fa0145e9": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentc969c99f9d" - } + "Description": "RestApi deployment id: d5fa0145e9e6393911d32967e66fd7091d605483", + "StageName": "Stage" + } + }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", + "Properties": { + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] } }, "ServerlessRestApi": { @@ -214,36 +245,36 @@ "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } }, - "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] + ], + "responses": {} } } }, - "swagger": "2.0", + "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" @@ -254,16 +285,6 @@ "endpointConfigurationTypes": "REGIONAL" } } - }, - "ExplicitApiDeploymentd5fa0145e9": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: d5fa0145e9e6393911d32967e66fd7091d605483", - "StageName": "Stage" - } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/globals_for_function.json b/tests/translator/output/aws-us-gov/globals_for_function.json index bd87cc916..e087c7180 100644 --- a/tests/translator/output/aws-us-gov/globals_for_function.json +++ b/tests/translator/output/aws-us-gov/globals_for_function.json @@ -7,7 +7,7 @@ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/AWSXrayWriteOnlyAccess" ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", + "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -29,6 +29,14 @@ "FunctionWithOverrides": { "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2" + } + ], "TracingConfig": { "Mode": "PassThrough" }, @@ -37,6 +45,9 @@ "S3Key": "hello.zip" }, "VpcConfig": { + "SubnetIds": [ + "sub-id-2" + ], "SecurityGroupIds": [ "sg-edcd9784", "sg-123" @@ -56,8 +67,8 @@ "Key": "tag1" } ], - "MemorySize": 512, "ReservedConcurrentExecutions": 100, + "MemorySize": 512, "Environment": { "Variables": { "Var1": "value1", @@ -73,11 +84,7 @@ ] }, "Timeout": 100, - "Runtime": "nodejs4.3", - "Layers": [ - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer:1" }, - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer2:2" } - ] + "Runtime": "nodejs4.3" } }, "MinimalFunctionRole": { @@ -87,7 +94,7 @@ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/AWSXrayWriteOnlyAccess" ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -124,6 +131,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" + } + ], "TracingConfig": { "Mode": "Active" }, @@ -132,6 +144,9 @@ "S3Key": "global.zip" }, "VpcConfig": { + "SubnetIds": [ + "sub-id-2" + ], "SecurityGroupIds": [ "sg-edcd9784" ] @@ -146,8 +161,8 @@ "Key": "tag1" } ], - "MemorySize": 1024, "ReservedConcurrentExecutions": 50, + "MemorySize": 1024, "Environment": { "Variables": { "Var1": "value1", @@ -162,10 +177,7 @@ ] }, "Timeout": 30, - "Runtime": "python2.7", - "Layers": [ - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer:1" } - ] + "Runtime": "python2.7" } }, "MinimalFunctionAliaslive": { @@ -202,4 +214,4 @@ } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/intrinsic_functions.json b/tests/translator/output/aws-us-gov/intrinsic_functions.json index 2debe1a6d..70b728c09 100644 --- a/tests/translator/output/aws-us-gov/intrinsic_functions.json +++ b/tests/translator/output/aws-us-gov/intrinsic_functions.json @@ -1,5 +1,17 @@ { + "Conditions": { + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, "Parameters": { + "CodeKey": { + "Default": "key", + "Type": "String" + }, "CodeBucket": { "Default": "sam-demo-bucket", "Type": "String" @@ -16,16 +28,183 @@ "Default": "PassThrough", "Type": "String" } - }, - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - } - }, + }, "Resources": { + "MyExplicitApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "swagger.yaml" + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + }, + "Name": { + "Ref": "MyExplicitApiName" + } + } + }, + "MyTable": { + "Type": "AWS::DynamoDB::Table", + "Properties": { + "KeySchema": [ + { + "KeyType": "HASH", + "AttributeName": "id" + } + ], + "StreamSpecification": { + "StreamViewType": "NEW_IMAGE" + }, + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "ProvisionedThroughput": { + "WriteCapacityUnits": 5, + "ReadCapacityUnits": 5 + } + } + }, + "SnsDlqQueue": { + "Type": "AWS::SNS::Topic" + }, + "MySqsDlqLambdaFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "DeadLetterConfig": { + "TargetArn": { + "Fn::GetAtt": [ + "SqsDlqQueue", + "Arn" + ] + } + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MySqsDlqLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, + "SqsDlqQueue": { + "Type": "AWS::SQS::Queue" + }, + "ApiWithExplicitS3Uri": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "BodyS3Location": { + "Version": "myversion", + "Bucket": "mybucket", + "Key": "mykey" + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Condition": "TrueCondition" + }, + "MyExplicitApiDeployment31ec20c228": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "Description": "RestApi deployment id: 31ec20c2288b273d15235777b0b90f3c0e2f9d52", + "StageName": "Stage" + } + }, + "FunctionWithExplicitS3Uri": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "stream.ddb_handler", + "Code": { + "S3Bucket": "mybucket", + "S3Key": "mykey", + "S3ObjectVersion": "MyVersion" + }, + "Role": { + "Fn::GetAtt": [ + "FunctionWithExplicitS3UriRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MySnsDlqLambdaFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Policies": [ + { + "PolicyName": "DeadLetterQueuePolicy", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sns:Publish", + "Resource": { + "Ref": "SnsDlqQueue" + }, + "Effect": "Allow" + } + ] + } + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "MyFunction": { "Type": "AWS::Lambda::Function", "Properties": { @@ -39,9 +218,7 @@ "Ref": "CodeBucket" }, "S3Key": { - "Fn::Sub": [ - "code.zip" - ] + "Fn::Sub": "code.zip.${CodeKey}" }, "S3ObjectVersion": { "Fn::Join": [ @@ -111,19 +288,6 @@ } } }, - "ApiWithExplicitS3UridevStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "TrueCondition", - "Properties": { - "DeploymentId": { - "Ref": "ApiWithExplicitS3UriDeploymenta227798f00" - }, - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" - }, - "StageName": "dev" - } - }, "DynamoDBFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { @@ -158,10 +322,7 @@ }, "DeadLetterConfig": { "TargetArn": { - "Fn::GetAtt": [ - "SnsDlqQueue", - "Arn" - ] + "Ref": "SnsDlqQueue" } }, "Tags": [ @@ -180,37 +341,6 @@ "Runtime": "python2.7" } }, - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "swagger.yaml" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "Name": { - "Ref": "MyExplicitApiName" - } - } - }, - "ApiWithExplicitS3UriDeploymenta227798f00": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "TrueCondition", - "Properties": { - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" - }, - "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", - "StageName": "Stage" - } - }, "MyFunctionMyApiPermissionTest": { "Type": "AWS::Lambda::Permission", "Properties": { @@ -232,41 +362,53 @@ } } }, - "MyTable": { - "Type": "AWS::DynamoDB::Table", + "MyNewRole": { + "Type": "AWS::IAM::Role", "Properties": { - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ + "Policies": [ { - "AttributeName": "id", - "AttributeType": "S" + "PolicyName": "lambdaRole", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "cloudwatch:*", + "logs:*" + ], + "Resource": "*", + "Effect": "Allow" + } + ] + } } ], - "ProvisionedThroughput": { - "WriteCapacityUnits": "5", - "ReadCapacityUnits": "5" + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] } } }, - "SnsDlqQueue": { - "Type": "AWS::SNS::Topic" - }, "DynamoDBFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "stream.ddb_handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "streams.zip" }, - "Handler": "stream.ddb_handler", "Role": { "Fn::GetAtt": [ "DynamoDBFunctionRole", @@ -282,62 +424,18 @@ ] } }, - "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "DeadLetterConfig": { - "TargetArn": { - "Fn::GetAtt": [ - "SqsDlqQueue", - "Arn" - ] - } - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MySqsDlqLambdaFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "MyExplicitApidevStage": { + "ApiWithExplicitS3UridevStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { - "Variables": { - "FunctionName": { - "Fn::Sub": "${MyFunction}" - }, - "Var2": { - "Fn::Join": [ - "join ", - [ - "some value ", - "with some other value" - ] - ] - } + "DeploymentId": { + "Ref": "ApiWithExplicitS3UriDeploymenta227798f00" }, "RestApiId": { - "Ref": "MyExplicitApi" - }, - "DeploymentId": { - "Ref": "MyExplicitApiDeployment31ec20c228" + "Ref": "ApiWithExplicitS3Uri" }, "StageName": "dev" - } + }, + "Condition": "TrueCondition" }, "DynamoDBFunctionMyDDBStream": { "Type": "AWS::Lambda::EventSourceMapping", @@ -355,37 +453,16 @@ "StartingPosition": "LATEST" } }, - "SqsDlqQueue": { - "Type": "AWS::SQS::Queue" - }, - "MyExplicitApiDeployment31ec20c228": { + "ApiWithExplicitS3UriDeploymenta227798f00": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { - "Ref": "MyExplicitApi" + "Ref": "ApiWithExplicitS3Uri" }, - "Description": "RestApi deployment id: 31ec20c2288b273d15235777b0b90f3c0e2f9d52", + "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", "StageName": "Stage" - } - }, - "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", - "Condition": "TrueCondition", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Version": "myversion", - "Bucket": "mybucket", - "Key": "mykey" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + }, + "Condition": "TrueCondition" }, "MySqsDlqLambdaFunctionRole": { "Type": "AWS::IAM::Role", @@ -431,72 +508,30 @@ } } }, - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ - { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": { - "Fn::GetAtt": [ - "SnsDlqQueue", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", + "MyExplicitApidevStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { - "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", - "S3ObjectVersion": "MyVersion" + "DeploymentId": { + "Ref": "MyExplicitApiDeployment31ec20c228" }, - "Handler": "stream.ddb_handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", - "Arn" - ] + "RestApiId": { + "Ref": "MyExplicitApi" }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Variables": { + "FunctionName": { + "Fn::Sub": "${MyFunction}" + }, + "Var2": { + "Fn::Join": [ + "join ", + [ + "some value ", + "with some other value" + ] + ] } - ] + }, + "StageName": "dev" } }, "MyFunctionMyApiPermissiondev": { diff --git a/tests/translator/output/aws-us-gov/layers_all_properties.json b/tests/translator/output/aws-us-gov/layers_all_properties.json index a6455d6cb..0a625c83a 100644 --- a/tests/translator/output/aws-us-gov/layers_all_properties.json +++ b/tests/translator/output/aws-us-gov/layers_all_properties.json @@ -1,50 +1,105 @@ { + "Outputs": { + "LayerSub": { + "Value": { + "Fn::Sub": "${MyLayerd04062b365}" + } + }, + "FunctionAtt": { + "Value": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + }, + "LayerName": { + "Value": { + "Ref": "MyLayerd04062b365" + } + }, + "FunctionSub": { + "Value": { + "Fn::Sub": "${MyFunction}" + } + }, + "FunctionName": { + "Value": { + "Ref": "MyFunction" + } + } + }, "Parameters": { "LayerDeleteParam": { "Default": "Delete", "Type": "String" } - }, + }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Ref": "MyLayerd04062b365" + } + ], "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, - "Handler": "app.handler", + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "app.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python3.6", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], - "Layers": [ - { - "Ref": "MyLayerd04062b365" - } - ] + }, + "Runtime": "python3.6" + } + }, + "MyLayerd04062b365": { + "DeletionPolicy": "Delete", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "MyLayer" } - }, + }, + "MyLayerWithANamefda8c9ec8c": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "DifferentLayerName" + } + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -52,71 +107,8 @@ } } ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ] - } - }, - "MyLayerd04062b365": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Delete", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "MyLayer" - } - }, - "MyLayerWithANamefda8c9ec8c": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "DifferentLayerName" - } - } - }, - "Outputs": { - "LayerName": { - "Value": { - "Ref": "MyLayerd04062b365" - } - }, - "FunctionName": { - "Value": { - "Ref": "MyFunction" - } - }, - "LayerAtt": { - "Value": { - "Fn::GetAtt": [ - "MyLayerd04062b365", - "Arn" - ] - } - }, - "FunctionAtt": { - "Value": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - } - }, - "LayerSub": { - "Value": { - "Fn::Sub": "${MyLayerd04062b365}" - } - }, - "FunctionSub": { - "Value": { - "Fn::Sub": "${MyFunction}" + } } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/no_implicit_api_with_serverless_rest_api_resource.json b/tests/translator/output/aws-us-gov/no_implicit_api_with_serverless_rest_api_resource.json index b2fade6f0..ffbb87e6b 100644 --- a/tests/translator/output/aws-us-gov/no_implicit_api_with_serverless_rest_api_resource.json +++ b/tests/translator/output/aws-us-gov/no_implicit_api_with_serverless_rest_api_resource.json @@ -1,25 +1,29 @@ { "Resources": { - "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "GetHtmlFunction": { + "Type": "AWS::Lambda::Function", "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" ] - } + }, + "Runtime": "python3.6", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] } - }, - "ThumbnailFunctionRole": { + }, + "GetHtmlFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ @@ -56,14 +60,106 @@ "Principal": "s3.amazonaws.com" } }, + "RestApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "RestApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.6", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ThumbnailFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "Images": { + "Type": "AWS::S3::Bucket", + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + }, + "Event": "s3:ObjectCreated:*" + } + ] + } + }, + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ] + }, "ThumbnailFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.generate_thumbails", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ "ThumbnailFunctionRole", diff --git a/tests/translator/output/aws-us-gov/s3_existing_other_notification_configuration.json b/tests/translator/output/aws-us-gov/s3_existing_other_notification_configuration.json index ea48df6f2..b0f782d57 100644 --- a/tests/translator/output/aws-us-gov/s3_existing_other_notification_configuration.json +++ b/tests/translator/output/aws-us-gov/s3_existing_other_notification_configuration.json @@ -1,8 +1,7 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "Type": "AWS::S3::Bucket", "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ @@ -18,11 +17,15 @@ ], "TopicConfigurations": [ { - "Topic": "my-super-awesome-topic" + "Topic": "my-super-awesome-topic", + "Event": "s3:ObjectRemoved:*" } ] } - } + }, + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ] }, "ThumbnailFunctionRole": { "Type": "AWS::IAM::Role", @@ -64,11 +67,11 @@ "ThumbnailFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.generate_thumbails", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ "ThumbnailFunctionRole", diff --git a/tests/translator/output/aws-us-gov/s3_with_condition.json b/tests/translator/output/aws-us-gov/s3_with_condition.json index 8eddaf870..1604f0aff 100644 --- a/tests/translator/output/aws-us-gov/s3_with_condition.json +++ b/tests/translator/output/aws-us-gov/s3_with_condition.json @@ -1,48 +1,55 @@ { + "Conditions": { + "MyCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, "Resources": { "Images": { - "Type": "AWS::S3::Bucket", + "Type": "AWS::S3::Bucket", "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { "Fn::If": [ - "MyCondition", + "MyCondition", { "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, + }, "Event": "s3:ObjectCreated:*" - }, + }, { "Ref": "AWS::NoValue" } ] } ] - }, + }, "Tags": [ { "Value": { "Fn::If": [ - "MyCondition", + "MyCondition", { "Ref": "ThumbnailFunctionImageBucketPermission" - }, + }, "no dependency" ] - }, + }, "Key": "sam:ConditionalDependsOn:ThumbnailFunctionImageBucketPermission" } - ] + ] } }, "ThumbnailFunctionRole": { "Type": "AWS::IAM::Role", - "Condition": "MyCondition", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -63,11 +70,11 @@ } ] } - } + }, + "Condition": "MyCondition" }, "ThumbnailFunctionImageBucketPermission": { "Type": "AWS::Lambda::Permission", - "Condition": "MyCondition", "Properties": { "Action": "lambda:invokeFunction", "SourceAccount": { @@ -77,17 +84,17 @@ "Ref": "ThumbnailFunction" }, "Principal": "s3.amazonaws.com" - } + }, + "Condition": "MyCondition" }, "ThumbnailFunction": { "Type": "AWS::Lambda::Function", - "Condition": "MyCondition", "Properties": { + "Handler": "index.generate_thumbails", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ "ThumbnailFunctionRole", @@ -101,7 +108,8 @@ "Key": "lambda:createdBy" } ] - } + }, + "Condition": "MyCondition" } } } \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/simple_table_ref_parameter_intrinsic.json b/tests/translator/output/aws-us-gov/simple_table_ref_parameter_intrinsic.json index 667ce5351..e9a652d3b 100644 --- a/tests/translator/output/aws-us-gov/simple_table_ref_parameter_intrinsic.json +++ b/tests/translator/output/aws-us-gov/simple_table_ref_parameter_intrinsic.json @@ -1,4 +1,18 @@ { + "Parameters": { + "ReadCapacity": { + "Default": 15, + "Type": "Number" + }, + "WriteCapacity": { + "Default": 15, + "Type": "Number" + }, + "EnableSSE": { + "Default": true, + "Type": "String" + } + }, "Resources": { "MinimalTableRefParamLongForm": { "Type": "AWS::DynamoDB::Table", diff --git a/tests/translator/output/aws-us-gov/simple_table_with_extra_tags.json b/tests/translator/output/aws-us-gov/simple_table_with_extra_tags.json index 23d2f3fb6..a02e088cd 100644 --- a/tests/translator/output/aws-us-gov/simple_table_with_extra_tags.json +++ b/tests/translator/output/aws-us-gov/simple_table_with_extra_tags.json @@ -1,4 +1,10 @@ { + "Parameters": { + "TagValueParam": { + "Default": "value", + "Type": "String" + } + }, "Resources": { "MinimalTableWithTags": { "Type": "AWS::DynamoDB::Table", @@ -32,7 +38,7 @@ "Key": "TagKey3" }, { - "Value": 123, + "Value": "123", "Key": "TagKey4" } ] diff --git a/tests/translator/output/aws-us-gov/simple_table_with_table_name.json b/tests/translator/output/aws-us-gov/simple_table_with_table_name.json index 215960a56..57b9ef7a8 100644 --- a/tests/translator/output/aws-us-gov/simple_table_with_table_name.json +++ b/tests/translator/output/aws-us-gov/simple_table_with_table_name.json @@ -1,4 +1,10 @@ { + "Parameters": { + "MySimpleTableParameter": { + "Default": "TableName", + "Type": "String" + } + }, "Resources": { "MinimalTableWithTableName": { "Type": "AWS::DynamoDB::Table", diff --git a/tests/translator/output/basic_application.json b/tests/translator/output/basic_application.json index e2056aaca..058e8037e 100644 --- a/tests/translator/output/basic_application.json +++ b/tests/translator/output/basic_application.json @@ -1,94 +1,100 @@ { + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, "Resources": { - "BasicApplication": { - "Type": "AWS::CloudFormation::Stack", + "NormalApplication": { + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "NotificationARNs": [ + "arn:aws:sns:us-east-1:123456789012:sns-arn" + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TimeoutInMinutes": 15, + "Parameters": { + "IdentityNameParameter": "IdentityName" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", "Key": "serverlessrepo:applicationId" - }, + }, { - "Value": "1.0.2", + "Value": "1.0.2", "Key": "serverlessrepo:semanticVersion" + }, + { + "Value": "TagValue", + "Key": "TagName" } ] } - }, - "NormalApplication": { - "Type": "AWS::CloudFormation::Stack", + }, + "BasicApplication": { + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", "Key": "serverlessrepo:applicationId" - }, + }, { - "Value": "1.0.2", + "Value": "1.0.2", "Key": "serverlessrepo:semanticVersion" - }, - { - "Value": "TagValue", - "Key": "TagName" } - ], - "Parameters": - { - "IdentityNameParameter": "IdentityName" - }, - "NotificationArns": - [ - "arn:aws:sns:us-east-1:123456789012:sns-arn" - ], - "TimeoutInMinutes": 15 + ] } - }, + }, "ApplicationWithLocationUrl": { - "Type": "AWS::CloudFormation::Stack", + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml", + "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "TagValue2", + "Value": "TagValue2", "Key": "TagName2" } ] } - }, + }, "ApplicationWithCondition": { - "Type": "AWS::CloudFormation::Stack", + "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" - }, + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", "Key": "serverlessrepo:applicationId" - }, + }, { - "Value": "1.0.2", + "Value": "1.0.2", "Key": "serverlessrepo:semanticVersion" } ] - }, - "Condition": "this is a test" + }, + "Condition": "TestCondition" } } -} +} \ No newline at end of file diff --git a/tests/translator/output/basic_function.json b/tests/translator/output/basic_function.json index f3987a813..c1bd1e19c 100644 --- a/tests/translator/output/basic_function.json +++ b/tests/translator/output/basic_function.json @@ -1,56 +1,40 @@ { + "Parameters": { + "SomeParameter": { + "Default": "param", + "Type": "String" + }, + "SomeOtherParameter": { + "Default": "otherparam", + "Type": "String" + } + }, "Resources": { - "FunctionWithTracingRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "FunctionWithTracing": { - "Type": "AWS::Lambda::Function", + "FunctionWithInlineCode": { + "Type": "AWS::Lambda::Function", "Properties": { + "TracingConfig": { + "Mode": "Active" + }, "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithTracingRole", - "Arn" - ] - }, - "Runtime": "python2.7", + "ZipFile": "hello world" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "TracingConfig": { - "Mode": "Active" - } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithInlineCodeRole", + "Arn" + ] + }, + "Runtime": "python2.7" } - }, + }, "MinimalFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { @@ -78,11 +62,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", @@ -101,11 +85,11 @@ "FunctionWithPolicyDocument": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionWithPolicyDocumentRole", @@ -124,11 +108,11 @@ "FunctionWithPolicies": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionWithPoliciesRole", @@ -209,16 +193,14 @@ "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "FunctionName": "MyAwesomeFunction", + "Description": "Starter Lambda Function", "VpcConfig": { "SubnetIds": [ "subnet-9d4a7b6c", - "subnet-65ea5f08" - ], - "SubnetIdsUsingRef": [ + "subnet-65ea5f08", { "Ref": "SomeParameter" }, @@ -246,18 +228,18 @@ "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", "Timeout": 60, "Runtime": "python2.7", - "Description": "Starter Lambda Function" + "FunctionName": "MyAwesomeFunction" } }, "FunctionWithCodeUriObject": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "somebucket", "S3Key": "somekey", - "S3ObjectVersion": 1 + "S3ObjectVersion": "1" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionWithCodeUriObjectRole", @@ -277,8 +259,58 @@ "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess", - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "FunctionWithInlineCodeRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "FunctionWithTracingRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" ], "AssumeRolePolicyDocument": { "Version": "2012-10-17", @@ -301,11 +333,11 @@ "FunctionWithRoleRef": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyFunctionRole", @@ -321,6 +353,32 @@ ] } }, + "FunctionWithTracing": { + "Type": "AWS::Lambda::Function", + "Properties": { + "TracingConfig": { + "Mode": "Active" + }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithTracingRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, "FunctionWithPolicyDocumentRole": { "Type": "AWS::IAM::Role", "Properties": { @@ -360,56 +418,6 @@ ] } } - }, - "FunctionWithInlineCodeRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "FunctionWithInlineCode": { - "Type": "AWS::Lambda::Function", - "Properties": { - "TracingConfig": { - "Mode": "Active" - }, - "Code": { - "ZipFile": "hello world" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithInlineCodeRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/basic_function_with_tags.json b/tests/translator/output/basic_function_with_tags.json index 2a05f7b4d..dffbcbb81 100644 --- a/tests/translator/output/basic_function_with_tags.json +++ b/tests/translator/output/basic_function_with_tags.json @@ -69,7 +69,7 @@ "Key": "TagKey3" }, { - "Value": 123, + "Value": "123", "Key": "TagKey4" } ], diff --git a/tests/translator/output/basic_layer.json b/tests/translator/output/basic_layer.json index 0b0a67400..d373bd19c 100644 --- a/tests/translator/output/basic_layer.json +++ b/tests/translator/output/basic_layer.json @@ -1,56 +1,64 @@ { + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + "beta", + "beta" + ] + } + }, "Resources": { + "LayerWithCondition7c655e10ea": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "LayerWithCondition" + }, + "Condition": "TestCondition" + }, "MinimalLayer0c7f96cce7": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { - "LayerName": "MinimalLayer", "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - } + }, + "LayerName": "MinimalLayer" } - }, + }, "CompleteLayer5d71a60e81": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "MyAwesomeLayer", - "Description": "Starter Lambda Layer", + }, + "LayerName": "MyAwesomeLayer", + "Description": "Starter Lambda Layer", + "LicenseInfo": "License information", "CompatibleRuntimes": [ - "python3.6", + "python3.6", "python2.7" - ], - "LicenseInfo": "License information" + ] } - }, - "LayerWithContentUriObjectac002ba767": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Delete", + }, + "LayerWithContentUriObjectbdbf1b82ac": { + "DeletionPolicy": "Delete", + "Type": "AWS::Lambda::LayerVersion", "Properties": { - "LayerName": "LayerWithContentUriObject", "Content": { - "S3Bucket": "somebucket", - "S3Key": "somekey", - "S3ObjectVersion": 1 - } + "S3Bucket": "somebucket", + "S3Key": "somekey", + "S3ObjectVersion": "v1" + }, + "LayerName": "LayerWithContentUriObject" } - }, - "LayerWithCondition93cfa80b64": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "LayerWithCondition" - }, - "Condition": "this is a test" } } -} +} \ No newline at end of file diff --git a/tests/translator/output/depends_on.json b/tests/translator/output/depends_on.json index ea248c690..54eb10dd9 100644 --- a/tests/translator/output/depends_on.json +++ b/tests/translator/output/depends_on.json @@ -66,8 +66,8 @@ } ], "ProvisionedThroughput": { - "WriteCapacityUnits": "5", - "ReadCapacityUnits": "5" + "WriteCapacityUnits": 5, + "ReadCapacityUnits": 5 } }, "DependsOn": "MySamTable" diff --git a/tests/translator/output/explicit_api.json b/tests/translator/output/explicit_api.json index 5e04eb852..db2d9479b 100644 --- a/tests/translator/output/explicit_api.json +++ b/tests/translator/output/explicit_api.json @@ -1,5 +1,9 @@ { "Parameters": { + "something": { + "Default": "something", + "Type": "String" + }, "MyStageName": { "Default": "Production", "Type": "String" @@ -9,11 +13,11 @@ "GetHtmlFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "webpage.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "GetHtmlFunctionRole", @@ -144,18 +148,18 @@ "GetHtmlApiStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "GetHtmlApi" + }, "Variables": { "EndpointUri": { "Ref": "something" }, "EndpointUri2": "http://example.com" }, - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, "StageName": { "Ref": "MyStageName" } diff --git a/tests/translator/output/function_managed_inline_policy.json b/tests/translator/output/function_managed_inline_policy.json index a1a9c468c..15911c5b7 100644 --- a/tests/translator/output/function_managed_inline_policy.json +++ b/tests/translator/output/function_managed_inline_policy.json @@ -1,13 +1,19 @@ { + "Parameters": { + "SomeManagedPolicyArn": { + "Default": "arn:aws:iam::aws:policy/OtherPolicy", + "Type": "String" + } + }, "Resources": { "Function": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionRole", @@ -27,11 +33,13 @@ "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess", - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - {"Ref": "SomeManagedPolicyArn"}, - "arn:aws:1234:iam:policy/CustomerCreatedManagedPolicy" + "arn:aws:iam::aws:policy/service-role/AWSLambdaRole", + { + "Ref": "SomeManagedPolicyArn" + }, + "arn:aws:iam::123456789012:policy/CustomerCreatedManagedPolicy" ], "Policies": [ { diff --git a/tests/translator/output/function_with_alias_and_event_sources.json b/tests/translator/output/function_with_alias_and_event_sources.json index 603f9f7c9..2e6f8e194 100644 --- a/tests/translator/output/function_with_alias_and_event_sources.json +++ b/tests/translator/output/function_with_alias_and_event_sources.json @@ -1,4 +1,10 @@ { + "Parameters": { + "MyStageName": { + "Default": "beta", + "Type": "String" + } + }, "Resources": { "MyAwesomeFunctionAliasLive": { "Type": "AWS::Lambda::Alias", @@ -312,11 +318,11 @@ "MyAwesomeFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyAwesomeFunctionRole", @@ -429,19 +435,16 @@ "GetHtmlApiStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { - "Variables": { - "LambdaFunction": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAliasLive", - "Arn" - ] - } + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" }, "RestApiId": { "Ref": "GetHtmlApi" }, - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" + "Variables": { + "LambdaFunction": { + "Ref": "MyAwesomeFunction" + } }, "StageName": { "Ref": "MyStageName" diff --git a/tests/translator/output/function_with_condition.json b/tests/translator/output/function_with_condition.json index e20488c63..a73a16074 100644 --- a/tests/translator/output/function_with_condition.json +++ b/tests/translator/output/function_with_condition.json @@ -1,14 +1,21 @@ { + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + "test", + "test" + ] + } + }, "Resources": { "ConditionFunction": { "Type": "AWS::Lambda::Function", - "Condition": "this is a test", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "ConditionFunctionRole", @@ -22,11 +29,11 @@ "Key": "lambda:createdBy" } ] - } - }, + }, + "Condition": "TestCondition" + }, "ConditionFunctionRole": { "Type": "AWS::IAM::Role", - "Condition": "this is a test", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -47,7 +54,8 @@ } ] } - } + }, + "Condition": "TestCondition" } } } \ No newline at end of file diff --git a/tests/translator/output/function_with_deployment_and_custom_role.json b/tests/translator/output/function_with_deployment_and_custom_role.json index 32792b4c7..7a2dd87c9 100644 --- a/tests/translator/output/function_with_deployment_and_custom_role.json +++ b/tests/translator/output/function_with_deployment_and_custom_role.json @@ -3,13 +3,16 @@ "FunctionWithRole": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { - "Ref": "DeploymentRole" + "Fn::GetAtt": [ + "DeploymentRole", + "Arn" + ] }, "Runtime": "python2.7", "Tags": [ @@ -23,11 +26,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", diff --git a/tests/translator/output/function_with_layers.json b/tests/translator/output/function_with_layers.json index 07c058dff..a6b6e357a 100644 --- a/tests/translator/output/function_with_layers.json +++ b/tests/translator/output/function_with_layers.json @@ -1,19 +1,84 @@ { "Resources": { + "MinimalLayerFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalLayerFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + } + }, + "FunctionReferencesLayer": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Layers": [ + { + "Ref": "MyLayera5167acaba" + } + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionReferencesLayerRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, "MinimalLayerFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -23,194 +88,135 @@ ] } } - }, - "MinimalLayerFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalLayerFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ] - } - }, - "FunctionNoLayerVersionRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionReferencesLayerRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ] } } - }, - "FunctionNoLayerVersion": { - "Type": "AWS::Lambda::Function", + }, + "FunctionLayerWithSubIntrinsic": { + "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpXLayer:1" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpYLayer:1" + } + ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionNoLayerVersionRole", + "FunctionLayerWithSubIntrinsicRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7" + } + }, + "FunctionNoLayerVersion": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ] + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionNoLayerVersionRole", + "Arn" + ] + }, + "Runtime": "python2.7" } - }, - "FunctionLayerWithSubIntrinsicRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionNoLayerVersionRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ] } } - }, - "FunctionLayerWithSubIntrinsic": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionLayerWithSubIntrinsicRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Layers": [ - {"Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:CorpXLayer:1"}, - {"Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:CorpYLayer:1"} - ] - } - }, - "MyLayera5167acaba": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", - "Properties": { - "LayerName": "MyLayer", - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - } - } - }, - "FunctionReferencesLayerRole": { - "Type": "AWS::IAM::Role", + }, + "FunctionLayerWithSubIntrinsicRole": { + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ] } } - }, - "FunctionReferencesLayer": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionReferencesLayerRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Layers": [ - { "Ref": "MyLayera5167acaba" } - ] - } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/function_with_many_layers.json b/tests/translator/output/function_with_many_layers.json index c760894e2..885be8351 100644 --- a/tests/translator/output/function_with_many_layers.json +++ b/tests/translator/output/function_with_many_layers.json @@ -1,19 +1,30 @@ { "Resources": { + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + } + }, "ManyLayersFuncRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -23,46 +34,41 @@ ] } } - }, + }, "ManyLayersFunc": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:z:1", + { + "Fn::Sub": "arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1" + }, + "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1" + }, + { + "Ref": "MyLayera5167acaba" + } + ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ManyLayersFuncRole", - "Arn" - ] - }, - "Runtime": "python2.7", + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:z:1", - { "Fn::Sub": "arn:aws:lambda:${AWS:Region}:123456789101:layer:a:1" }, - "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:123456789101:layer:c:1" }, - { "Ref": "MyLayera5167acaba" } - ] - } - }, - "MyLayera5167acaba": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", - "Properties": { - "LayerName": "MyLayer", - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - } + ], + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ManyLayersFuncRole", + "Arn" + ] + }, + "Runtime": "python2.7" } } } diff --git a/tests/translator/output/function_with_resource_refs.json b/tests/translator/output/function_with_resource_refs.json index 7903b5b7d..e583d2819 100644 --- a/tests/translator/output/function_with_resource_refs.json +++ b/tests/translator/output/function_with_resource_refs.json @@ -1,50 +1,64 @@ { "Outputs": { "AliasArn": { - "Ref": "MinimalFunctionAliaslive" + "Value": { + "Ref": "MinimalFunctionAliaslive" + } }, "VersionArn": { - "Ref": "MinimalFunctionVersion640128d35d" + "Value": { + "Ref": "MinimalFunctionVersion640128d35d" + } }, "VersionNumber": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] + "Value": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + } }, "AliasName": { - "Fn::GetAtt": [ - "MinimalFunctionAliaslive", - "Name" - ] + "Value": { + "Fn::GetAtt": [ + "MinimalFunctionAliaslive", + "Name" + ] + } }, "UnResolvedVersion": { - "Ref": "FunctionWithoutAlias.Version" + "Value": { + "Ref": "FunctionWithoutAlias.Version" + } }, "AliasInSub": { - "Fn::Sub": [ - "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", - { - "SomeValue": "World" - } - ] + "Value": { + "Fn::Sub": [ + "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", + { + "SomeValue": "World" + } + ] + } }, "MustNotResolve": { - "Fn::GetAtt": [ - "FunctionWithoutAlias", - "Alias.Name" - ] + "Value": { + "Fn::GetAtt": [ + "FunctionWithoutAlias", + "Alias.Name" + ] + } } }, "Resources": { "FunctionWithoutAlias": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "FunctionWithoutAliasRole", @@ -87,11 +101,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", diff --git a/tests/translator/output/globals_for_api.json b/tests/translator/output/globals_for_api.json index b9c74178c..13abe4197 100644 --- a/tests/translator/output/globals_for_api.json +++ b/tests/translator/output/globals_for_api.json @@ -3,11 +3,11 @@ "ImplicitApiFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -68,27 +68,6 @@ } } }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:invokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "Prod", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, "ExplicitApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { @@ -109,36 +88,36 @@ "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } }, - "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] + ], + "responses": {} } } }, - "swagger": 2.0, + "swagger": 2.0, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } } - }, + }, "Name": "some api" } }, @@ -169,6 +148,44 @@ "StageName": "Stage" } }, + "ExplicitApiSomeStageStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "SomeStage", + "CacheClusterSize": "1.6", + "Variables": { + "SomeVar": "Value" + }, + "CacheClusterEnabled": true, + "DeploymentId": { + "Ref": "ExplicitApiDeploymentd5fa0145e9" + } + } + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, "ExplicitApiDeploymentd5fa0145e9": { "Type": "AWS::ApiGateway::Deployment", "Properties": { @@ -179,6 +196,27 @@ "StageName": "Stage" } }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", + "Properties": { + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] + } + }, "ServerlessRestApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { @@ -199,55 +237,38 @@ "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } }, - "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] + ], + "responses": {} } } }, - "swagger": "2.0", + "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "in": "header", + "type": "apiKey", + "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } } - }, - "Name": "some api" - } - }, - "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "SomeStage", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentd5fa0145e9" - } + "Name": "some api" } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/globals_for_function.json b/tests/translator/output/globals_for_function.json index 6d0e58931..0cf77bc37 100644 --- a/tests/translator/output/globals_for_function.json +++ b/tests/translator/output/globals_for_function.json @@ -7,7 +7,7 @@ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", + "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -29,6 +29,14 @@ "FunctionWithOverrides": { "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2" + } + ], "TracingConfig": { "Mode": "PassThrough" }, @@ -37,6 +45,9 @@ "S3Key": "hello.zip" }, "VpcConfig": { + "SubnetIds": [ + "sub-id-2" + ], "SecurityGroupIds": [ "sg-edcd9784", "sg-123" @@ -56,8 +67,8 @@ "Key": "tag1" } ], - "MemorySize": 512, "ReservedConcurrentExecutions": 100, + "MemorySize": 512, "Environment": { "Variables": { "Var1": "value1", @@ -73,11 +84,7 @@ ] }, "Timeout": 100, - "Runtime": "nodejs4.3", - "Layers": [ - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer:1" }, - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer2:2" } - ] + "Runtime": "nodejs4.3" } }, "MinimalFunctionRole": { @@ -87,7 +94,7 @@ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -124,6 +131,11 @@ "MinimalFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" + } + ], "TracingConfig": { "Mode": "Active" }, @@ -132,6 +144,9 @@ "S3Key": "global.zip" }, "VpcConfig": { + "SubnetIds": [ + "sub-id-2" + ], "SecurityGroupIds": [ "sg-edcd9784" ] @@ -146,8 +161,8 @@ "Key": "tag1" } ], - "MemorySize": 1024, "ReservedConcurrentExecutions": 50, + "MemorySize": 1024, "Environment": { "Variables": { "Var1": "value1", @@ -162,10 +177,7 @@ ] }, "Timeout": 30, - "Runtime": "python2.7", - "Layers": [ - { "Fn::Sub": "arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer:1" } - ] + "Runtime": "python2.7" } }, "MinimalFunctionAliaslive": { @@ -202,4 +214,4 @@ } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/intrinsic_functions.json b/tests/translator/output/intrinsic_functions.json index 62d8274d9..060b3eb26 100644 --- a/tests/translator/output/intrinsic_functions.json +++ b/tests/translator/output/intrinsic_functions.json @@ -1,5 +1,17 @@ { + "Conditions": { + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, "Parameters": { + "CodeKey": { + "Default": "key", + "Type": "String" + }, "CodeBucket": { "Default": "sam-demo-bucket", "Type": "String" @@ -16,16 +28,167 @@ "Default": "PassThrough", "Type": "String" } - }, - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - } - }, + }, "Resources": { + "MyExplicitApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "swagger.yaml" + }, + "Name": { + "Ref": "MyExplicitApiName" + } + } + }, + "MyTable": { + "Type": "AWS::DynamoDB::Table", + "Properties": { + "KeySchema": [ + { + "KeyType": "HASH", + "AttributeName": "id" + } + ], + "StreamSpecification": { + "StreamViewType": "NEW_IMAGE" + }, + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "ProvisionedThroughput": { + "WriteCapacityUnits": 5, + "ReadCapacityUnits": 5 + } + } + }, + "SnsDlqQueue": { + "Type": "AWS::SNS::Topic" + }, + "MySqsDlqLambdaFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "DeadLetterConfig": { + "TargetArn": { + "Fn::GetAtt": [ + "SqsDlqQueue", + "Arn" + ] + } + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MySqsDlqLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7" + } + }, + "SqsDlqQueue": { + "Type": "AWS::SQS::Queue" + }, + "ApiWithExplicitS3Uri": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "BodyS3Location": { + "Version": "myversion", + "Bucket": "mybucket", + "Key": "mykey" + } + }, + "Condition": "TrueCondition" + }, + "MyExplicitApiDeployment31ec20c228": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "Description": "RestApi deployment id: 31ec20c2288b273d15235777b0b90f3c0e2f9d52", + "StageName": "Stage" + } + }, + "FunctionWithExplicitS3Uri": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "stream.ddb_handler", + "Code": { + "S3Bucket": "mybucket", + "S3Key": "mykey", + "S3ObjectVersion": "MyVersion" + }, + "Role": { + "Fn::GetAtt": [ + "FunctionWithExplicitS3UriRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MySnsDlqLambdaFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Policies": [ + { + "PolicyName": "DeadLetterQueuePolicy", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sns:Publish", + "Resource": { + "Ref": "SnsDlqQueue" + }, + "Effect": "Allow" + } + ] + } + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, "MyFunction": { "Type": "AWS::Lambda::Function", "Properties": { @@ -39,9 +202,7 @@ "Ref": "CodeBucket" }, "S3Key": { - "Fn::Sub": [ - "code.zip" - ] + "Fn::Sub": "code.zip.${CodeKey}" }, "S3ObjectVersion": { "Fn::Join": [ @@ -111,19 +272,6 @@ } } }, - "ApiWithExplicitS3UridevStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "TrueCondition", - "Properties": { - "DeploymentId": { - "Ref": "ApiWithExplicitS3UriDeploymenta227798f00" - }, - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" - }, - "StageName": "dev" - } - }, "DynamoDBFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { @@ -158,10 +306,7 @@ }, "DeadLetterConfig": { "TargetArn": { - "Fn::GetAtt": [ - "SnsDlqQueue", - "Arn" - ] + "Ref": "SnsDlqQueue" } }, "Tags": [ @@ -180,29 +325,6 @@ "Runtime": "python2.7" } }, - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "swagger.yaml" - }, - "Name": { - "Ref": "MyExplicitApiName" - } - } - }, - "ApiWithExplicitS3UriDeploymenta227798f00": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "TrueCondition", - "Properties": { - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" - }, - "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", - "StageName": "Stage" - } - }, "MyFunctionMyApiPermissionTest": { "Type": "AWS::Lambda::Permission", "Properties": { @@ -224,41 +346,53 @@ } } }, - "MyTable": { - "Type": "AWS::DynamoDB::Table", + "MyNewRole": { + "Type": "AWS::IAM::Role", "Properties": { - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ + "Policies": [ { - "AttributeName": "id", - "AttributeType": "S" + "PolicyName": "lambdaRole", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "cloudwatch:*", + "logs:*" + ], + "Resource": "*", + "Effect": "Allow" + } + ] + } } ], - "ProvisionedThroughput": { - "WriteCapacityUnits": "5", - "ReadCapacityUnits": "5" + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] } } }, - "SnsDlqQueue": { - "Type": "AWS::SNS::Topic" - }, "DynamoDBFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "stream.ddb_handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "streams.zip" }, - "Handler": "stream.ddb_handler", "Role": { "Fn::GetAtt": [ "DynamoDBFunctionRole", @@ -274,62 +408,18 @@ ] } }, - "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "DeadLetterConfig": { - "TargetArn": { - "Fn::GetAtt": [ - "SqsDlqQueue", - "Arn" - ] - } - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MySqsDlqLambdaFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "MyExplicitApidevStage": { + "ApiWithExplicitS3UridevStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { - "Variables": { - "FunctionName": { - "Fn::Sub": "${MyFunction}" - }, - "Var2": { - "Fn::Join": [ - "join ", - [ - "some value ", - "with some other value" - ] - ] - } + "DeploymentId": { + "Ref": "ApiWithExplicitS3UriDeploymenta227798f00" }, "RestApiId": { - "Ref": "MyExplicitApi" - }, - "DeploymentId": { - "Ref": "MyExplicitApiDeployment31ec20c228" + "Ref": "ApiWithExplicitS3Uri" }, "StageName": "dev" - } + }, + "Condition": "TrueCondition" }, "DynamoDBFunctionMyDDBStream": { "Type": "AWS::Lambda::EventSourceMapping", @@ -347,29 +437,16 @@ "StartingPosition": "LATEST" } }, - "SqsDlqQueue": { - "Type": "AWS::SQS::Queue" - }, - "MyExplicitApiDeployment31ec20c228": { + "ApiWithExplicitS3UriDeploymenta227798f00": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { - "Ref": "MyExplicitApi" + "Ref": "ApiWithExplicitS3Uri" }, - "Description": "RestApi deployment id: 31ec20c2288b273d15235777b0b90f3c0e2f9d52", + "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", "StageName": "Stage" - } - }, - "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", - "Condition": "TrueCondition", - "Properties": { - "BodyS3Location": { - "Version": "myversion", - "Bucket": "mybucket", - "Key": "mykey" - } - } + }, + "Condition": "TrueCondition" }, "MySqsDlqLambdaFunctionRole": { "Type": "AWS::IAM::Role", @@ -415,72 +492,30 @@ } } }, - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ - { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": { - "Fn::GetAtt": [ - "SnsDlqQueue", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", + "MyExplicitApidevStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { - "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", - "S3ObjectVersion": "MyVersion" + "DeploymentId": { + "Ref": "MyExplicitApiDeployment31ec20c228" }, - "Handler": "stream.ddb_handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", - "Arn" - ] + "RestApiId": { + "Ref": "MyExplicitApi" }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Variables": { + "FunctionName": { + "Fn::Sub": "${MyFunction}" + }, + "Var2": { + "Fn::Join": [ + "join ", + [ + "some value ", + "with some other value" + ] + ] } - ] + }, + "StageName": "dev" } }, "MyFunctionMyApiPermissiondev": { diff --git a/tests/translator/output/layers_all_properties.json b/tests/translator/output/layers_all_properties.json index bc67f3d9f..2cb5221e0 100644 --- a/tests/translator/output/layers_all_properties.json +++ b/tests/translator/output/layers_all_properties.json @@ -1,50 +1,105 @@ { + "Outputs": { + "LayerSub": { + "Value": { + "Fn::Sub": "${MyLayerd04062b365}" + } + }, + "FunctionAtt": { + "Value": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + }, + "LayerName": { + "Value": { + "Ref": "MyLayerd04062b365" + } + }, + "FunctionSub": { + "Value": { + "Fn::Sub": "${MyFunction}" + } + }, + "FunctionName": { + "Value": { + "Ref": "MyFunction" + } + } + }, "Parameters": { "LayerDeleteParam": { "Default": "Delete", "Type": "String" } - }, + }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Layers": [ + { + "Ref": "MyLayerd04062b365" + } + ], "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, - "Handler": "app.handler", + }, + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "Handler": "app.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python3.6", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], - "Layers": [ - { - "Ref": "MyLayerd04062b365" - } - ] + }, + "Runtime": "python3.6" + } + }, + "MyLayerd04062b365": { + "DeletionPolicy": "Delete", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "MyLayer" } - }, + }, + "MyLayerWithANamefda8c9ec8c": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "DifferentLayerName" + } + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -52,71 +107,8 @@ } } ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ] - } - }, - "MyLayerd04062b365": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Delete", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "MyLayer" - } - }, - "MyLayerWithANamefda8c9ec8c": { - "Type": "AWS::Lambda::LayerVersion", - "DeletionPolicy": "Retain", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "DifferentLayerName" - } - } - }, - "Outputs": { - "LayerName": { - "Value": { - "Ref": "MyLayerd04062b365" - } - }, - "FunctionName": { - "Value": { - "Ref": "MyFunction" - } - }, - "LayerAtt": { - "Value": { - "Fn::GetAtt": [ - "MyLayerd04062b365", - "Arn" - ] - } - }, - "FunctionAtt": { - "Value": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - } - }, - "LayerSub": { - "Value": { - "Fn::Sub": "${MyLayerd04062b365}" - } - }, - "FunctionSub": { - "Value": { - "Fn::Sub": "${MyFunction}" + } } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/no_implicit_api_with_serverless_rest_api_resource.json b/tests/translator/output/no_implicit_api_with_serverless_rest_api_resource.json index 8dcbdab10..1ffbb945e 100644 --- a/tests/translator/output/no_implicit_api_with_serverless_rest_api_resource.json +++ b/tests/translator/output/no_implicit_api_with_serverless_rest_api_resource.json @@ -1,25 +1,29 @@ { "Resources": { - "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "GetHtmlFunction": { + "Type": "AWS::Lambda::Function", "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" ] - } + }, + "Runtime": "python3.6", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] } - }, - "ThumbnailFunctionRole": { + }, + "GetHtmlFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ @@ -56,14 +60,106 @@ "Principal": "s3.amazonaws.com" } }, + "RestApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "RestApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.6", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ThumbnailFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "Images": { + "Type": "AWS::S3::Bucket", + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + }, + "Event": "s3:ObjectCreated:*" + } + ] + } + }, + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ] + }, "ThumbnailFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.generate_thumbails", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ "ThumbnailFunctionRole", diff --git a/tests/translator/output/s3_existing_other_notification_configuration.json b/tests/translator/output/s3_existing_other_notification_configuration.json index 71ceed34d..447f0a8f6 100644 --- a/tests/translator/output/s3_existing_other_notification_configuration.json +++ b/tests/translator/output/s3_existing_other_notification_configuration.json @@ -1,8 +1,7 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "Type": "AWS::S3::Bucket", "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ @@ -18,11 +17,15 @@ ], "TopicConfigurations": [ { - "Topic": "my-super-awesome-topic" + "Topic": "my-super-awesome-topic", + "Event": "s3:ObjectRemoved:*" } ] } - } + }, + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ] }, "ThumbnailFunctionRole": { "Type": "AWS::IAM::Role", @@ -64,11 +67,11 @@ "ThumbnailFunction": { "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "index.generate_thumbails", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ "ThumbnailFunctionRole", diff --git a/tests/translator/output/s3_with_condition.json b/tests/translator/output/s3_with_condition.json index 931232247..b2397cc3a 100644 --- a/tests/translator/output/s3_with_condition.json +++ b/tests/translator/output/s3_with_condition.json @@ -1,48 +1,55 @@ { + "Conditions": { + "MyCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, "Resources": { "Images": { - "Type": "AWS::S3::Bucket", + "Type": "AWS::S3::Bucket", "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { "Fn::If": [ - "MyCondition", + "MyCondition", { "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, + }, "Event": "s3:ObjectCreated:*" - }, + }, { "Ref": "AWS::NoValue" } ] } ] - }, + }, "Tags": [ { "Value": { "Fn::If": [ - "MyCondition", + "MyCondition", { "Ref": "ThumbnailFunctionImageBucketPermission" - }, + }, "no dependency" ] - }, + }, "Key": "sam:ConditionalDependsOn:ThumbnailFunctionImageBucketPermission" } - ] + ] } }, "ThumbnailFunctionRole": { "Type": "AWS::IAM::Role", - "Condition": "MyCondition", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -63,11 +70,11 @@ } ] } - } + }, + "Condition": "MyCondition" }, "ThumbnailFunctionImageBucketPermission": { "Type": "AWS::Lambda::Permission", - "Condition": "MyCondition", "Properties": { "Action": "lambda:invokeFunction", "SourceAccount": { @@ -77,17 +84,17 @@ "Ref": "ThumbnailFunction" }, "Principal": "s3.amazonaws.com" - } + }, + "Condition": "MyCondition" }, "ThumbnailFunction": { "Type": "AWS::Lambda::Function", - "Condition": "MyCondition", "Properties": { + "Handler": "index.generate_thumbails", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ "ThumbnailFunctionRole", @@ -101,7 +108,8 @@ "Key": "lambda:createdBy" } ] - } + }, + "Condition": "MyCondition" } } } \ No newline at end of file diff --git a/tests/translator/output/simple_table_ref_parameter_intrinsic.json b/tests/translator/output/simple_table_ref_parameter_intrinsic.json index 667ce5351..f2e511930 100644 --- a/tests/translator/output/simple_table_ref_parameter_intrinsic.json +++ b/tests/translator/output/simple_table_ref_parameter_intrinsic.json @@ -1,4 +1,18 @@ { + "Parameters": { + "ReadCapacity": { + "Default": 15, + "Type": "Number" + }, + "WriteCapacity": { + "Default": 15, + "Type": "Number" + }, + "EnableSSE": { + "Default": true, + "Type": "String" + } + }, "Resources": { "MinimalTableRefParamLongForm": { "Type": "AWS::DynamoDB::Table", diff --git a/tests/translator/output/simple_table_with_extra_tags.json b/tests/translator/output/simple_table_with_extra_tags.json index 23d2f3fb6..a02e088cd 100644 --- a/tests/translator/output/simple_table_with_extra_tags.json +++ b/tests/translator/output/simple_table_with_extra_tags.json @@ -1,4 +1,10 @@ { + "Parameters": { + "TagValueParam": { + "Default": "value", + "Type": "String" + } + }, "Resources": { "MinimalTableWithTags": { "Type": "AWS::DynamoDB::Table", @@ -32,7 +38,7 @@ "Key": "TagKey3" }, { - "Value": 123, + "Value": "123", "Key": "TagKey4" } ] diff --git a/tests/translator/output/simple_table_with_table_name.json b/tests/translator/output/simple_table_with_table_name.json index 215960a56..57b9ef7a8 100644 --- a/tests/translator/output/simple_table_with_table_name.json +++ b/tests/translator/output/simple_table_with_table_name.json @@ -1,4 +1,10 @@ { + "Parameters": { + "MySimpleTableParameter": { + "Default": "TableName", + "Type": "String" + } + }, "Resources": { "MinimalTableWithTableName": { "Type": "AWS::DynamoDB::Table", diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 88657b15b..1de9ab8e4 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -1,4 +1,6 @@ import json +import cfnlint.core +from cfnlint import Runner import itertools import os.path import hashlib @@ -34,6 +36,19 @@ INPUT_FOLDER = os.path.join(BASE_PATH, 'input') OUTPUT_FOLDER = os.path.join(BASE_PATH, 'output') +LINT_IGNORE_WARNINGS = [ + 'W2001', # unused parameters. Sometimes, SAM uses parameters and removes the param reference from the output template, but the parameter stays in the parameters section. + 'W1001', # Ref/GetAtt with conditions. This incorrectly flags resources since it can't map conditions fully. + 'E3001', # Check for resource availability in a region. + 'W7001', # Check if mappings are used. Serverless::Application uses mappings, the output CFN doesn't use them anymore. + 'W1020', # Sub isn't needed if it doesn't have a variable defined. SAM leaves `!Sub` in even if it tries to resolve variables. +] + +LINT_IGNORE_TESTS = [ + 'function_with_resource_refs', # Tests functionality of the translator in ways that result in improper GetAtt calls on CFN resources. + 'api_with_canary_setting', # Has stage variable overrides for nonexistent stage variables. +] + def deep_sort_lists(value): """ @@ -254,7 +269,8 @@ def test_transform_success(self, testcase, partition_with_region): # To uncover unicode-related bugs, convert dict to JSON string and parse JSON back to dict manifest = json.loads(json.dumps(manifest)) partition_folder = partition if partition != "aws" else "" - expected = json.load(open(os.path.join(OUTPUT_FOLDER, partition_folder, testcase + '.json'), 'r')) + expected_filepath = os.path.join(OUTPUT_FOLDER, partition_folder, testcase + '.json') + expected = json.load(open(expected_filepath, 'r')) with patch('boto3.session.Session.region_name', region): parameter_values = get_template_parameter_values() @@ -271,12 +287,29 @@ def test_transform_success(self, testcase, partition_with_region): print(json.dumps(output_fragment, indent=2)) + # Run cfn-lint on translator test output files. + rules = cfnlint.core.get_rules([], LINT_IGNORE_WARNINGS, []) + # Only update the deployment Logical Id hash in Py3. if sys.version_info.major >= 3: self._update_logical_id_hash(expected) self._update_logical_id_hash(output_fragment) + output_template = cfnlint.decode.cfn_json.load(expected_filepath) + else: # deprecation warning catching in py2 + import warnings + with warnings.catch_warnings(): + warnings.filterwarnings("ignore",category=DeprecationWarning) + output_template = cfnlint.decode.cfn_json.load(expected_filepath) + runner = cfnlint.Runner(rules, expected_filepath, output_template, [region]) + matches = [] + + # Only run linter on normal/gov partitions. It errors on china regions + if testcase not in LINT_IGNORE_TESTS and partition != 'aws-cn': + matches = runner.run() + print('cfn-lint ({}): {}'.format(expected_filepath, matches)) assert deep_sort_lists(output_fragment) == deep_sort_lists(expected) + assert len(matches) == 0 def _update_logical_id_hash(self, resources): """ @@ -339,8 +372,8 @@ def _update_logical_id_hash(self, resources): # Update any Output References in the template for output_key, output_value in resources.get("Outputs", {}).items(): - if output_value.get("Ref") in deployment_logical_id_dict: - output_value["Ref"] = deployment_logical_id_dict[output_value.get("Ref")] + if output_value.get("Value").get("Ref") in deployment_logical_id_dict: + output_value["Value"]["Ref"] = deployment_logical_id_dict[output_value.get("Value").get("Ref")] def _generate_new_deployment_hash(self, logical_id, dict_to_hash, rest_api_to_swagger_hash): data_bytes = json.dumps(dict_to_hash, separators=(',', ':'), sort_keys=True).encode("utf8") diff --git a/tests/translator/validator/test_validator.py b/tests/translator/validator/test_validator.py index e69d199ec..baf9da873 100644 --- a/tests/translator/validator/test_validator.py +++ b/tests/translator/validator/test_validator.py @@ -8,7 +8,6 @@ INPUT_FOLDER = os.path.join(BASE_PATH, os.pardir, 'input') @pytest.mark.parametrize('testcase', [ - 'basic_function', 'cloudwatchevent', 'cloudwatch_logs_with_ref', 'cloudwatchlog', diff --git a/versions/2016-10-31.md b/versions/2016-10-31.md index c487ad7cb..b5f7f6f17 100644 --- a/versions/2016-10-31.md +++ b/versions/2016-10-31.md @@ -259,7 +259,7 @@ Property Name | Type | Description ---|:---:|--- Location | `string` or [Application Location Object](#application-location-object) | **Required** Template URL or location of nested application. If a template URL is given, it must follow the format specified in the [CloudFormation TemplateUrl documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html#cfn-cloudformation-stack-templateurl) and contain a valid CloudFormation or SAM template. Parameters | Map of `string` to `string` | Application parameter values. -NotificationArns | List of `string` | A list of existing Amazon SNS topics where notifications about stack events are sent. +NotificationARNs | List of `string` | A list of existing Amazon SNS topics where notifications about stack events are sent. Tags | Map of `string` to `string` | A map (string to string) that specifies the [tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html) to be added to this application. When the stack is created, SAM will automatically add the following tags: lambda:createdBy:SAM, serverlessrepo:applicationId:\, serverlessrepo:semanticVersion:\. TimeoutInMinutes | `integer` | The length of time, in minutes, that AWS CloudFormation waits for the nested stack to reach the CREATE_COMPLETE state. The default is no timeout. When AWS CloudFormation detects that the nested stack has reached the CREATE_COMPLETE state, it marks the nested stack resource as CREATE_COMPLETE in the parent stack and resumes creating the parent stack. If the timeout period expires before the nested stack reaches CREATE_COMPLETE, AWS CloudFormation marks the nested stack as failed and rolls back both the nested stack and parent stack. From 7209ed4c71a7f6b87cdbe62abd8aeaadf9f13bd1 Mon Sep 17 00:00:00 2001 From: Manvendra Singh Date: Wed, 17 Apr 2019 00:27:49 +0530 Subject: [PATCH 05/34] feat: custom CodeDeploy configurations in DeploymentPreference (#848) --- docs/safe_lambda_deployments.rst | 3 +- .../deployment_preference_collection.py | 34 ++- ...stom_codedeploy_deployment_preference.yaml | 10 + ...onal_codedeploy_deployment_preference.yaml | 19 ++ .../function_with_deployment_preference.yaml | 2 +- ...ment_preference_multiple_combinations.yaml | 2 +- .../test_deployment_preference_collection.py | 63 +++++- ...stom_codedeploy_deployment_preference.json | 142 +++++++++++++ ...onal_codedeploy_deployment_preference.json | 193 ++++++++++++++++++ .../function_with_deployment_preference.json | 2 +- ...ment_preference_multiple_combinations.json | 2 +- ...stom_codedeploy_deployment_preference.json | 142 +++++++++++++ ...onal_codedeploy_deployment_preference.json | 193 ++++++++++++++++++ .../function_with_deployment_preference.json | 2 +- ...ment_preference_multiple_combinations.json | 2 +- ...stom_codedeploy_deployment_preference.json | 142 +++++++++++++ ...onal_codedeploy_deployment_preference.json | 193 ++++++++++++++++++ .../function_with_deployment_preference.json | 2 +- ...ment_preference_multiple_combinations.json | 2 +- tests/translator/test_translator.py | 2 + 20 files changed, 1137 insertions(+), 15 deletions(-) create mode 100644 tests/translator/input/function_with_custom_codedeploy_deployment_preference.yaml create mode 100644 tests/translator/input/function_with_custom_conditional_codedeploy_deployment_preference.yaml create mode 100644 tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json create mode 100644 tests/translator/output/aws-cn/function_with_custom_conditional_codedeploy_deployment_preference.json create mode 100644 tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json create mode 100644 tests/translator/output/aws-us-gov/function_with_custom_conditional_codedeploy_deployment_preference.json create mode 100644 tests/translator/output/function_with_custom_codedeploy_deployment_preference.json create mode 100644 tests/translator/output/function_with_custom_conditional_codedeploy_deployment_preference.json diff --git a/docs/safe_lambda_deployments.rst b/docs/safe_lambda_deployments.rst index c6c4b1454..539d12424 100644 --- a/docs/safe_lambda_deployments.rst +++ b/docs/safe_lambda_deployments.rst @@ -223,7 +223,8 @@ They work as follows: - **AllAtOnce**: This is an instant shifting of 100% of traffic to new version. This is useful if you want to run run pre/post hooks but don't want a gradual deployment. If you have a pipeline, you can set Beta/Gamma stages to deploy instantly because the speed of deployments matter more than safety here. - +- **Custom**: Aside from Above mentioned Configurations, Custom Codedeploy configuration are also supported. + (Example. Type: CustomCodeDeployConfiguration) PreTraffic & PostTraffic Hooks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/samtranslator/model/preferences/deployment_preference_collection.py b/samtranslator/model/preferences/deployment_preference_collection.py index 25ac19158..1c67e8b11 100644 --- a/samtranslator/model/preferences/deployment_preference_collection.py +++ b/samtranslator/model/preferences/deployment_preference_collection.py @@ -2,12 +2,23 @@ from samtranslator.model.codedeploy import CodeDeployApplication from samtranslator.model.codedeploy import CodeDeployDeploymentGroup from samtranslator.model.iam import IAMRole -from samtranslator.model.intrinsics import fnSub +from samtranslator.model.intrinsics import fnSub, is_instrinsic from samtranslator.model.update_policy import UpdatePolicy from samtranslator.translator.arn_generator import ArnGenerator +import copy CODE_DEPLOY_SERVICE_ROLE_LOGICAL_ID = 'CodeDeployServiceRole' CODEDEPLOY_APPLICATION_LOGICAL_ID = 'ServerlessDeploymentApplication' +CODEDEPLOY_PREDEFINED_CONFIGURATIONS_LIST = ["Canary10Percent5Minutes", + "Canary10Percent10Minutes", + "Canary10Percent15Minutes", + "Canary10Percent30Minutes", + "Linear10PercentEvery1Minute", + "Linear10PercentEvery2Minutes", + "Linear10PercentEvery3Minutes", + "Linear10PercentEvery10Minutes", + "AllAtOnce" + ] class DeploymentPreferenceCollection(object): @@ -95,6 +106,7 @@ def deployment_group(self, function_logical_id): :param function_logical_id: logical_id of the function this deployment group belongs to :return: CodeDeployDeploymentGroup resource """ + deployment_preference = self.get(function_logical_id) deployment_group = CodeDeployDeploymentGroup(self.deployment_group_logical_id(function_logical_id)) @@ -109,8 +121,10 @@ def deployment_group(self, function_logical_id): 'Events': ['DEPLOYMENT_FAILURE', 'DEPLOYMENT_STOP_ON_ALARM', 'DEPLOYMENT_STOP_ON_REQUEST']} - deployment_group.DeploymentConfigName = fnSub("CodeDeployDefault.Lambda${ConfigName}", - {"ConfigName": deployment_preference.deployment_type}) + + deployment_group.DeploymentConfigName = self._replace_deployment_types(copy.deepcopy( + deployment_preference.deployment_type)) + deployment_group.DeploymentStyle = {'DeploymentType': 'BLUE_GREEN', 'DeploymentOption': 'WITH_TRAFFIC_CONTROL'} @@ -120,6 +134,20 @@ def deployment_group(self, function_logical_id): return deployment_group + def _replace_deployment_types(self, value): + if isinstance(value, list): + for i in range(len(value)): + value[i] = self._replace_deployment_types(value[i]) + return value + elif is_instrinsic(value): + for (k, v) in value.items(): + value[k] = self._replace_deployment_types(v) + return value + else: + if value in CODEDEPLOY_PREDEFINED_CONFIGURATIONS_LIST: + return fnSub("CodeDeployDefault.Lambda${ConfigName}", {"ConfigName": value}) + return value + def update_policy(self, function_logical_id): deployment_preference = self.get(function_logical_id) diff --git a/tests/translator/input/function_with_custom_codedeploy_deployment_preference.yaml b/tests/translator/input/function_with_custom_codedeploy_deployment_preference.yaml new file mode 100644 index 000000000..25846f700 --- /dev/null +++ b/tests/translator/input/function_with_custom_codedeploy_deployment_preference.yaml @@ -0,0 +1,10 @@ +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: TestDeploymentConfiguration \ No newline at end of file diff --git a/tests/translator/input/function_with_custom_conditional_codedeploy_deployment_preference.yaml b/tests/translator/input/function_with_custom_conditional_codedeploy_deployment_preference.yaml new file mode 100644 index 000000000..e1a53328e --- /dev/null +++ b/tests/translator/input/function_with_custom_conditional_codedeploy_deployment_preference.yaml @@ -0,0 +1,19 @@ +AWSTemplateFormatVersion : '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Parameters: + EnvType: + Default: dev + Type: String +Conditions: + IsDevEnv: !Equals [!Ref EnvType, dev] + IsDevEnv2: !Equals [!Ref EnvType, prod] +Resources: + HelloWorldFunction: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: nodejs8.10 + CodeUri: s3://bucket/key + AutoPublishAlias: live + DeploymentPreference: + Type: !If [IsDevEnv, !If [IsDevEnv2, AllAtOnce, TestCustomDeploymentConfig], Canary10Percent15Minutes] diff --git a/tests/translator/input/function_with_deployment_preference.yaml b/tests/translator/input/function_with_deployment_preference.yaml index f2215849e..19eaa9431 100644 --- a/tests/translator/input/function_with_deployment_preference.yaml +++ b/tests/translator/input/function_with_deployment_preference.yaml @@ -7,4 +7,4 @@ Resources: Runtime: python2.7 AutoPublishAlias: live DeploymentPreference: - Type: Linear10PercentEvery3Minute \ No newline at end of file + Type: Linear10PercentEvery3Minutes \ No newline at end of file diff --git a/tests/translator/input/function_with_deployment_preference_multiple_combinations.yaml b/tests/translator/input/function_with_deployment_preference_multiple_combinations.yaml index 079d10950..588983aa0 100644 --- a/tests/translator/input/function_with_deployment_preference_multiple_combinations.yaml +++ b/tests/translator/input/function_with_deployment_preference_multiple_combinations.yaml @@ -25,7 +25,7 @@ Resources: Runtime: python2.7 AutoPublishAlias: livewithdeploymentwithhooksandalarms DeploymentPreference: - Type: Linear10PercentEvery2Minute + Type: Linear10PercentEvery2Minutes Hooks: PreTraffic: !Ref MySanityTestFunction PostTraffic: !Ref MyValidationTestFunction diff --git a/tests/translator/model/preferences/test_deployment_preference_collection.py b/tests/translator/model/preferences/test_deployment_preference_collection.py index 0481628b6..4415c01c2 100644 --- a/tests/translator/model/preferences/test_deployment_preference_collection.py +++ b/tests/translator/model/preferences/test_deployment_preference_collection.py @@ -63,12 +63,11 @@ def test_deployment_group_with_minimal_parameters(self): 'Events': ['DEPLOYMENT_FAILURE', 'DEPLOYMENT_STOP_ON_ALARM', 'DEPLOYMENT_STOP_ON_REQUEST']} - deployment_type = 'deployment_type' expected_deployment_group.DeploymentConfigName = { 'Fn::Sub': [ 'CodeDeployDefault.Lambda${ConfigName}', { - 'ConfigName': deployment_type + 'ConfigName': self.deployment_type_global } ] } @@ -77,12 +76,70 @@ def test_deployment_group_with_minimal_parameters(self): expected_deployment_group.ServiceRoleArn = {'Fn::GetAtt': [CODE_DEPLOY_SERVICE_ROLE_LOGICAL_ID, 'Arn']} deployment_preference_collection = DeploymentPreferenceCollection() - deployment_preference_collection.add(self.function_logical_id, {'Type': deployment_type}) + deployment_preference_collection.add(self.function_logical_id, {'Type': self.deployment_type_global}) deployment_group = deployment_preference_collection.deployment_group(self.function_logical_id) self.assertEqual(deployment_group.to_dict(), expected_deployment_group.to_dict()) + @patch('boto3.session.Session.region_name', 'ap-southeast-1') + def test_deployment_preference_with_codedeploy_custom_configuration(self): + deployment_type = "TestDeploymentConfiguration" + deployment_preference_collection = DeploymentPreferenceCollection() + deployment_preference_collection.add(self.function_logical_id, {'Type': deployment_type}) + deployment_group = deployment_preference_collection.deployment_group(self.function_logical_id) + + self.assertEqual(deployment_type, deployment_group.DeploymentConfigName) + + @patch('boto3.session.Session.region_name', 'ap-southeast-1') + def test_deployment_preference_with_codedeploy_predifined_configuration(self): + deployment_type = "Canary10Percent5Minutes" + expected_deployment_config_name = { + 'Fn::Sub': [ + 'CodeDeployDefault.Lambda${ConfigName}', + { + 'ConfigName': deployment_type + } + ] + } + deployment_preference_collection = DeploymentPreferenceCollection() + deployment_preference_collection.add(self.function_logical_id, {'Type': deployment_type}) + deployment_group = deployment_preference_collection.deployment_group(self.function_logical_id) + + print(deployment_group.DeploymentConfigName) + self.assertEqual(expected_deployment_config_name, deployment_group.DeploymentConfigName) + + @patch('boto3.session.Session.region_name', 'ap-southeast-1') + def test_deployment_preference_with_conditional_custom_configuration(self): + deployment_type = {'Fn::If': ['IsDevEnv', {'Fn::If': + ['IsDevEnv1', 'AllAtOnce', 'TestDeploymentConfiguration']}, + 'Canary10Percent15Minutes']} + + expected_deployment_config_name = {'Fn::If': + ['IsDevEnv', {'Fn::If': + ['IsDevEnv1', {'Fn::Sub': [ + 'CodeDeployDefault.Lambda${ConfigName}', + { + 'ConfigName': 'AllAtOnce' + } + ] + }, + 'TestDeploymentConfiguration']}, + {'Fn::Sub': [ + 'CodeDeployDefault.Lambda${ConfigName}', + { + 'ConfigName': 'Canary10Percent15Minutes' + } + ] + } + ] + } + deployment_preference_collection = DeploymentPreferenceCollection() + deployment_preference_collection.add(self.function_logical_id, {'Type': deployment_type}) + deployment_group = deployment_preference_collection.deployment_group(self.function_logical_id) + print(deployment_group.DeploymentConfigName) + self.assertEqual(expected_deployment_config_name, deployment_group.DeploymentConfigName) + @patch('boto3.session.Session.region_name', 'ap-southeast-1') def test_deployment_group_with_all_parameters(self): expected_deployment_group = CodeDeployDeploymentGroup(self.function_logical_id + 'DeploymentGroup') diff --git a/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json b/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json new file mode 100644 index 000000000..e15c61776 --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json @@ -0,0 +1,142 @@ +{ + "Resources": { + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": "TestDeploymentConfiguration", + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + } + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + } + } + } diff --git a/tests/translator/output/aws-cn/function_with_custom_conditional_codedeploy_deployment_preference.json b/tests/translator/output/aws-cn/function_with_custom_conditional_codedeploy_deployment_preference.json new file mode 100644 index 000000000..e78aeb5bf --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_custom_conditional_codedeploy_deployment_preference.json @@ -0,0 +1,193 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": { + "EnvType": { + "Default": "dev", + "Type": "String" + } + }, + "Conditions": { + "IsDevEnv2": { + "Fn::Equals": [ + { + "Ref": "EnvType" + }, + "prod" + ] + }, + "IsDevEnv": { + "Fn::Equals": [ + { + "Ref": "EnvType" + }, + "dev" + ] + } + }, + "Resources": { + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "HelloWorldFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + } + } + }, + "HelloWorldFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::If": [ + "IsDevEnv", + { + "Fn::If": [ + "IsDevEnv2", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "TestCustomDeploymentConfig" + ] + }, + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Canary10Percent15Minutes" + } + ] + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "HelloWorldFunctionVersionfb53d5c2e6": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "HelloWorldFunction" + } + } + }, + "HelloWorldFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "HelloWorldFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "HelloWorldFunctionVersionfb53d5c2e6", + "Version" + ] + }, + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "Name": "live" + } + }, + "HelloWorldFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + } + } +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference.json b/tests/translator/output/aws-cn/function_with_deployment_preference.json index 81771bafc..d61057286 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference.json @@ -24,7 +24,7 @@ "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", { - "ConfigName": "Linear10PercentEvery3Minute" + "ConfigName": "Linear10PercentEvery3Minutes" } ] }, diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations.json b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations.json index 9600d5271..6fed70de7 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations.json @@ -148,7 +148,7 @@ "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", { - "ConfigName": "Linear10PercentEvery2Minute" + "ConfigName": "Linear10PercentEvery2Minutes" } ] }, diff --git a/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json b/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json new file mode 100644 index 000000000..60928c399 --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json @@ -0,0 +1,142 @@ +{ + "Resources": { + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": "TestDeploymentConfiguration", + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + } + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + } + } + } diff --git a/tests/translator/output/aws-us-gov/function_with_custom_conditional_codedeploy_deployment_preference.json b/tests/translator/output/aws-us-gov/function_with_custom_conditional_codedeploy_deployment_preference.json new file mode 100644 index 000000000..c2da9a1fd --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_custom_conditional_codedeploy_deployment_preference.json @@ -0,0 +1,193 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": { + "EnvType": { + "Default": "dev", + "Type": "String" + } + }, + "Conditions": { + "IsDevEnv2": { + "Fn::Equals": [ + { + "Ref": "EnvType" + }, + "prod" + ] + }, + "IsDevEnv": { + "Fn::Equals": [ + { + "Ref": "EnvType" + }, + "dev" + ] + } + }, + "Resources": { + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "HelloWorldFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + } + } + }, + "HelloWorldFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::If": [ + "IsDevEnv", + { + "Fn::If": [ + "IsDevEnv2", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "TestCustomDeploymentConfig" + ] + }, + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Canary10Percent15Minutes" + } + ] + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "HelloWorldFunctionVersionfb53d5c2e6": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "HelloWorldFunction" + } + } + }, + "HelloWorldFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "HelloWorldFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "HelloWorldFunctionVersionfb53d5c2e6", + "Version" + ] + }, + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "Name": "live" + } + }, + "HelloWorldFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + } + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference.json index f02c6a1e4..a16ba0a1d 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference.json @@ -24,7 +24,7 @@ "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", { - "ConfigName": "Linear10PercentEvery3Minute" + "ConfigName": "Linear10PercentEvery3Minutes" } ] }, diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations.json index a3cd8f87b..ab1cdabb4 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations.json @@ -148,7 +148,7 @@ "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", { - "ConfigName": "Linear10PercentEvery2Minute" + "ConfigName": "Linear10PercentEvery2Minutes" } ] }, diff --git a/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json b/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json new file mode 100644 index 000000000..d0d846442 --- /dev/null +++ b/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json @@ -0,0 +1,142 @@ +{ + "Resources": { + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": "TestDeploymentConfiguration", + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + } + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + } + } + } \ No newline at end of file diff --git a/tests/translator/output/function_with_custom_conditional_codedeploy_deployment_preference.json b/tests/translator/output/function_with_custom_conditional_codedeploy_deployment_preference.json new file mode 100644 index 000000000..413b8913d --- /dev/null +++ b/tests/translator/output/function_with_custom_conditional_codedeploy_deployment_preference.json @@ -0,0 +1,193 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": { + "EnvType": { + "Default": "dev", + "Type": "String" + } + }, + "Conditions": { + "IsDevEnv2": { + "Fn::Equals": [ + { + "Ref": "EnvType" + }, + "prod" + ] + }, + "IsDevEnv": { + "Fn::Equals": [ + { + "Ref": "EnvType" + }, + "dev" + ] + } + }, + "Resources": { + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "HelloWorldFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + } + } + }, + "HelloWorldFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::If": [ + "IsDevEnv", + { + "Fn::If": [ + "IsDevEnv2", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "TestCustomDeploymentConfig" + ] + }, + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Canary10Percent15Minutes" + } + ] + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "HelloWorldFunctionVersionfb53d5c2e6": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "HelloWorldFunction" + } + } + }, + "HelloWorldFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "HelloWorldFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "HelloWorldFunctionVersionfb53d5c2e6", + "Version" + ] + }, + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "Name": "live" + } + }, + "HelloWorldFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + } + } +} diff --git a/tests/translator/output/function_with_deployment_preference.json b/tests/translator/output/function_with_deployment_preference.json index bfdbb7bdc..75ba69524 100644 --- a/tests/translator/output/function_with_deployment_preference.json +++ b/tests/translator/output/function_with_deployment_preference.json @@ -24,7 +24,7 @@ "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", { - "ConfigName": "Linear10PercentEvery3Minute" + "ConfigName": "Linear10PercentEvery3Minutes" } ] }, diff --git a/tests/translator/output/function_with_deployment_preference_multiple_combinations.json b/tests/translator/output/function_with_deployment_preference_multiple_combinations.json index 925b0ceb5..774d48121 100644 --- a/tests/translator/output/function_with_deployment_preference_multiple_combinations.json +++ b/tests/translator/output/function_with_deployment_preference_multiple_combinations.json @@ -148,7 +148,7 @@ "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", { - "ConfigName": "Linear10PercentEvery2Minute" + "ConfigName": "Linear10PercentEvery2Minutes" } ] }, diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 1de9ab8e4..39cd31d5a 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -221,6 +221,8 @@ class TestTranslatorEndToEnd(TestCase): 'function_with_kmskeyarn', 'function_with_alias', 'function_with_alias_intrinsics', + 'function_with_custom_codedeploy_deployment_preference', + 'function_with_custom_conditional_codedeploy_deployment_preference', 'function_with_disabled_deployment_preference', 'function_with_deployment_preference', 'function_with_deployment_preference_all_parameters', From 2b2ea35c62f043974134efc2da808b764e274edf Mon Sep 17 00:00:00 2001 From: sullis Date: Thu, 2 May 2019 14:03:23 -0400 Subject: [PATCH 06/34] docs: update lambda_safe_deployments example to use nodejs8.10 for the PreTraffic hook (#605) --- .../src/preTrafficHook.js | 61 +++++++++---------- .../lambda_safe_deployments/src/safeTest.js | 5 +- .../lambda_safe_deployments/template.yaml | 6 +- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/examples/2016-10-31/lambda_safe_deployments/src/preTrafficHook.js b/examples/2016-10-31/lambda_safe_deployments/src/preTrafficHook.js index 40fb631c4..8e86b34a8 100644 --- a/examples/2016-10-31/lambda_safe_deployments/src/preTrafficHook.js +++ b/examples/2016-10-31/lambda_safe_deployments/src/preTrafficHook.js @@ -1,47 +1,44 @@ +// @ts-check 'use strict'; const aws = require('aws-sdk'); const codedeploy = new aws.CodeDeploy({apiVersion: '2014-10-06'}); -exports.handler = (event, context, callback) => { +exports.handler = async (event, context, callback) => { - console.log("Entering PreTraffic Hook!"); - console.log(JSON.stringify(event)); - - //Read the DeploymentId from the event payload. - var deploymentId = event.DeploymentId; - console.log(deploymentId); + console.log("Entering PreTraffic Hook!"); + console.log(JSON.stringify(event)); + + //Read the DeploymentId from the event payload. + let deploymentId = event.DeploymentId; + console.log("deploymentId=" + deploymentId); //Read the LifecycleEventHookExecutionId from the event payload - var lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId; - console.log(lifecycleEventHookExecutionId); - - /* - [Perform validation or prewarming steps here] - */ - - // Prepare the validation test results with the deploymentId and + let lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId; + console.log("lifecycleEventHookExecutionId=" + lifecycleEventHookExecutionId); + + /* + [Perform validation or prewarming steps here] + */ + + // Prepare the validation test results with the deploymentId and // the lifecycleEventHookExecutionId for AWS CodeDeploy. - var params = { + let params = { deploymentId: deploymentId, lifecycleEventHookExecutionId: lifecycleEventHookExecutionId, status: 'Succeeded' // status can be 'Succeeded' or 'Failed' }; - - // Pass AWS CodeDeploy the prepared validation test results. - codedeploy.putLifecycleEventHookExecutionStatus(params, function(err, data) { - if (err) { - // Validation failed. - console.log('Validation test failed'); - console.log(err); - console.log(data); - callback('Validation test failed'); - } else { - // Validation succeeded. - console.log('Validation test succeeded'); - callback(null, 'Validation test succeeded'); - } - }); + + try { + await codedeploy.putLifecycleEventHookExecutionStatus(params).promise(); + console.log("putLifecycleEventHookExecutionStatus done. executionStatus=[" + params.status + "]"); + return 'Validation test succeeded' + } + catch (err) { + console.log("putLifecycleEventHookExecutionStatus ERROR: " + err); + throw new Error('Validation test failed') + } + } -// See more: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#reference-appspec-file-structure-hooks-section-structure-lambda-sample-function \ No newline at end of file +// See more: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#reference-appspec-file-structure-hooks-section-structure-lambda-sample-function diff --git a/examples/2016-10-31/lambda_safe_deployments/src/safeTest.js b/examples/2016-10-31/lambda_safe_deployments/src/safeTest.js index 3b623f18f..ac3eaff1d 100644 --- a/examples/2016-10-31/lambda_safe_deployments/src/safeTest.js +++ b/examples/2016-10-31/lambda_safe_deployments/src/safeTest.js @@ -1,8 +1,9 @@ 'use strict'; -exports.handler = (event, context, callback) => { +exports.handler = async (event, context, callback) => { + console.log("Function loaded! " + context.functionName + ":" + context.functionVersion); callback(null, "Success"); -} \ No newline at end of file +} diff --git a/examples/2016-10-31/lambda_safe_deployments/template.yaml b/examples/2016-10-31/lambda_safe_deployments/template.yaml index 586824c28..211158fbc 100644 --- a/examples/2016-10-31/lambda_safe_deployments/template.yaml +++ b/examples/2016-10-31/lambda_safe_deployments/template.yaml @@ -9,7 +9,7 @@ Resources: Properties: Handler: safeTest.handler CodeUri: src/ - Runtime: nodejs6.10 + Runtime: nodejs8.10 AutoPublishAlias: live DeploymentPreference: Type: Linear10PercentEvery1Minute @@ -35,10 +35,10 @@ Resources: Action: - "lambda:InvokeFunction" Resource: !Ref safeTest.Version - Runtime: nodejs6.10 + Runtime: nodejs8.10 FunctionName: 'CodeDeployHook_preTrafficHook' DeploymentPreference: Enabled: false Environment: Variables: - CurrentVersion: !Ref safeTest.Version \ No newline at end of file + CurrentVersion: !Ref safeTest.Version From 973a187914354fd557273ece2f7909394d327d6c Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Fri, 3 May 2019 10:29:00 -0700 Subject: [PATCH 07/34] docs: add Auth to supported Api Global properties (#899) --- docs/globals.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/globals.rst b/docs/globals.rst index 07ab036ee..729ad4e46 100644 --- a/docs/globals.rst +++ b/docs/globals.rst @@ -73,6 +73,7 @@ Currently, the following resources and properties are being supported: Api: # Properties of AWS::Serverless::Api # Also works with Implicit APIs + Auth: Name: DefinitionUri: CacheClusterEnabled: From f762241b59c851eb32a6b121a99188743793d0f1 Mon Sep 17 00:00:00 2001 From: Le Stephane <5460884+lestephane@users.noreply.github.com> Date: Fri, 3 May 2019 17:33:33 +0000 Subject: [PATCH 08/34] docs: fix typo in DEVELOPMENT_GUIDE (#902) --- DEVELOPMENT_GUIDE.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DEVELOPMENT_GUIDE.rst b/DEVELOPMENT_GUIDE.rst index 51085637f..0c9c4fada 100755 --- a/DEVELOPMENT_GUIDE.rst +++ b/DEVELOPMENT_GUIDE.rst @@ -80,7 +80,7 @@ Install snakeviz `pip install snakeviz` .. code-block:: shell - python -m cProfile -o sam_profile_results bin/sam-translate.py translate --input-file=tests/translator/input/alexa_skill.yaml --output-file=cfn-template.json + python -m cProfile -o sam_profile_results bin/sam-translate.py translate --template-file=tests/translator/input/alexa_skill.yaml --output-template=cfn-template.json snakeviz sam_profile_results Verifying transforms @@ -96,7 +96,7 @@ If you make changes to the transformer and want to verify the resulting CloudFor # Transform your SAM template into a CloudFormation template # Replace "output-template.yaml" if you didn't run the package command above or specified a different path for --output-template-file - bin/sam-translate.py --input-file=output-template.yaml + bin/sam-translate.py --template-file=output-template.yaml # Deploy your transformed CloudFormation template # Replace MY_STACK_NAME with a unique name each time you deploy From 61c094b8e0b504d9291c80ab3f1dacafcbbec577 Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Fri, 3 May 2019 10:39:20 -0700 Subject: [PATCH 09/34] docs: update globals.rst (#905) --- docs/globals.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/globals.rst b/docs/globals.rst index 729ad4e46..c0878242e 100644 --- a/docs/globals.rst +++ b/docs/globals.rst @@ -91,7 +91,7 @@ Currently, the following resources and properties are being supported: SimpleTable: # Properties of AWS::Serverless::SimpleTable - SSESpecification + SSESpecification: Implicit APIs ~~~~~~~~~~~~~ From 97bacc3ae6403f10c7ca002a01dc80e6597a767f Mon Sep 17 00:00:00 2001 From: Lars Jacobsson Date: Sat, 4 May 2019 00:31:45 +0200 Subject: [PATCH 10/34] =?UTF-8?q?feat(policy-templates):=20add=20new=20pol?= =?UTF-8?q?icy=20for=20allowing=20step=20functions=20ex=E2=80=A6=20(#904)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../all_policy_templates.yaml | 3 ++ .../policy_templates.json | 28 +++++++++++++++++++ .../input/all_policy_templates.yaml | 3 ++ .../output/all_policy_templates.json | 21 ++++++++++++++ .../output/aws-cn/all_policy_templates.json | 21 ++++++++++++++ .../aws-us-gov/all_policy_templates.json | 21 ++++++++++++++ 6 files changed, 97 insertions(+) diff --git a/examples/2016-10-31/policy_templates/all_policy_templates.yaml b/examples/2016-10-31/policy_templates/all_policy_templates.yaml index ec01a6b85..9c26ad1b9 100644 --- a/examples/2016-10-31/policy_templates/all_policy_templates.yaml +++ b/examples/2016-10-31/policy_templates/all_policy_templates.yaml @@ -87,3 +87,6 @@ Resources: - FilterLogEventsPolicy: LogGroupName: name + + - StepFunctionsExecutionPolicy: + StateMachineName: name diff --git a/samtranslator/policy_templates_data/policy_templates.json b/samtranslator/policy_templates_data/policy_templates.json index 10e833d86..600fc8899 100644 --- a/samtranslator/policy_templates_data/policy_templates.json +++ b/samtranslator/policy_templates_data/policy_templates.json @@ -1562,6 +1562,34 @@ } ] } + }, + "StepFunctionsExecutionPolicy": { + "Description": "Gives permission to start a Step Functions state machine execution", + "Parameters": { + "StateMachineName": { + "Description":"The name of the state machine to execute." + } + }, + "Definition": { + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "states:StartExecution" + ], + "Resource": { + "Fn::Sub": [ + "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + { + "stateMachineName": { + "Ref": "StateMachineName" + } + } + ] + } + } + ] + } } } } diff --git a/tests/translator/input/all_policy_templates.yaml b/tests/translator/input/all_policy_templates.yaml index 4ccd5f87f..2cca6996f 100644 --- a/tests/translator/input/all_policy_templates.yaml +++ b/tests/translator/input/all_policy_templates.yaml @@ -143,3 +143,6 @@ Resources: - SSMParameterReadPolicy: ParameterName: name + + - StepFunctionsExecutionPolicy: + StateMachineName: name diff --git a/tests/translator/output/all_policy_templates.json b/tests/translator/output/all_policy_templates.json index 1c4b999ce..ef970472b 100644 --- a/tests/translator/output/all_policy_templates.json +++ b/tests/translator/output/all_policy_templates.json @@ -1215,6 +1215,27 @@ } ] } + }, + { + "PolicyName": "KitchenSinkFunctionRolePolicy49", + "PolicyDocument": { + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "states:StartExecution" + ], + "Resource": { + "Fn::Sub": [ + "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + { + "stateMachineName": "name" + } + ] + } + } + ] + } } ], "AssumeRolePolicyDocument": { diff --git a/tests/translator/output/aws-cn/all_policy_templates.json b/tests/translator/output/aws-cn/all_policy_templates.json index f908ddadf..9f54c7b85 100644 --- a/tests/translator/output/aws-cn/all_policy_templates.json +++ b/tests/translator/output/aws-cn/all_policy_templates.json @@ -1214,6 +1214,27 @@ } ] } + }, + { + "PolicyName": "KitchenSinkFunctionRolePolicy49", + "PolicyDocument": { + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "states:StartExecution" + ], + "Resource": { + "Fn::Sub": [ + "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + { + "stateMachineName": "name" + } + ] + } + } + ] + } } ], "AssumeRolePolicyDocument": { diff --git a/tests/translator/output/aws-us-gov/all_policy_templates.json b/tests/translator/output/aws-us-gov/all_policy_templates.json index de5379c63..4f665301f 100644 --- a/tests/translator/output/aws-us-gov/all_policy_templates.json +++ b/tests/translator/output/aws-us-gov/all_policy_templates.json @@ -1215,6 +1215,27 @@ } ] } + }, + { + "PolicyName": "KitchenSinkFunctionRolePolicy49", + "PolicyDocument": { + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "states:StartExecution" + ], + "Resource": { + "Fn::Sub": [ + "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + { + "stateMachineName": "name" + } + ] + } + } + ] + } } ], "AssumeRolePolicyDocument": { From 1571c334ac9c322cf2006395672f6a9fba2ac811 Mon Sep 17 00:00:00 2001 From: charliejllewellyn Date: Tue, 7 May 2019 20:05:31 +0100 Subject: [PATCH 11/34] docs: add S3 filter example to docs (#909) --- versions/2016-10-31.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/versions/2016-10-31.md b/versions/2016-10-31.md index b5f7f6f17..2c9134be9 100644 --- a/versions/2016-10-31.md +++ b/versions/2016-10-31.md @@ -409,6 +409,11 @@ Type: S3 Properties: Bucket: my-photo-bucket Events: s3:ObjectCreated:* + Filter: + S3Key: + Rules: + - Name: prefix|suffix + Value: my-prefix|my-suffix ``` #### SNS From fee6bb6d382d04c730ea07cf5859734d127f855a Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Tue, 7 May 2019 14:26:27 -0700 Subject: [PATCH 12/34] chore: bump version to 1.12.0 (#910) --- samtranslator/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samtranslator/__init__.py b/samtranslator/__init__.py index da77e85c6..666b2f71c 100644 --- a/samtranslator/__init__.py +++ b/samtranslator/__init__.py @@ -1 +1 @@ -__version__ = '1.11.0' +__version__ = '1.12.0' From d18c2fa5bc42ed3ea239249f313fa4b31fafa129 Mon Sep 17 00:00:00 2001 From: Manoj Jadhav Date: Thu, 9 May 2019 00:22:56 +0530 Subject: [PATCH 13/34] fix: fix Internal transform failure on bad Condition syntax (#908) --- samtranslator/sdk/resource.py | 12 +++++++++++- ...or_function_with_invalid_condition_name.yaml | 17 +++++++++++++++++ ...or_function_with_invalid_condition_name.json | 8 ++++++++ tests/translator/test_translator.py | 5 +++-- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 tests/translator/input/error_function_with_invalid_condition_name.yaml create mode 100644 tests/translator/output/error_function_with_invalid_condition_name.json diff --git a/samtranslator/sdk/resource.py b/samtranslator/sdk/resource.py index 07f79f5f2..e9d9ac5d0 100644 --- a/samtranslator/sdk/resource.py +++ b/samtranslator/sdk/resource.py @@ -1,4 +1,6 @@ from enum import Enum +from samtranslator.model.exceptions import InvalidDocumentException, InvalidTemplateException +from samtranslator.model.types import is_str class SamResource(object): @@ -30,7 +32,15 @@ def valid(self): :return: True, if the resource is valid """ - # As long as the type is valid. + # As long as the type is valid and type string. + # validate the condition should be string + + if self.condition: + + if not is_str()(self.condition, should_raise=False): + raise InvalidDocumentException([ + InvalidTemplateException("Every Condition member must be a string.")]) + return SamResourceType.has_value(self.type) def to_dict(self): diff --git a/tests/translator/input/error_function_with_invalid_condition_name.yaml b/tests/translator/input/error_function_with_invalid_condition_name.yaml new file mode 100644 index 000000000..c06eb329a --- /dev/null +++ b/tests/translator/input/error_function_with_invalid_condition_name.yaml @@ -0,0 +1,17 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: 'AWS::Serverless-2016-10-31' +Conditions: + MyCondition: + Fn::Equals: + - true + - false + +Resources: + ConditionFunction: + Type: 'AWS::Serverless::Function' + Condition: + Ref: MyCondition + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 diff --git a/tests/translator/output/error_function_with_invalid_condition_name.json b/tests/translator/output/error_function_with_invalid_condition_name.json new file mode 100644 index 000000000..628769ae9 --- /dev/null +++ b/tests/translator/output/error_function_with_invalid_condition_name.json @@ -0,0 +1,8 @@ +{ + "errors": [ + { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Every Condition member must be a string." + } + ], + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Every Condition member must be a string." +} diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 39cd31d5a..8a2b49248 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -252,7 +252,7 @@ class TestTranslatorEndToEnd(TestCase): 'implicit_api_with_many_conditions', 'implicit_and_explicit_api_with_conditions', 'api_with_cors_and_conditions_no_definitionbody', - 'api_with_auth_and_conditions_all_max' + 'api_with_auth_and_conditions_all_max', ], [ ("aws", "ap-southeast-1"), @@ -436,7 +436,8 @@ def _generate_new_deployment_hash(self, logical_id, dict_to_hash, rest_api_to_sw 'error_function_policy_template_with_missing_parameter', 'error_function_policy_template_invalid_value', 'error_function_with_unknown_policy_template', - 'error_function_with_invalid_policy_statement' + 'error_function_with_invalid_policy_statement', + 'error_function_with_invalid_condition_name' ]) @patch('boto3.session.Session.region_name', 'ap-southeast-1') @patch('samtranslator.plugins.application.serverless_app_plugin.ServerlessAppPlugin._sar_service_call', mock_sar_service_call) From 82f4ef7578a6fa90d283efaf70ca8903f1fa2cc8 Mon Sep 17 00:00:00 2001 From: Manoj Jadhav Date: Fri, 17 May 2019 22:35:39 +0530 Subject: [PATCH 14/34] fix: internal transform failure on path parameters (#913) --- samtranslator/swagger/swagger.py | 4 + .../global_handle_path_level_parameter.yaml | 64 ++++ .../global_handle_path_level_parameter.json | 299 ++++++++++++++++++ .../global_handle_path_level_parameter.json | 299 ++++++++++++++++++ .../global_handle_path_level_parameter.json | 283 +++++++++++++++++ tests/translator/test_translator.py | 1 + 6 files changed, 950 insertions(+) create mode 100644 tests/translator/input/global_handle_path_level_parameter.yaml create mode 100644 tests/translator/output/aws-cn/global_handle_path_level_parameter.json create mode 100644 tests/translator/output/aws-us-gov/global_handle_path_level_parameter.json create mode 100644 tests/translator/output/global_handle_path_level_parameter.json diff --git a/samtranslator/swagger/swagger.py b/samtranslator/swagger/swagger.py index f1803f33d..dc9549285 100644 --- a/samtranslator/swagger/swagger.py +++ b/samtranslator/swagger/swagger.py @@ -404,7 +404,11 @@ def set_path_default_authorizer(self, path, default_authorizer, authorizers): authorizers param. :param list authorizers: List of Authorizer configurations defined on the related Api. """ + for method_name, method in self.get_path(path).items(): + # Excluding paramters section + if method_name == "parameters": + continue self.set_method_authorizer(path, method_name, default_authorizer, authorizers, default_authorizer=default_authorizer, is_default=True) diff --git a/tests/translator/input/global_handle_path_level_parameter.yaml b/tests/translator/input/global_handle_path_level_parameter.yaml new file mode 100644 index 000000000..2bd9995fb --- /dev/null +++ b/tests/translator/input/global_handle_path_level_parameter.yaml @@ -0,0 +1,64 @@ +Globals: + Api: + Name: "some api" + CacheClusterEnabled: True + CacheClusterSize: "1.6" + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: !GetAtt MyUserPool.Arn + Variables: + SomeVar: Value + +Resources: + ImplicitApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: SomeStage + DefinitionBody: + swagger: 2.0 + info: + version: '1.0' + title: !Ref AWS::StackName + paths: + "/": + parameters: + - name: domain + in: path + description: Application domain + type: string + required: true + get: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations + responses: {} + + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/translator/output/aws-cn/global_handle_path_level_parameter.json b/tests/translator/output/aws-cn/global_handle_path_level_parameter.json new file mode 100644 index 000000000..2d6aa4753 --- /dev/null +++ b/tests/translator/output/aws-cn/global_handle_path_level_parameter.json @@ -0,0 +1,299 @@ +{ + "Resources": { + "ImplicitApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs4.3", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ImplicitApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "ImplicitApiFunctionGetHtmlPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "ExplicitApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "parameters": [ + { + "required": true, + "type": "string", + "description": "Application domain", + "name": "domain", + "in": "path" + } + ], + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "responses": {} + } + } + }, + "swagger": 2.0, + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "type": "apiKey", + "name": "Authorization", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "some api", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + } + }, + "ServerlessRestApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "CacheClusterSize": "1.6", + "Variables": { + "SomeVar": "Value" + }, + "CacheClusterEnabled": true, + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymente1212668e0" + } + } + }, + "ServerlessRestApiDeploymente1212668e0": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Description": "RestApi deployment id: e1212668e096994ab32167666f5a877bd6ac5fad", + "StageName": "Stage" + } + }, + "ExplicitApiSomeStageStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "SomeStage", + "CacheClusterSize": "1.6", + "Variables": { + "SomeVar": "Value" + }, + "CacheClusterEnabled": true, + "DeploymentId": { + "Ref": "ExplicitApiDeployment9a254aa466" + } + } + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", + "Properties": { + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] + } + }, + "ExplicitApiDeployment9a254aa466": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "Description": "RestApi deployment id: 9a254aa466c6f818951dfb6e45fde65489beb153", + "StageName": "Stage" + } + }, + "ServerlessRestApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "responses": {} + } + } + }, + "swagger": "2.0", + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "type": "apiKey", + "name": "Authorization", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "some api", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/global_handle_path_level_parameter.json b/tests/translator/output/aws-us-gov/global_handle_path_level_parameter.json new file mode 100644 index 000000000..1515aecb8 --- /dev/null +++ b/tests/translator/output/aws-us-gov/global_handle_path_level_parameter.json @@ -0,0 +1,299 @@ +{ + "Resources": { + "ImplicitApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs4.3", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ImplicitApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "ImplicitApiFunctionGetHtmlPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "ExplicitApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "parameters": [ + { + "required": true, + "type": "string", + "description": "Application domain", + "name": "domain", + "in": "path" + } + ], + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "responses": {} + } + } + }, + "swagger": 2.0, + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "type": "apiKey", + "name": "Authorization", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "some api", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + } + }, + "ServerlessRestApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "CacheClusterSize": "1.6", + "Variables": { + "SomeVar": "Value" + }, + "CacheClusterEnabled": true, + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentc969c99f9d" + } + } + }, + "ExplicitApiSomeStageStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "SomeStage", + "CacheClusterSize": "1.6", + "Variables": { + "SomeVar": "Value" + }, + "CacheClusterEnabled": true, + "DeploymentId": { + "Ref": "ExplicitApiDeployment9a254aa466" + } + } + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "ServerlessRestApiDeploymentc969c99f9d": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Description": "RestApi deployment id: c969c99f9d6b6921dff605a206e8989bdb7d1bc7", + "StageName": "Stage" + } + }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", + "Properties": { + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] + } + }, + "ExplicitApiDeployment9a254aa466": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "Description": "RestApi deployment id: 9a254aa466c6f818951dfb6e45fde65489beb153", + "StageName": "Stage" + } + }, + "ServerlessRestApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "responses": {} + } + } + }, + "swagger": "2.0", + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "type": "apiKey", + "name": "Authorization", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "some api", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + } + } + } +} diff --git a/tests/translator/output/global_handle_path_level_parameter.json b/tests/translator/output/global_handle_path_level_parameter.json new file mode 100644 index 000000000..50f9cedf6 --- /dev/null +++ b/tests/translator/output/global_handle_path_level_parameter.json @@ -0,0 +1,283 @@ +{ + "Resources": { + "ImplicitApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs4.3", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ImplicitApiFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "ImplicitApiFunctionGetHtmlPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "ExplicitApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "parameters": [ + { + "required": true, + "type": "string", + "description": "Application domain", + "name": "domain", + "in": "path" + } + ], + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "responses": {} + } + } + }, + "swagger": 2.0, + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "type": "apiKey", + "name": "Authorization", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "Name": "some api" + } + }, + "ServerlessRestApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "CacheClusterSize": "1.6", + "Variables": { + "SomeVar": "Value" + }, + "CacheClusterEnabled": true, + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentdb4b9da82a" + } + } + }, + "ServerlessRestApiDeploymentdb4b9da82a": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Description": "RestApi deployment id: db4b9da82adc6031fcd32bf3a4954485464fc009", + "StageName": "Stage" + } + }, + "ExplicitApiSomeStageStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "SomeStage", + "CacheClusterSize": "1.6", + "Variables": { + "SomeVar": "Value" + }, + "CacheClusterEnabled": true, + "DeploymentId": { + "Ref": "ExplicitApiDeployment9a254aa466" + } + } + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "MyUserPool": { + "Type": "AWS::Cognito::UserPool", + "Properties": { + "UsernameAttributes": [ + "email" + ], + "UserPoolName": "UserPoolName", + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Required": false, + "Name": "email" + } + ] + } + }, + "ExplicitApiDeployment9a254aa466": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ExplicitApi" + }, + "Description": "RestApi deployment id: 9a254aa466c6f818951dfb6e45fde65489beb153", + "StageName": "Stage" + } + }, + "ServerlessRestApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "responses": {} + } + } + }, + "swagger": "2.0", + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "type": "apiKey", + "name": "Authorization", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "Name": "some api" + } + } + } +} \ No newline at end of file diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 8a2b49248..6e1afe56b 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -237,6 +237,7 @@ class TestTranslatorEndToEnd(TestCase): 'function_with_permissions_boundary', 'function_with_policy_templates', 'function_with_sns_event_source_all_parameters', + 'global_handle_path_level_parameter', 'globals_for_function', 'globals_for_api', 'globals_for_simpletable', From f532185561e7787a7878d81803ccfaa2f9461435 Mon Sep 17 00:00:00 2001 From: Ingve Vormestrand Date: Fri, 17 May 2019 19:11:46 +0200 Subject: [PATCH 15/34] docs: update generated_resources.rst (#919) --- docs/internals/generated_resources.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internals/generated_resources.rst b/docs/internals/generated_resources.rst index 53f4fdcf1..82166eb13 100644 --- a/docs/internals/generated_resources.rst +++ b/docs/internals/generated_resources.rst @@ -5,7 +5,7 @@ CloudFormation Resources Generated By SAM :local: :backlinks: none -When you create a Serverless Function or a Serverlesss API, SAM will create additional AWS resources wire everything up. +When you create a Serverless Function or a Serverlesss API, SAM will create additional AWS resources to wire everything up. For example, when you create a ``AWS::Serverless::Function``, SAM will create a Lambda Function resource along with an IAM Role resource to give appropriate permissions for your function. This document describes all such generated resources, how they are named, and how to refer to them in your SAM template. From 6352f8a5cc0db67d53de259ef4ab7cec3c5f0775 Mon Sep 17 00:00:00 2001 From: praneetap Date: Fri, 17 May 2019 14:11:35 -0700 Subject: [PATCH 16/34] fix: invalid event type error (#918) --- samtranslator/model/sam_resources.py | 2 +- .../input/error_function_invalid_event_type.yaml | 10 ++++++++++ .../output/error_function_invalid_event_type.json | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index e20b45c8c..66008dee5 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -268,7 +268,7 @@ def _event_resources_to_link(self, resources): try: event_source = self.event_resolver.resolve_resource_type(event_dict).from_dict( self.logical_id + logical_id, event_dict, logical_id) - except TypeError as e: + except (TypeError, AttributeError) as e: raise InvalidEventException(logical_id, "{}".format(e)) event_resources[logical_id] = event_source.resources_to_link(resources) return event_resources diff --git a/tests/translator/input/error_function_invalid_event_type.yaml b/tests/translator/input/error_function_invalid_event_type.yaml index 322d9abb1..cbf2f5e8c 100644 --- a/tests/translator/input/error_function_invalid_event_type.yaml +++ b/tests/translator/input/error_function_invalid_event_type.yaml @@ -24,3 +24,13 @@ Resources: Method: get Path: / + TestFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: code/ + Handler: lambda_handler.handler + + Runtime: python3.6 + Events: + FileUploaded: + diff --git a/tests/translator/output/error_function_invalid_event_type.json b/tests/translator/output/error_function_invalid_event_type.json index 0e404b5c6..d816f28fb 100644 --- a/tests/translator/output/error_function_invalid_event_type.json +++ b/tests/translator/output/error_function_invalid_event_type.json @@ -4,5 +4,5 @@ "errorMessage": "Resource with id [FunctionApiTypeError] is invalid. Event with id [ApiEvent] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: API. Resource with id [FunctionNoEventType] is invalid. Event with id [MissingType] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: None." } ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [FunctionApiTypeError] is invalid. Event with id [ApiEvent] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: API. Resource with id [FunctionNoEventType] is invalid. Event with id [MissingType] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: None." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 3. Resource with id [FunctionApiTypeError] is invalid. Event with id [ApiEvent] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: API. Resource with id [FunctionNoEventType] is invalid. Event with id [MissingType] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: None. Resource with id [TestFunction] is invalid. Event with id [FileUploaded] is invalid. 'NoneType' object has no attribute 'get'" } From 1255690dd28e62aa0d383b898cfd546a25019130 Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Mon, 20 May 2019 14:34:27 -0700 Subject: [PATCH 17/34] chore: update requirements.txt (#928) --- docs/website/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/website/requirements.txt b/docs/website/requirements.txt index 3f5a201c0..9df3d56fe 100644 --- a/docs/website/requirements.txt +++ b/docs/website/requirements.txt @@ -6,7 +6,7 @@ CommonMark==0.5.4 docutils==0.14 idna==2.6 imagesize==0.7.1 -Jinja2==2.10 +Jinja2>=2.10.1 MarkupSafe==1.0 Pygments==2.2.0 pytz==2017.3 From 41fb86a4414af082d4840954755d8be3272254eb Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Mon, 20 May 2019 14:35:24 -0700 Subject: [PATCH 18/34] chore: update base.txt (#927) --- requirements/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/base.txt b/requirements/base.txt index 86742d26e..a1d1d6270 100755 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,5 +1,5 @@ boto3~=1.5 enum34~=1.1; python_version<"3.4" -jsonschema~=2.6 +jsonschema~=3.0 six~=1.11 From c85796fbf559933b00346545d95901d162008980 Mon Sep 17 00:00:00 2001 From: Manoj Jadhav Date: Tue, 21 May 2019 23:09:14 +0530 Subject: [PATCH 19/34] test: added test cases for semantic version check (#929) --- .../error_invalid_document_empty_semantic_version.yaml | 7 +++++++ .../error_invalid_document_empty_semantic_version.json | 8 ++++++++ tests/translator/test_translator.py | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/translator/input/error_invalid_document_empty_semantic_version.yaml create mode 100644 tests/translator/output/error_invalid_document_empty_semantic_version.json diff --git a/tests/translator/input/error_invalid_document_empty_semantic_version.yaml b/tests/translator/input/error_invalid_document_empty_semantic_version.yaml new file mode 100644 index 000000000..ec3b5bea0 --- /dev/null +++ b/tests/translator/input/error_invalid_document_empty_semantic_version.yaml @@ -0,0 +1,7 @@ +Resources: + helloworld: + Type: AWS::Serverless::Application + Properties: + Location: + ApplicationId: arn:aws:serverlessrepo:us-east-1:077246666028:applications/hello-world + SemanticVersion: diff --git a/tests/translator/output/error_invalid_document_empty_semantic_version.json b/tests/translator/output/error_invalid_document_empty_semantic_version.json new file mode 100644 index 000000000..7b228c1be --- /dev/null +++ b/tests/translator/output/error_invalid_document_empty_semantic_version.json @@ -0,0 +1,8 @@ +{ + "errors": [ + { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [helloworld] is invalid. Property 'SemanticVersion' cannot be blank." + } + ], + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [helloworld] is invalid. Property 'SemanticVersion' cannot be blank." +} \ No newline at end of file diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 6e1afe56b..cb25ddfd0 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -438,7 +438,8 @@ def _generate_new_deployment_hash(self, logical_id, dict_to_hash, rest_api_to_sw 'error_function_policy_template_invalid_value', 'error_function_with_unknown_policy_template', 'error_function_with_invalid_policy_statement', - 'error_function_with_invalid_condition_name' + 'error_function_with_invalid_condition_name', + 'error_invalid_document_empty_semantic_version' ]) @patch('boto3.session.Session.region_name', 'ap-southeast-1') @patch('samtranslator.plugins.application.serverless_app_plugin.ServerlessAppPlugin._sar_service_call', mock_sar_service_call) From 73cf9d342917976ed24ae5987ee650b3372cbe42 Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Fri, 24 May 2019 09:41:07 -0700 Subject: [PATCH 20/34] chore: update test_translator.py (#933) --- tests/translator/test_translator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index cb25ddfd0..b304df6e3 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -42,6 +42,8 @@ 'E3001', # Check for resource availability in a region. 'W7001', # Check if mappings are used. Serverless::Application uses mappings, the output CFN doesn't use them anymore. 'W1020', # Sub isn't needed if it doesn't have a variable defined. SAM leaves `!Sub` in even if it tries to resolve variables. + 'E2531', # we don't care if a runtime has been deprecated in our tests. + 'E3038', # Serverless resources- test for invalid resources. ] LINT_IGNORE_TESTS = [ From a27fa65b10fd08819167b408fef2e178ede60fda Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Wed, 29 May 2019 12:41:30 -0700 Subject: [PATCH 21/34] fix: partitionalize arn in StepFunctionsExecutionPolicy (#941) --- samtranslator/policy_templates_data/policy_templates.json | 2 +- tests/translator/output/all_policy_templates.json | 2 +- tests/translator/output/aws-cn/all_policy_templates.json | 2 +- tests/translator/output/aws-us-gov/all_policy_templates.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samtranslator/policy_templates_data/policy_templates.json b/samtranslator/policy_templates_data/policy_templates.json index 600fc8899..f15dc1308 100644 --- a/samtranslator/policy_templates_data/policy_templates.json +++ b/samtranslator/policy_templates_data/policy_templates.json @@ -1579,7 +1579,7 @@ ], "Resource": { "Fn::Sub": [ - "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", { "stateMachineName": { "Ref": "StateMachineName" diff --git a/tests/translator/output/all_policy_templates.json b/tests/translator/output/all_policy_templates.json index ef970472b..4488918b0 100644 --- a/tests/translator/output/all_policy_templates.json +++ b/tests/translator/output/all_policy_templates.json @@ -1227,7 +1227,7 @@ ], "Resource": { "Fn::Sub": [ - "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", { "stateMachineName": "name" } diff --git a/tests/translator/output/aws-cn/all_policy_templates.json b/tests/translator/output/aws-cn/all_policy_templates.json index 9f54c7b85..0bf9d3225 100644 --- a/tests/translator/output/aws-cn/all_policy_templates.json +++ b/tests/translator/output/aws-cn/all_policy_templates.json @@ -1226,7 +1226,7 @@ ], "Resource": { "Fn::Sub": [ - "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", { "stateMachineName": "name" } diff --git a/tests/translator/output/aws-us-gov/all_policy_templates.json b/tests/translator/output/aws-us-gov/all_policy_templates.json index 4f665301f..9e8386268 100644 --- a/tests/translator/output/aws-us-gov/all_policy_templates.json +++ b/tests/translator/output/aws-us-gov/all_policy_templates.json @@ -1227,7 +1227,7 @@ ], "Resource": { "Fn::Sub": [ - "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", { "stateMachineName": "name" } From fe01a9ceea16ae15fdfc2df7d2ebf6689094fa98 Mon Sep 17 00:00:00 2001 From: bbeck Date: Tue, 4 Jun 2019 21:02:22 -0600 Subject: [PATCH 22/34] added RequestParameters property to Api event source --- samtranslator/model/eventsources/push.py | 39 ++++++++++++++++++++- samtranslator/swagger/swagger.py | 43 ++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index d07cf3c78..57ff507b3 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -1,5 +1,6 @@ import copy import re +from collections import namedtuple from six import string_types from samtranslator.model import ResourceMacro, PropertyType from samtranslator.model.types import is_type, list_of, dict_of, one_of, is_str @@ -17,6 +18,9 @@ CONDITION = 'Condition' +RequestParameterProperties = namedtuple("_RequestParameterProperties", ["Required", "Caching"]) +RequestParameterProperties.__new__.__defaults__ = (False, False) + class PushEventSource(ResourceMacro): """Base class for push event sources for SAM Functions. @@ -386,7 +390,8 @@ class Api(PushEventSource): # Api Event sources must "always" be paired with a Serverless::Api 'RestApiId': PropertyType(True, is_str()), - 'Auth': PropertyType(False, is_type(dict)) + 'Auth': PropertyType(False, is_type(dict)), + 'RequestParameters': PropertyType(False, is_type(list)) } def resources_to_link(self, resources): @@ -564,6 +569,38 @@ def _add_swagger_integration(self, api, function): editor.add_auth_to_method(api=api, path=self.Path, method_name=self.Method, auth=self.Auth) + if self.RequestParameters: + + parameters = {} + for parameter in self.RequestParameters: + + if isinstance(parameter, dict): + + parameter_name, parameter_value = parameter.items()[0] + + if not re.match('method\.request\.(query|path|header)', parameter_name): + raise InvalidEventException( + self.relative_id, + "Invalid value for 'RequestParameters' property") + + if not all(key in RequestParameterProperties._fields for key in parameter_value.keys()): + raise InvalidEventException( + self.relative_id, + "Invalid value for 'RequestParameters' property") + + parameters[parameter_name] = RequestParameterProperties(**parameter_value) + + elif not isinstance(parameter, string_types): + raise InvalidEventException( + self.relative_id, + "Invalid value for 'RequestParameters' property") + + else: + parameters[parameter] = RequestParameterProperties() + + editor.add_request_parameters_to_method(path=self.Path, method_name=self.Method, + request_parameters=parameters) + api["DefinitionBody"] = editor.swagger diff --git a/samtranslator/swagger/swagger.py b/samtranslator/swagger/swagger.py index dc9549285..dcb4b180c 100644 --- a/samtranslator/swagger/swagger.py +++ b/samtranslator/swagger/swagger.py @@ -528,6 +528,49 @@ def add_gateway_responses(self, gateway_responses): for response_type, response in gateway_responses.items(): self.gateway_responses[response_type] = response.generate_swagger() + def add_request_parameters_to_method(self, path, method_name, request_parameters): + """ + Add Parameters to Swagger. + + :param string path: Path name + :param string method_name: Method name + :param dict request_parameters: Dictionary of Parameters + :return: + """ + + normalized_method_name = self._normalize_method_name(method_name) + # It is possible that the method could have two definitions in a Fn::If block. + for method_definition in self.get_method_contents(self.get_path(path)[normalized_method_name]): + + # If no integration given, then we don't need to process this definition (could be AWS::NoValue) + if not self.method_definition_has_integration(method_definition): + continue + + existing_parameters = method_definition.get('parameters', []) + + for parameter_name, parameter_settings in request_parameters.items(): + + location_name = parameter_name.replace('method.request.', '') + location, name = location_name.split('.') + + parameter = { + 'in': location, + 'name': name, + 'required': parameter_settings.Required, + 'type': 'string' + } + + existing_parameters.append(parameter) + + if parameter_settings.Caching: + + integration = method_definition[self._X_APIGW_INTEGRATION] + cache_parameters = integration.get('cacheKeyParameters', []) + cache_parameters.append(parameter_name) + integration['cacheKeyParameters'] = cache_parameters + + method_definition['parameters'] = existing_parameters + @property def swagger(self): """ From 7dacb5f39e5c0c0c4951a04519c8b932b5cebccd Mon Sep 17 00:00:00 2001 From: bbeck Date: Tue, 4 Jun 2019 21:22:47 -0600 Subject: [PATCH 23/34] switch namedtuple to dictionary with default values --- samtranslator/model/eventsources/push.py | 17 ++++++++++++----- samtranslator/swagger/swagger.py | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index 57ff507b3..b51c7447f 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -18,8 +18,7 @@ CONDITION = 'Condition' -RequestParameterProperties = namedtuple("_RequestParameterProperties", ["Required", "Caching"]) -RequestParameterProperties.__new__.__defaults__ = (False, False) +RequestParameterProperties = ["Required", "Caching"] class PushEventSource(ResourceMacro): @@ -571,6 +570,11 @@ def _add_swagger_integration(self, api, function): if self.RequestParameters: + default_value = { + 'Required': False, + 'Caching': False + } + parameters = {} for parameter in self.RequestParameters: @@ -583,12 +587,15 @@ def _add_swagger_integration(self, api, function): self.relative_id, "Invalid value for 'RequestParameters' property") - if not all(key in RequestParameterProperties._fields for key in parameter_value.keys()): + if not all(key in RequestParameterProperties for key in parameter_value.keys()): raise InvalidEventException( self.relative_id, "Invalid value for 'RequestParameters' property") - parameters[parameter_name] = RequestParameterProperties(**parameter_value) + settings = default_value.copy() + settings.update(parameter_value) + + parameters[parameter_name] = settings elif not isinstance(parameter, string_types): raise InvalidEventException( @@ -596,7 +603,7 @@ def _add_swagger_integration(self, api, function): "Invalid value for 'RequestParameters' property") else: - parameters[parameter] = RequestParameterProperties() + parameters[parameter] = default_value.copy() editor.add_request_parameters_to_method(path=self.Path, method_name=self.Method, request_parameters=parameters) diff --git a/samtranslator/swagger/swagger.py b/samtranslator/swagger/swagger.py index dcb4b180c..c5c5aff2e 100644 --- a/samtranslator/swagger/swagger.py +++ b/samtranslator/swagger/swagger.py @@ -556,13 +556,13 @@ def add_request_parameters_to_method(self, path, method_name, request_parameters parameter = { 'in': location, 'name': name, - 'required': parameter_settings.Required, + 'required': parameter_settings['Required'], 'type': 'string' } existing_parameters.append(parameter) - if parameter_settings.Caching: + if parameter_settings['Caching']: integration = method_definition[self._X_APIGW_INTEGRATION] cache_parameters = integration.get('cacheKeyParameters', []) From 5ca3afdffd10fca05c42637469d22a16f7c0c03f Mon Sep 17 00:00:00 2001 From: bbeck Date: Tue, 4 Jun 2019 21:26:45 -0600 Subject: [PATCH 24/34] removed unnecessary import --- samtranslator/model/eventsources/push.py | 1 - 1 file changed, 1 deletion(-) diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index b51c7447f..241e65411 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -1,6 +1,5 @@ import copy import re -from collections import namedtuple from six import string_types from samtranslator.model import ResourceMacro, PropertyType from samtranslator.model.types import is_type, list_of, dict_of, one_of, is_str From 1941f5a0995545e47df6e22c684aca94e5916fe6 Mon Sep 17 00:00:00 2001 From: bbeck Date: Tue, 4 Jun 2019 21:48:38 -0600 Subject: [PATCH 25/34] added swagger tests --- tests/swagger/test_swagger.py | 139 ++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/tests/swagger/test_swagger.py b/tests/swagger/test_swagger.py index 388209213..b7492246d 100644 --- a/tests/swagger/test_swagger.py +++ b/tests/swagger/test_swagger.py @@ -789,3 +789,142 @@ def test_must_work_on_valid_values(self, swagger): ]) def test_must_fail_for_invalid_values(self, data, case): self.assertFalse(SwaggerEditor.is_valid(data), "Swagger dictionary with {} must not be valid".format(case)) + + +class TestSwaggerEditor_add_request_parameter_to_method(TestCase): + + def setUp(self): + self.original_swagger = { + "swagger": "2.0", + "paths": { + "/foo": { + 'get': { + 'x-amazon-apigateway-integration': { + 'test': 'must have integration' + } + } + } + } + } + + self.editor = SwaggerEditor(self.original_swagger) + + def test_must_add_parameter_to_method_with_required_and_caching_true(self): + + parameters = { + 'method.request.header.Authorization': { + 'Required': True, + 'Caching': True + } + } + + self.editor.add_request_parameters_to_method('/foo', 'get', parameters) + + expected_parameters = [ + { + 'in': 'header', + 'required': True, + 'name': 'Authorization', + 'type': 'string' + } + ] + + method_swagger = self.editor.swagger['paths']['/foo']['get'] + + self.assertEqual(expected_parameters, method_swagger['parameters']) + self.assertEqual(['method.request.header.Authorization'], method_swagger[_X_INTEGRATION]['cacheKeyParameters']) + + def test_must_add_parameter_to_method_with_required_and_caching_false(self): + + parameters = { + 'method.request.header.Authorization': { + 'Required': False, + 'Caching': False + } + } + + self.editor.add_request_parameters_to_method('/foo', 'get', parameters) + + expected_parameters = [ + { + 'in': 'header', + 'required': False, + 'name': 'Authorization', + 'type': 'string' + } + ] + + method_swagger = self.editor.swagger['paths']['/foo']['get'] + + self.assertEqual(expected_parameters, method_swagger['parameters']) + self.assertNotIn('cacheKeyParameters', method_swagger[_X_INTEGRATION].keys()) + + def test_must_add_parameter_to_method_with_existing_parameters(self): + + original_swagger = { + "swagger": "2.0", + "paths": { + "/foo": { + 'get': { + 'x-amazon-apigateway-integration': { + 'test': 'must have integration' + }, + 'parameters': [{'test': 'existing parameter'}] + } + } + } + } + + editor = SwaggerEditor(original_swagger) + + parameters = { + 'method.request.header.Authorization': { + 'Required': False, + 'Caching': False + } + } + + editor.add_request_parameters_to_method('/foo', 'get', parameters) + + expected_parameters = [ + { + 'test': 'existing parameter' + }, + { + 'in': 'header', + 'required': False, + 'name': 'Authorization', + 'type': 'string' + } + ] + + method_swagger = editor.swagger['paths']['/foo']['get'] + + self.assertEqual(expected_parameters, method_swagger['parameters']) + self.assertNotIn('cacheKeyParameters', method_swagger[_X_INTEGRATION].keys()) + + def test_must_not_add_parameter_to_method_without_integration(self): + original_swagger = { + "swagger": "2.0", + "paths": { + "/foo": { + 'get': {} + } + } + } + + editor = SwaggerEditor(original_swagger) + + parameters = { + 'method.request.header.Authorization': { + 'Required': True, + 'Caching': True + } + } + + editor.add_request_parameters_to_method('/foo', 'get', parameters) + + expected = {} + + self.assertEqual(expected, editor.swagger['paths']['/foo']['get']) + From 41d4b2ee47535eb1ec600d082275df8d29397f66 Mon Sep 17 00:00:00 2001 From: bbeck Date: Wed, 5 Jun 2019 12:26:43 -0600 Subject: [PATCH 26/34] added end to end tests for request parameters --- samtranslator/model/eventsources/push.py | 8 +- ...r_function_invalid_request_parameters.yaml | 109 ++++++ .../function_with_request_parameters.yaml | 40 +++ .../function_with_request_parameters.json | 319 ++++++++++++++++++ .../function_with_request_parameters.json | 319 ++++++++++++++++++ ...r_function_invalid_request_parameters.json | 3 + .../function_with_request_parameters.json | 303 +++++++++++++++++ tests/translator/test_translator.py | 2 + 8 files changed, 1102 insertions(+), 1 deletion(-) create mode 100644 tests/translator/input/error_function_invalid_request_parameters.yaml create mode 100644 tests/translator/input/function_with_request_parameters.yaml create mode 100644 tests/translator/output/aws-cn/function_with_request_parameters.json create mode 100644 tests/translator/output/aws-us-gov/function_with_request_parameters.json create mode 100644 tests/translator/output/error_function_invalid_request_parameters.json create mode 100644 tests/translator/output/function_with_request_parameters.json diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index 241e65411..7556a8ccd 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -586,7 +586,8 @@ def _add_swagger_integration(self, api, function): self.relative_id, "Invalid value for 'RequestParameters' property") - if not all(key in RequestParameterProperties for key in parameter_value.keys()): + if not isinstance(parameter_value, dict) or not all(key in RequestParameterProperties + for key in parameter_value.keys()): raise InvalidEventException( self.relative_id, "Invalid value for 'RequestParameters' property") @@ -602,6 +603,11 @@ def _add_swagger_integration(self, api, function): "Invalid value for 'RequestParameters' property") else: + if not re.match('method\.request\.(query|path|header)', parameter): + raise InvalidEventException( + self.relative_id, + "Invalid value for 'RequestParameters' property") + parameters[parameter] = default_value.copy() editor.add_request_parameters_to_method(path=self.Path, method_name=self.Method, diff --git a/tests/translator/input/error_function_invalid_request_parameters.yaml b/tests/translator/input/error_function_invalid_request_parameters.yaml new file mode 100644 index 000000000..16f2fa68b --- /dev/null +++ b/tests/translator/input/error_function_invalid_request_parameters.yaml @@ -0,0 +1,109 @@ +Resources: + + InvalidNameStringParameterFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + RequestParameters: + - Authorization + + InvalidNameLocationStringParameterFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + RequestParameters: + - method.request.invalid.Authorization + + InvalidNameDictParameterFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + RequestParameters: + - Authorization: + Required: true + + InvalidNameLocationDictParameterFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + RequestParameters: + - method.request.invalid.Authorization: + Required: true + + ParameterNotDictFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + RequestParameters: + - method.request.header.Authorization: notadict + + ParameterInvalidFieldFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + RequestParameters: + - method.request.header.Authorization: + invalid: field + + ParameterNotDictOrStringFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + RequestParameters: + - [Authorization] diff --git a/tests/translator/input/function_with_request_parameters.yaml b/tests/translator/input/function_with_request_parameters.yaml new file mode 100644 index 000000000..ad281159d --- /dev/null +++ b/tests/translator/input/function_with_request_parameters.yaml @@ -0,0 +1,40 @@ +Resources: + + Api: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + + ApiParameterFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Events: + GetHtml: + Type: Api + Properties: + RestApiId: Api + Path: / + Method: get + RequestParameters: + - method.request.header.Authorization: + Required: True + Caching: True + + NoApiParameterFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + RequestParameters: + - method.request.query.type + - method.request.path.id diff --git a/tests/translator/output/aws-cn/function_with_request_parameters.json b/tests/translator/output/aws-cn/function_with_request_parameters.json new file mode 100644 index 000000000..1bb9bb4ea --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_request_parameters.json @@ -0,0 +1,319 @@ +{ + "Resources": { + "ApiParameterFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "ApiParameterFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs4.3", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "NoApiParameterFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "ApiParameterFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "NoApiParameterFunctionGetHtmlPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "NoApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "NoApiParameterFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "NoApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "ServerlessRestApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment3c9bb096ad" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + } + }, + "ApiDeploymentd779e9df57": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "Api" + }, + "Description": "RestApi deployment id: d779e9df577321942ace63ca5592fbc8ba6fa9ec", + "StageName": "Stage" + } + }, + "Api": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiParameterFunction.Arn}/invocations" + }, + "cacheKeyParameters": [ + "method.request.header.Authorization" + ] + }, + "responses": {}, + "parameters": [ + { + "required": true, + "type": "string", + "name": "Authorization", + "in": "header" + } + ] + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + } + }, + "ApiParameterFunctionGetHtmlPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "*", + "__ApiId__": "Api" + } + ] + } + } + }, + "ApiParameterFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": "Api" + } + ] + } + } + }, + "ApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "ApiDeploymentd779e9df57" + }, + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Prod" + } + }, + "ServerlessRestApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NoApiParameterFunction.Arn}/invocations" + } + }, + "responses": {}, + "parameters": [ + { + "required": false, + "type": "string", + "name": "id", + "in": "path" + }, + { + "required": false, + "type": "string", + "name": "type", + "in": "query" + } + ] + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + } + }, + "NoApiParameterFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "NoApiParameterFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs4.3", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ServerlessRestApiDeployment3c9bb096ad": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Description": "RestApi deployment id: 3c9bb096ad422fa382c7f05ea5fb9eb4c67a8f38", + "StageName": "Stage" + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/function_with_request_parameters.json b/tests/translator/output/aws-us-gov/function_with_request_parameters.json new file mode 100644 index 000000000..840018ac0 --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_request_parameters.json @@ -0,0 +1,319 @@ +{ + "Resources": { + "ApiParameterFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "ApiParameterFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs4.3", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "NoApiParameterFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "ApiDeployment5e67eb8be3": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "Api" + }, + "Description": "RestApi deployment id: 5e67eb8be3d6956bbeadcb3ffdae9abcac90f01e", + "StageName": "Stage" + } + }, + "ApiParameterFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "NoApiParameterFunctionGetHtmlPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "NoApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "NoApiParameterFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "NoApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "ServerlessRestApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymente89a793d7f" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + } + }, + "Api": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiParameterFunction.Arn}/invocations" + }, + "cacheKeyParameters": [ + "method.request.header.Authorization" + ] + }, + "responses": {}, + "parameters": [ + { + "required": true, + "type": "string", + "name": "Authorization", + "in": "header" + } + ] + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + } + }, + "ApiParameterFunctionGetHtmlPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "*", + "__ApiId__": "Api" + } + ] + } + } + }, + "ApiParameterFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": "Api" + } + ] + } + } + }, + "ServerlessRestApiDeploymente89a793d7f": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Description": "RestApi deployment id: e89a793d7f3e12a4d9caa193350f172c769fa81c", + "StageName": "Stage" + } + }, + "ApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "ApiDeployment5e67eb8be3" + }, + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Prod" + } + }, + "ServerlessRestApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NoApiParameterFunction.Arn}/invocations" + } + }, + "responses": {}, + "parameters": [ + { + "required": false, + "type": "string", + "name": "id", + "in": "path" + }, + { + "required": false, + "type": "string", + "name": "type", + "in": "query" + } + ] + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + } + }, + "NoApiParameterFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "NoApiParameterFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs4.3", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/error_function_invalid_request_parameters.json b/tests/translator/output/error_function_invalid_request_parameters.json new file mode 100644 index 000000000..a79374026 --- /dev/null +++ b/tests/translator/output/error_function_invalid_request_parameters.json @@ -0,0 +1,3 @@ +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 6. Resource with id [InvalidNameDictParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property Resource with id [InvalidNameLocationStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property Resource with id [InvalidNameStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property Resource with id [ParameterInvalidFieldFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property Resource with id [ParameterNotDictFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property Resource with id [ParameterNotDictOrStringFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property" +} \ No newline at end of file diff --git a/tests/translator/output/function_with_request_parameters.json b/tests/translator/output/function_with_request_parameters.json new file mode 100644 index 000000000..41ef6dbc2 --- /dev/null +++ b/tests/translator/output/function_with_request_parameters.json @@ -0,0 +1,303 @@ +{ + "Resources": { + "ApiParameterFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "ApiParameterFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs4.3", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "NoApiParameterFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "ApiParameterFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "NoApiParameterFunctionGetHtmlPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "NoApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "NoApiParameterFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "NoApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + } + }, + "ServerlessRestApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentd87b63187d" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + } + }, + "ApiDeploymentb45131471b": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "Api" + }, + "Description": "RestApi deployment id: b45131471b437edb4cca88487357f3bfbcf59866", + "StageName": "Stage" + } + }, + "ServerlessRestApiDeploymentd87b63187d": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Description": "RestApi deployment id: d87b63187df8e37b3658e755490457f1fb5426cb", + "StageName": "Stage" + } + }, + "Api": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiParameterFunction.Arn}/invocations" + }, + "cacheKeyParameters": [ + "method.request.header.Authorization" + ] + }, + "responses": {}, + "parameters": [ + { + "required": true, + "type": "string", + "name": "Authorization", + "in": "header" + } + ] + } + } + }, + "swagger": "2.0" + } + } + }, + "ApiParameterFunctionGetHtmlPermissionTest": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "*", + "__ApiId__": "Api" + } + ] + } + } + }, + "ApiParameterFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:invokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "ApiParameterFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__Stage__": "Prod", + "__ApiId__": "Api" + } + ] + } + } + }, + "ApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "ApiDeploymentb45131471b" + }, + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Prod" + } + }, + "ServerlessRestApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NoApiParameterFunction.Arn}/invocations" + } + }, + "responses": {}, + "parameters": [ + { + "required": false, + "type": "string", + "name": "id", + "in": "path" + }, + { + "required": false, + "type": "string", + "name": "type", + "in": "query" + } + ] + } + } + }, + "swagger": "2.0" + } + } + }, + "NoApiParameterFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.gethtml", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Role": { + "Fn::GetAtt": [ + "NoApiParameterFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs4.3", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index b304df6e3..32cc5d5f3 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -239,6 +239,7 @@ class TestTranslatorEndToEnd(TestCase): 'function_with_permissions_boundary', 'function_with_policy_templates', 'function_with_sns_event_source_all_parameters', + 'function_with_request_parameters', 'global_handle_path_level_parameter', 'globals_for_function', 'globals_for_api', @@ -416,6 +417,7 @@ def _generate_new_deployment_hash(self, logical_id, dict_to_hash, rest_api_to_sw 'error_function_no_runtime', 'error_function_with_deployment_preference_missing_alias', 'error_function_with_invalid_deployment_preference_hook_property', + 'error_function_invalid_request_parameters', 'error_invalid_logical_id', 'error_layer_invalid_properties', 'error_missing_queue', From 9e21f6b8eacbb9c18c8b39e8a5eb19599d30b512 Mon Sep 17 00:00:00 2001 From: bbeck Date: Fri, 7 Jun 2019 10:08:31 -0600 Subject: [PATCH 27/34] fix get first request parameter after test failure --- samtranslator/model/eventsources/push.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index 7556a8ccd..d65d638ca 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -579,7 +579,7 @@ def _add_swagger_integration(self, api, function): if isinstance(parameter, dict): - parameter_name, parameter_value = parameter.items()[0] + parameter_name, parameter_value = next(iter(parameter.items())) if not re.match('method\.request\.(query|path|header)', parameter_name): raise InvalidEventException( From 4078aa4d159e913d79cbaadde743f5dbde9aa4a3 Mon Sep 17 00:00:00 2001 From: bbeck Date: Fri, 7 Jun 2019 12:23:01 -0600 Subject: [PATCH 28/34] changed dictionary to list to preserve order of parameters --- samtranslator/model/eventsources/push.py | 10 ++-- samtranslator/swagger/swagger.py | 9 ++-- tests/swagger/test_swagger.py | 44 ++++++++-------- .../function_with_request_parameters.json | 30 +++++------ .../function_with_request_parameters.json | 30 +++++------ .../function_with_request_parameters.json | 50 +++++++++---------- 6 files changed, 87 insertions(+), 86 deletions(-) diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index d65d638ca..fe4659370 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -574,7 +574,7 @@ def _add_swagger_integration(self, api, function): 'Caching': False } - parameters = {} + parameters = [] for parameter in self.RequestParameters: if isinstance(parameter, dict): @@ -594,8 +594,9 @@ def _add_swagger_integration(self, api, function): settings = default_value.copy() settings.update(parameter_value) + settings.update({'Name': parameter_name}) - parameters[parameter_name] = settings + parameters.append(settings) elif not isinstance(parameter, string_types): raise InvalidEventException( @@ -608,7 +609,10 @@ def _add_swagger_integration(self, api, function): self.relative_id, "Invalid value for 'RequestParameters' property") - parameters[parameter] = default_value.copy() + settings = default_value.copy() + settings.update({'Name': parameter}) + + parameters.append(settings) editor.add_request_parameters_to_method(path=self.Path, method_name=self.Method, request_parameters=parameters) diff --git a/samtranslator/swagger/swagger.py b/samtranslator/swagger/swagger.py index 73366eace..fd4b7c9ff 100644 --- a/samtranslator/swagger/swagger.py +++ b/samtranslator/swagger/swagger.py @@ -535,7 +535,7 @@ def add_request_parameters_to_method(self, path, method_name, request_parameters :param string path: Path name :param string method_name: Method name - :param dict request_parameters: Dictionary of Parameters + :param list request_parameters: Dictionary of Parameters :return: """ @@ -549,21 +549,22 @@ def add_request_parameters_to_method(self, path, method_name, request_parameters existing_parameters = method_definition.get('parameters', []) - for parameter_name, parameter_settings in request_parameters.items(): + for request_parameter in request_parameters: + parameter_name = request_parameter['Name'] location_name = parameter_name.replace('method.request.', '') location, name = location_name.split('.') parameter = { 'in': location, 'name': name, - 'required': parameter_settings['Required'], + 'required': request_parameter['Required'], 'type': 'string' } existing_parameters.append(parameter) - if parameter_settings['Caching']: + if request_parameter['Caching']: integration = method_definition[self._X_APIGW_INTEGRATION] cache_parameters = integration.get('cacheKeyParameters', []) diff --git a/tests/swagger/test_swagger.py b/tests/swagger/test_swagger.py index 5dfb316c2..b1ed01438 100644 --- a/tests/swagger/test_swagger.py +++ b/tests/swagger/test_swagger.py @@ -849,12 +849,11 @@ def setUp(self): def test_must_add_parameter_to_method_with_required_and_caching_true(self): - parameters = { - 'method.request.header.Authorization': { - 'Required': True, - 'Caching': True - } - } + parameters = [{ + 'Name': 'method.request.header.Authorization', + 'Required': True, + 'Caching': True + }] self.editor.add_request_parameters_to_method('/foo', 'get', parameters) @@ -874,12 +873,11 @@ def test_must_add_parameter_to_method_with_required_and_caching_true(self): def test_must_add_parameter_to_method_with_required_and_caching_false(self): - parameters = { - 'method.request.header.Authorization': { - 'Required': False, - 'Caching': False - } - } + parameters = [{ + 'Name': 'method.request.header.Authorization', + 'Required': False, + 'Caching': False + }] self.editor.add_request_parameters_to_method('/foo', 'get', parameters) @@ -915,12 +913,11 @@ def test_must_add_parameter_to_method_with_existing_parameters(self): editor = SwaggerEditor(original_swagger) - parameters = { - 'method.request.header.Authorization': { - 'Required': False, - 'Caching': False - } - } + parameters = [{ + 'Name': 'method.request.header.Authorization', + 'Required': False, + 'Caching': False + }] editor.add_request_parameters_to_method('/foo', 'get', parameters) @@ -953,12 +950,11 @@ def test_must_not_add_parameter_to_method_without_integration(self): editor = SwaggerEditor(original_swagger) - parameters = { - 'method.request.header.Authorization': { - 'Required': True, - 'Caching': True - } - } + parameters = [{ + 'Name': 'method.request.header.Authorization', + 'Required': True, + 'Caching': True + }] editor.add_request_parameters_to_method('/foo', 'get', parameters) diff --git a/tests/translator/output/aws-cn/function_with_request_parameters.json b/tests/translator/output/aws-cn/function_with_request_parameters.json index 1bb9bb4ea..d49468fc6 100644 --- a/tests/translator/output/aws-cn/function_with_request_parameters.json +++ b/tests/translator/output/aws-cn/function_with_request_parameters.json @@ -47,6 +47,16 @@ } } }, + "ServerlessRestApiDeployment4e9e7f13b1": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Description": "RestApi deployment id: 4e9e7f13b1c53469a304456bc133a9703a2c62f1", + "StageName": "Stage" + } + }, "ApiParameterFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { @@ -117,7 +127,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "ServerlessRestApiDeployment3c9bb096ad" + "Ref": "ServerlessRestApiDeployment4e9e7f13b1" }, "RestApiId": { "Ref": "ServerlessRestApi" @@ -257,14 +267,14 @@ { "required": false, "type": "string", - "name": "id", - "in": "path" + "name": "type", + "in": "query" }, { "required": false, "type": "string", - "name": "type", - "in": "query" + "name": "id", + "in": "path" } ] } @@ -304,16 +314,6 @@ } ] } - }, - "ServerlessRestApiDeployment3c9bb096ad": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 3c9bb096ad422fa382c7f05ea5fb9eb4c67a8f38", - "StageName": "Stage" - } } } } \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/function_with_request_parameters.json b/tests/translator/output/aws-us-gov/function_with_request_parameters.json index 840018ac0..19aeec3c8 100644 --- a/tests/translator/output/aws-us-gov/function_with_request_parameters.json +++ b/tests/translator/output/aws-us-gov/function_with_request_parameters.json @@ -47,6 +47,16 @@ } } }, + "ServerlessRestApiDeploymentbb31ea9793": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Description": "RestApi deployment id: bb31ea9793b7e80d8ef62bd1054ea3f819ceb563", + "StageName": "Stage" + } + }, "ApiDeployment5e67eb8be3": { "Type": "AWS::ApiGateway::Deployment", "Properties": { @@ -127,7 +137,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "ServerlessRestApiDeploymente89a793d7f" + "Ref": "ServerlessRestApiDeploymentbb31ea9793" }, "RestApiId": { "Ref": "ServerlessRestApi" @@ -220,16 +230,6 @@ } } }, - "ServerlessRestApiDeploymente89a793d7f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: e89a793d7f3e12a4d9caa193350f172c769fa81c", - "StageName": "Stage" - } - }, "ApiProdStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { @@ -267,14 +267,14 @@ { "required": false, "type": "string", - "name": "id", - "in": "path" + "name": "type", + "in": "query" }, { "required": false, "type": "string", - "name": "type", - "in": "query" + "name": "id", + "in": "path" } ] } diff --git a/tests/translator/output/function_with_request_parameters.json b/tests/translator/output/function_with_request_parameters.json index 41ef6dbc2..df2e35f82 100644 --- a/tests/translator/output/function_with_request_parameters.json +++ b/tests/translator/output/function_with_request_parameters.json @@ -47,6 +47,16 @@ } } }, + "ServerlessRestApiDeployment498b4bac69": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Description": "RestApi deployment id: 498b4bac6915ecf6514efc3763418babae239612", + "StageName": "Stage" + } + }, "ApiParameterFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { @@ -117,7 +127,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentd87b63187d" + "Ref": "ServerlessRestApiDeployment498b4bac69" }, "RestApiId": { "Ref": "ServerlessRestApi" @@ -125,26 +135,6 @@ "StageName": "Prod" } }, - "ApiDeploymentb45131471b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "Api" - }, - "Description": "RestApi deployment id: b45131471b437edb4cca88487357f3bfbcf59866", - "StageName": "Stage" - } - }, - "ServerlessRestApiDeploymentd87b63187d": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: d87b63187df8e37b3658e755490457f1fb5426cb", - "StageName": "Stage" - } - }, "Api": { "Type": "AWS::ApiGateway::RestApi", "Properties": { @@ -222,6 +212,16 @@ } } }, + "ApiDeploymentb45131471b": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "Api" + }, + "Description": "RestApi deployment id: b45131471b437edb4cca88487357f3bfbcf59866", + "StageName": "Stage" + } + }, "ApiProdStage": { "Type": "AWS::ApiGateway::Stage", "Properties": { @@ -259,14 +259,14 @@ { "required": false, "type": "string", - "name": "id", - "in": "path" + "name": "type", + "in": "query" }, { "required": false, "type": "string", - "name": "type", - "in": "query" + "name": "id", + "in": "path" } ] } From a6736e919c1c25ff235063b0d144dfad7aace381 Mon Sep 17 00:00:00 2001 From: bbeck Date: Wed, 19 Jun 2019 10:57:58 -0600 Subject: [PATCH 29/34] added request parameters example --- .../function_request_parameters/src/index.js | 6 ++++ .../function_request_parameters/template.yaml | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 examples/2016-10-31/function_request_parameters/src/index.js create mode 100644 examples/2016-10-31/function_request_parameters/template.yaml diff --git a/examples/2016-10-31/function_request_parameters/src/index.js b/examples/2016-10-31/function_request_parameters/src/index.js new file mode 100644 index 000000000..7f7a6018d --- /dev/null +++ b/examples/2016-10-31/function_request_parameters/src/index.js @@ -0,0 +1,6 @@ +exports.handler = function(event, context, callback) { + callback(null, { + "statusCode": 200, + "body": "hello world" + }); +} diff --git a/examples/2016-10-31/function_request_parameters/template.yaml b/examples/2016-10-31/function_request_parameters/template.yaml new file mode 100644 index 000000000..969d32213 --- /dev/null +++ b/examples/2016-10-31/function_request_parameters/template.yaml @@ -0,0 +1,28 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: Simple API Endpoint configured using Swagger specified inline and backed by a Lambda function +Resources: + + MyLambdaFunction: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: nodejs8.10 + CodeUri: s3://gbdx-build-artifacts/bbeck-test/423f9056eb70d25480852fc472b43dd5 #src/ + Events: + GetApi: + Type: Api + Properties: + Path: /post + Method: POST + RequestParameters: + - method.request.header.Authorization: + Required: True + Caching: True + - method.request.query.type + +Outputs: + + ApiURL: + Description: "API endpoint URL for Prod environment" + Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/prod/get" \ No newline at end of file From 1e5a86243555d62e41a0536c1543b617efb0b79f Mon Sep 17 00:00:00 2001 From: bbeck Date: Wed, 19 Jun 2019 10:58:41 -0600 Subject: [PATCH 30/34] fixed CodeUri --- examples/2016-10-31/function_request_parameters/template.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/2016-10-31/function_request_parameters/template.yaml b/examples/2016-10-31/function_request_parameters/template.yaml index 969d32213..76d21b5b3 100644 --- a/examples/2016-10-31/function_request_parameters/template.yaml +++ b/examples/2016-10-31/function_request_parameters/template.yaml @@ -8,7 +8,7 @@ Resources: Properties: Handler: index.handler Runtime: nodejs8.10 - CodeUri: s3://gbdx-build-artifacts/bbeck-test/423f9056eb70d25480852fc472b43dd5 #src/ + CodeUri: src/ Events: GetApi: Type: Api From 9e33bb1d22754cfb55dfc9d210b35d23a9330a50 Mon Sep 17 00:00:00 2001 From: bbeck Date: Wed, 19 Jun 2019 11:11:32 -0600 Subject: [PATCH 31/34] updated documentation for request parameters --- versions/2016-10-31.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/versions/2016-10-31.md b/versions/2016-10-31.md index 9493abade..275aa26a8 100644 --- a/versions/2016-10-31.md +++ b/versions/2016-10-31.md @@ -528,6 +528,7 @@ Method | `string` | **Required.** HTTP method for which this function is invoked RestApiId | `string` | Identifier of a RestApi resource which MUST contain an operation with the given path and method. Typically, this is set to [reference](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html) an `AWS::Serverless::Api` resource defined in this template. If not defined, a default `AWS::Serverless::Api` resource is created using a generated Swagger document contains a union of all paths and methods defined by `Api` events defined in this template that do not specify a RestApiId. Auth | [Function Auth Object](#function-auth-object) | Auth configuration for this specific Api+Path+Method. Useful for overriding the API's `DefaultAuthorizer` or setting auth config on an individual path when no `DefaultAuthorizer` is specified. RequestModel | [Function Request Model Object](#function-request-model-object) | Request model configuration for this specific Api+Path+Method. +RequestParameters | List of `string` | List of [Function Request Parameter Object](#function-request-parameter-object) | Request parameters configuration for this specific Api+Path+Method. All parameter names must start with `method.request` and must be limited to `method.request.header`, `method.request.query`, or `method.request.path`. If a parameter is a `string` and NOT a [Function Request Parameter Object](#function-request-parameter-object) then `Required` and `Caching` will default to `False`. ##### Example: Api event source object @@ -700,6 +701,7 @@ Properties: - [API Auth Object](#api-auth-object) - [Function Auth Object](#function-auth-object) - [Function Request Model Object](#function-request-model-object) +- [Function Request Parameter Object](#function-request-parameter-object) - [Gateway Response Object](#gateway-response-object) #### S3 Location Object @@ -845,6 +847,16 @@ RequestModel: Required: true # OPTIONAL; boolean ``` +#### Function Request Parameter Object + +Configure Request Parameter for a specific Api+Path+Method. + +```yaml +- method.request.header.Authorization: + Required: True + Caching: True +``` + #### Gateway Response Object Configure Gateway Responses on APIs. These are associated with the ID of a Gateway Response [response type][]. From c1b7b35345d1c567bf5b2322d5561a8d48cac19e Mon Sep 17 00:00:00 2001 From: bbeck Date: Mon, 29 Jul 2019 16:26:06 -0600 Subject: [PATCH 32/34] updated error messages for request parameters --- samtranslator/model/eventsources/push.py | 21 +++++++++++-------- ...r_function_invalid_request_parameters.json | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index a124ae0c6..cad4c8ccc 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -627,13 +627,15 @@ def _add_swagger_integration(self, api, function): if not re.match('method\.request\.(query|path|header)', parameter_name): raise InvalidEventException( self.relative_id, - "Invalid value for 'RequestParameters' property") + "Invalid value for 'RequestParameters' property. Keys must be in the format " + "'method.request.[query|path|header].{value}', e.g 'method.request.header.Authorization'.") if not isinstance(parameter_value, dict) or not all(key in RequestParameterProperties for key in parameter_value.keys()): raise InvalidEventException( self.relative_id, - "Invalid value for 'RequestParameters' property") + "Invalid value for 'RequestParameters' property. Values must be an object, " + "e.g { Required: true, Caching: false }") settings = default_value.copy() settings.update(parameter_value) @@ -641,22 +643,23 @@ def _add_swagger_integration(self, api, function): parameters.append(settings) - elif not isinstance(parameter, string_types): - raise InvalidEventException( - self.relative_id, - "Invalid value for 'RequestParameters' property") - - else: + elif isinstance(parameter, string_types): if not re.match('method\.request\.(query|path|header)', parameter): raise InvalidEventException( self.relative_id, - "Invalid value for 'RequestParameters' property") + "Invalid value for 'RequestParameters' property. Keys must be in the format " + "'method.request.[query|path|header].{value}', e.g 'method.request.header.Authorization'.") settings = default_value.copy() settings.update({'Name': parameter}) parameters.append(settings) + else: + raise InvalidEventException( + self.relative_id, + "Invalid value for 'RequestParameters' property. Property must be either a string or an object") + editor.add_request_parameters_to_method(path=self.Path, method_name=self.Method, request_parameters=parameters) diff --git a/tests/translator/output/error_function_invalid_request_parameters.json b/tests/translator/output/error_function_invalid_request_parameters.json index a79374026..71cf6358d 100644 --- a/tests/translator/output/error_function_invalid_request_parameters.json +++ b/tests/translator/output/error_function_invalid_request_parameters.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 6. Resource with id [InvalidNameDictParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property Resource with id [InvalidNameLocationStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property Resource with id [InvalidNameStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property Resource with id [ParameterInvalidFieldFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property Resource with id [ParameterNotDictFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property Resource with id [ParameterNotDictOrStringFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property" + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 6. Resource with id [InvalidNameDictParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[query|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [InvalidNameLocationStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[query|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [InvalidNameStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[query|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [ParameterInvalidFieldFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Values must be an object, e.g { Required: true, Caching: false } Resource with id [ParameterNotDictFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Values must be an object, e.g { Required: true, Caching: false } Resource with id [ParameterNotDictOrStringFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Property must be either a string or an object" } \ No newline at end of file From 99aedd94124a1fe9b6f0b7decfe6c32e0a03a0d0 Mon Sep 17 00:00:00 2001 From: bbeck Date: Tue, 6 Aug 2019 18:27:15 -0600 Subject: [PATCH 33/34] change query to querystring; fix styling --- .../function_request_parameters/template.yaml | 13 +++++++++---- samtranslator/model/eventsources/push.py | 14 ++++++++------ samtranslator/swagger/swagger.py | 8 ++++++-- .../input/function_with_request_parameters.yaml | 6 +++--- .../aws-cn/function_with_request_parameters.json | 6 +++--- .../function_with_request_parameters.json | 6 +++--- .../error_function_invalid_request_parameters.json | 2 +- .../output/function_with_request_parameters.json | 6 +++--- versions/2016-10-31.md | 6 +++--- 9 files changed, 39 insertions(+), 28 deletions(-) diff --git a/examples/2016-10-31/function_request_parameters/template.yaml b/examples/2016-10-31/function_request_parameters/template.yaml index 76d21b5b3..a453b9ba6 100644 --- a/examples/2016-10-31/function_request_parameters/template.yaml +++ b/examples/2016-10-31/function_request_parameters/template.yaml @@ -1,6 +1,11 @@ AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Simple API Endpoint configured using Swagger specified inline and backed by a Lambda function +Globals: + Api: + CacheClusterEnabled: true + CacheClusterSize: '0.5' + Resources: MyLambdaFunction: @@ -8,7 +13,7 @@ Resources: Properties: Handler: index.handler Runtime: nodejs8.10 - CodeUri: src/ + CodeUri: s3://gbdx-build-artifacts/bbeck-test/423f9056eb70d25480852fc472b43dd5 #src/ Events: GetApi: Type: Api @@ -17,9 +22,9 @@ Resources: Method: POST RequestParameters: - method.request.header.Authorization: - Required: True - Caching: True - - method.request.query.type + Required: true + Caching: true + - method.request.querystring.type Outputs: diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index cad4c8ccc..d11f721d8 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -17,7 +17,7 @@ CONDITION = 'Condition' -RequestParameterProperties = ["Required", "Caching"] +REQUEST_PARAMETER_PROPERTIES = ["Required", "Caching"] class PushEventSource(ResourceMacro): @@ -624,13 +624,14 @@ def _add_swagger_integration(self, api, function): parameter_name, parameter_value = next(iter(parameter.items())) - if not re.match('method\.request\.(query|path|header)', parameter_name): + if not re.match('method\.request\.(querystring|path|header)', parameter_name): raise InvalidEventException( self.relative_id, "Invalid value for 'RequestParameters' property. Keys must be in the format " - "'method.request.[query|path|header].{value}', e.g 'method.request.header.Authorization'.") + "'method.request.[querystring|path|header].{value}', " + "e.g 'method.request.header.Authorization'.") - if not isinstance(parameter_value, dict) or not all(key in RequestParameterProperties + if not isinstance(parameter_value, dict) or not all(key in REQUEST_PARAMETER_PROPERTIES for key in parameter_value.keys()): raise InvalidEventException( self.relative_id, @@ -644,11 +645,12 @@ def _add_swagger_integration(self, api, function): parameters.append(settings) elif isinstance(parameter, string_types): - if not re.match('method\.request\.(query|path|header)', parameter): + if not re.match('method\.request\.(querystring|path|header)', parameter): raise InvalidEventException( self.relative_id, "Invalid value for 'RequestParameters' property. Keys must be in the format " - "'method.request.[query|path|header].{value}', e.g 'method.request.header.Authorization'.") + "'method.request.[querystring|path|header].{value}', " + "e.g 'method.request.header.Authorization'.") settings = default_value.copy() settings.update({'Name': parameter}) diff --git a/samtranslator/swagger/swagger.py b/samtranslator/swagger/swagger.py index 8acff2f58..751d73707 100644 --- a/samtranslator/swagger/swagger.py +++ b/samtranslator/swagger/swagger.py @@ -23,6 +23,7 @@ class SwaggerEditor(object): _X_APIGW_GATEWAY_RESPONSES = 'x-amazon-apigateway-gateway-responses' _X_APIGW_POLICY = 'x-amazon-apigateway-policy' _X_ANY_METHOD = 'x-amazon-apigateway-any-method' + _CACHE_KEY_PARAMETERS = 'cacheKeyParameters' def __init__(self, doc): """ @@ -846,6 +847,9 @@ def add_request_parameters_to_method(self, path, method_name, request_parameters location_name = parameter_name.replace('method.request.', '') location, name = location_name.split('.') + if location == 'querystring': + location = 'query' + parameter = { 'in': location, 'name': name, @@ -858,9 +862,9 @@ def add_request_parameters_to_method(self, path, method_name, request_parameters if request_parameter['Caching']: integration = method_definition[self._X_APIGW_INTEGRATION] - cache_parameters = integration.get('cacheKeyParameters', []) + cache_parameters = integration.get(self._CACHE_KEY_PARAMETERS, []) cache_parameters.append(parameter_name) - integration['cacheKeyParameters'] = cache_parameters + integration[self._CACHE_KEY_PARAMETERS] = cache_parameters method_definition['parameters'] = existing_parameters diff --git a/tests/translator/input/function_with_request_parameters.yaml b/tests/translator/input/function_with_request_parameters.yaml index ad281159d..ebc89f893 100644 --- a/tests/translator/input/function_with_request_parameters.yaml +++ b/tests/translator/input/function_with_request_parameters.yaml @@ -20,8 +20,8 @@ Resources: Method: get RequestParameters: - method.request.header.Authorization: - Required: True - Caching: True + Required: true + Caching: true NoApiParameterFunction: Type: AWS::Serverless::Function @@ -36,5 +36,5 @@ Resources: Path: / Method: get RequestParameters: - - method.request.query.type + - method.request.querystring.type - method.request.path.id diff --git a/tests/translator/output/aws-cn/function_with_request_parameters.json b/tests/translator/output/aws-cn/function_with_request_parameters.json index d49468fc6..673f55726 100644 --- a/tests/translator/output/aws-cn/function_with_request_parameters.json +++ b/tests/translator/output/aws-cn/function_with_request_parameters.json @@ -47,13 +47,13 @@ } } }, - "ServerlessRestApiDeployment4e9e7f13b1": { + "ServerlessRestApiDeploymentc2741b5220": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "ServerlessRestApi" }, - "Description": "RestApi deployment id: 4e9e7f13b1c53469a304456bc133a9703a2c62f1", + "Description": "RestApi deployment id: c2741b5220c940a753e3d1e18da6763aaba1c19b", "StageName": "Stage" } }, @@ -127,7 +127,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "ServerlessRestApiDeployment4e9e7f13b1" + "Ref": "ServerlessRestApiDeploymentc2741b5220" }, "RestApiId": { "Ref": "ServerlessRestApi" diff --git a/tests/translator/output/aws-us-gov/function_with_request_parameters.json b/tests/translator/output/aws-us-gov/function_with_request_parameters.json index 19aeec3c8..ea45309d9 100644 --- a/tests/translator/output/aws-us-gov/function_with_request_parameters.json +++ b/tests/translator/output/aws-us-gov/function_with_request_parameters.json @@ -47,13 +47,13 @@ } } }, - "ServerlessRestApiDeploymentbb31ea9793": { + "ServerlessRestApiDeployment7c706bcd56": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "ServerlessRestApi" }, - "Description": "RestApi deployment id: bb31ea9793b7e80d8ef62bd1054ea3f819ceb563", + "Description": "RestApi deployment id: 7c706bcd56e685afb5882e0219515c9413bcd13b", "StageName": "Stage" } }, @@ -137,7 +137,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentbb31ea9793" + "Ref": "ServerlessRestApiDeployment7c706bcd56" }, "RestApiId": { "Ref": "ServerlessRestApi" diff --git a/tests/translator/output/error_function_invalid_request_parameters.json b/tests/translator/output/error_function_invalid_request_parameters.json index 71cf6358d..cfc869006 100644 --- a/tests/translator/output/error_function_invalid_request_parameters.json +++ b/tests/translator/output/error_function_invalid_request_parameters.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 6. Resource with id [InvalidNameDictParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[query|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [InvalidNameLocationStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[query|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [InvalidNameStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[query|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [ParameterInvalidFieldFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Values must be an object, e.g { Required: true, Caching: false } Resource with id [ParameterNotDictFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Values must be an object, e.g { Required: true, Caching: false } Resource with id [ParameterNotDictOrStringFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Property must be either a string or an object" + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 6. Resource with id [InvalidNameDictParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[querystring|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [InvalidNameLocationStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[querystring|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [InvalidNameStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[querystring|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [ParameterInvalidFieldFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Values must be an object, e.g { Required: true, Caching: false } Resource with id [ParameterNotDictFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Values must be an object, e.g { Required: true, Caching: false } Resource with id [ParameterNotDictOrStringFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Property must be either a string or an object" } \ No newline at end of file diff --git a/tests/translator/output/function_with_request_parameters.json b/tests/translator/output/function_with_request_parameters.json index df2e35f82..876e1a4f2 100644 --- a/tests/translator/output/function_with_request_parameters.json +++ b/tests/translator/output/function_with_request_parameters.json @@ -47,13 +47,13 @@ } } }, - "ServerlessRestApiDeployment498b4bac69": { + "ServerlessRestApiDeployment2223b43914": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "ServerlessRestApi" }, - "Description": "RestApi deployment id: 498b4bac6915ecf6514efc3763418babae239612", + "Description": "RestApi deployment id: 2223b439142974b7a3aad1381ddd39027077ce52", "StageName": "Stage" } }, @@ -127,7 +127,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "ServerlessRestApiDeployment498b4bac69" + "Ref": "ServerlessRestApiDeployment2223b43914" }, "RestApiId": { "Ref": "ServerlessRestApi" diff --git a/versions/2016-10-31.md b/versions/2016-10-31.md index 046611d7e..8812bc859 100644 --- a/versions/2016-10-31.md +++ b/versions/2016-10-31.md @@ -530,7 +530,7 @@ Method | `string` | **Required.** HTTP method for which this function is invoked RestApiId | `string` | Identifier of a RestApi resource which MUST contain an operation with the given path and method. Typically, this is set to [reference](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html) an `AWS::Serverless::Api` resource defined in this template. If not defined, a default `AWS::Serverless::Api` resource is created using a generated Swagger document contains a union of all paths and methods defined by `Api` events defined in this template that do not specify a RestApiId. Auth | [Function Auth Object](#function-auth-object) | Auth configuration for this specific Api+Path+Method. Useful for overriding the API's `DefaultAuthorizer` setting auth config on an individual path when no `DefaultAuthorizer` is specified or overriding the default `ApiKeyRequired' setting. RequestModel | [Function Request Model Object](#function-request-model-object) | Request model configuration for this specific Api+Path+Method. -RequestParameters | List of `string` | List of [Function Request Parameter Object](#function-request-parameter-object) | Request parameters configuration for this specific Api+Path+Method. All parameter names must start with `method.request` and must be limited to `method.request.header`, `method.request.query`, or `method.request.path`. If a parameter is a `string` and NOT a [Function Request Parameter Object](#function-request-parameter-object) then `Required` and `Caching` will default to `False`. +RequestParameters | List of `string` | List of [Function Request Parameter Object](#function-request-parameter-object) | Request parameters configuration for this specific Api+Path+Method. All parameter names must start with `method.request` and must be limited to `method.request.header`, `method.request.querystring`, or `method.request.path`. If a parameter is a `string` and NOT a [Function Request Parameter Object](#function-request-parameter-object) then `Required` and `Caching` will default to `False`. ##### Example: Api event source object @@ -891,8 +891,8 @@ Configure Request Parameter for a specific Api+Path+Method. ```yaml - method.request.header.Authorization: - Required: True - Caching: True + Required: true + Caching: true ``` #### Gateway Response Object From 7ec7d1a897c37ebfaa8f9c0a3b151a1cfd71d185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=92=BB=20=F0=9F=92=AA=20=F0=9F=98=89=20James=20Hood?= Date: Tue, 13 Aug 2019 15:40:02 -0700 Subject: [PATCH 34/34] minor cleanups --- examples/2016-10-31/function_request_parameters/template.yaml | 4 ++-- samtranslator/model/eventsources/push.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/2016-10-31/function_request_parameters/template.yaml b/examples/2016-10-31/function_request_parameters/template.yaml index a453b9ba6..e6334b98a 100644 --- a/examples/2016-10-31/function_request_parameters/template.yaml +++ b/examples/2016-10-31/function_request_parameters/template.yaml @@ -13,7 +13,7 @@ Resources: Properties: Handler: index.handler Runtime: nodejs8.10 - CodeUri: s3://gbdx-build-artifacts/bbeck-test/423f9056eb70d25480852fc472b43dd5 #src/ + CodeUri: src/ Events: GetApi: Type: Api @@ -30,4 +30,4 @@ Outputs: ApiURL: Description: "API endpoint URL for Prod environment" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/prod/get" \ No newline at end of file + Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/post" \ No newline at end of file diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index d11f721d8..995ec820a 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -624,7 +624,7 @@ def _add_swagger_integration(self, api, function): parameter_name, parameter_value = next(iter(parameter.items())) - if not re.match('method\.request\.(querystring|path|header)', parameter_name): + if not re.match('method\.request\.(querystring|path|header)\.', parameter_name): raise InvalidEventException( self.relative_id, "Invalid value for 'RequestParameters' property. Keys must be in the format " @@ -645,7 +645,7 @@ def _add_swagger_integration(self, api, function): parameters.append(settings) elif isinstance(parameter, string_types): - if not re.match('method\.request\.(querystring|path|header)', parameter): + if not re.match('method\.request\.(querystring|path|header)\.', parameter): raise InvalidEventException( self.relative_id, "Invalid value for 'RequestParameters' property. Keys must be in the format "