diff --git a/packages/@aws-cdk/aws-apigateway/lib/deployment.ts b/packages/@aws-cdk/aws-apigateway/lib/deployment.ts index 9a827f6038fc0..6fdadaccb3ec2 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/deployment.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/deployment.ts @@ -1,4 +1,4 @@ -import { Construct, DefaultTokenResolver, Lazy, RemovalPolicy, Resource, Stack, StringConcat, Tokenization } from '@aws-cdk/core'; +import { Construct, Lazy, RemovalPolicy, Resource, Stack } from '@aws-cdk/core'; import crypto = require('crypto'); import { CfnDeployment, CfnDeploymentProps } from './apigateway.generated'; import { IRestApi } from './restapi'; @@ -121,20 +121,13 @@ class LatestDeploymentResource extends CfnDeployment { * add via `addToLogicalId`. */ protected prepare() { + const stack = Stack.of(this); + // if hash components were added to the deployment, we use them to calculate // a logical ID for the deployment resource. if (this.hashComponents.length > 0) { const md5 = crypto.createHash('md5'); - this.hashComponents - .map(c => { - return Tokenization.resolve(c, { - scope: this, - resolver: new DefaultTokenResolver(new StringConcat()), - preparing: true, - }); - }) - .forEach(c => md5.update(JSON.stringify(c))); - + this.hashComponents.map(x => stack.resolve(x)).forEach(c => md5.update(JSON.stringify(c))); this.overrideLogicalId(this.originalLogicalId + md5.digest("hex")); } super.prepare(); diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.cors.expected.json b/packages/@aws-cdk/aws-apigateway/test/integ.cors.expected.json index 0c78af230bd90..85fe3ff7e60fd 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.cors.expected.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.cors.expected.json @@ -6,7 +6,7 @@ "Name": "cors-api-test" } }, - "corsapitestDeployment2BF1633Af56aad239353437f465d2090f2edab0c": { + "corsapitestDeployment2BF1633A197b7a426736ab40a59d8a41c2d3d50d": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { @@ -29,7 +29,7 @@ "Ref": "corsapitest8682546E" }, "DeploymentId": { - "Ref": "corsapitestDeployment2BF1633Af56aad239353437f465d2090f2edab0c" + "Ref": "corsapitestDeployment2BF1633A197b7a426736ab40a59d8a41c2d3d50d" }, "StageName": "prod" } diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.books.expected.json b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.books.expected.json index ea0156dfca4fa..18f6db923e3ff 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.books.expected.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.books.expected.json @@ -50,13 +50,194 @@ "BooksHandlerServiceRole5B6A8847" ] }, - "booksapibooksGETApiPermissionrestapibooksexamplebooksapi4538F335GETbooks391776D8": { + "BookHandlerServiceRole894768AD": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "BookHandlerF9638A7A": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "exports.handler = function echoHandlerCode(event, _, callback) {\n return callback(undefined, {\n isBase64Encoded: false,\n statusCode: 200,\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(event)\n });\n}" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "BookHandlerServiceRole894768AD", + "Arn" + ] + }, + "Runtime": "nodejs8.10" + }, + "DependsOn": [ + "BookHandlerServiceRole894768AD" + ] + }, + "HelloServiceRole1E55EA16": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "Hello4A628BD4": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "exports.handler = function helloCode(_event, _context, callback) {\n return callback(undefined, {\n statusCode: 200,\n body: 'hello, world!'\n });\n}" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "HelloServiceRole1E55EA16", + "Arn" + ] + }, + "Runtime": "nodejs8.10" + }, + "DependsOn": [ + "HelloServiceRole1E55EA16" + ] + }, + "booksapiE1885304": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Name": "books-api" + } + }, + "booksapiDeployment308B08F1c828b08824c062376eba921738884f85": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "booksapiE1885304" + }, + "Description": "Automatically created by the RestApi construct" + }, + "DependsOn": [ + "booksapiANYF4F0CDEB", + "booksapibooksbookidDELETE214F4059", + "booksapibooksbookidGETCCE21986", + "booksapibooksbookid5264BCA2", + "booksapibooksGETA776447A", + "booksapibooksPOSTF6C6559D", + "booksapibooks97D84727" + ] + }, + "booksapiDeploymentStageprod55D8E03E": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "booksapiE1885304" + }, + "DeploymentId": { + "Ref": "booksapiDeployment308B08F1c828b08824c062376eba921738884f85" + }, + "StageName": "prod" + } + }, + "booksapiCloudWatchRole089CB225": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "apigateway.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" + ] + ] + } + ] + } + }, + "booksapiAccountDBA98FB9": { + "Type": "AWS::ApiGateway::Account", + "Properties": { + "CloudWatchRoleArn": { + "Fn::GetAtt": [ + "booksapiCloudWatchRole089CB225", + "Arn" + ] + } + }, + "DependsOn": [ + "booksapiE1885304" + ] + }, + "booksapiANYApiPermissionrestapibooksexamplebooksapi4538F335ANY73B3CDDC": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ - "BooksHandler3EB83358", + "Hello4A628BD4", "Arn" ] }, @@ -85,19 +266,19 @@ { "Ref": "booksapiDeploymentStageprod55D8E03E" }, - "/GET/books" + "/*/" ] ] } } }, - "booksapibooksGETApiPermissionTestrestapibooksexamplebooksapi4538F335GETbooks01FB3D1B": { + "booksapiANYApiPermissionTestrestapibooksexamplebooksapi4538F335ANYB0D7D8AC": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ - "BooksHandler3EB83358", + "Hello4A628BD4", "Arn" ] }, @@ -122,13 +303,71 @@ { "Ref": "booksapiE1885304" }, - "/test-invoke-stage/GET/books" + "/test-invoke-stage/*/" ] ] } } }, - "booksapibooksPOSTApiPermissionrestapibooksexamplebooksapi4538F335POSTbooksDFEC643F": { + "booksapiANYF4F0CDEB": { + "Type": "AWS::ApiGateway::Method", + "Properties": { + "HttpMethod": "ANY", + "ResourceId": { + "Fn::GetAtt": [ + "booksapiE1885304", + "RootResourceId" + ] + }, + "RestApiId": { + "Ref": "booksapiE1885304" + }, + "AuthorizationType": "NONE", + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":apigateway:", + { + "Ref": "AWS::Region" + }, + ":lambda:path/2015-03-31/functions/", + { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "/invocations" + ] + ] + } + } + } + }, + "booksapibooks97D84727": { + "Type": "AWS::ApiGateway::Resource", + "Properties": { + "ParentId": { + "Fn::GetAtt": [ + "booksapiE1885304", + "RootResourceId" + ] + }, + "PathPart": "books", + "RestApiId": { + "Ref": "booksapiE1885304" + } + } + }, + "booksapibooksGETApiPermissionrestapibooksexamplebooksapi4538F335GETbooks391776D8": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", @@ -163,13 +402,13 @@ { "Ref": "booksapiDeploymentStageprod55D8E03E" }, - "/POST/books" + "/GET/books" ] ] } } }, - "booksapibooksPOSTApiPermissionTestrestapibooksexamplebooksapi4538F335POSTbooks1C6D24C8": { + "booksapibooksGETApiPermissionTestrestapibooksexamplebooksapi4538F335GETbooks01FB3D1B": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", @@ -200,29 +439,27 @@ { "Ref": "booksapiE1885304" }, - "/test-invoke-stage/POST/books" + "/test-invoke-stage/GET/books" ] ] } } }, - "BookHandlerServiceRole894768AD": { - "Type": "AWS::IAM::Role", + "booksapibooksGETA776447A": { + "Type": "AWS::ApiGateway::Method", "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com" - } - } - ], - "Version": "2012-10-17" + "HttpMethod": "GET", + "ResourceId": { + "Ref": "booksapibooks97D84727" }, - "ManagedPolicyArns": [ - { + "RestApiId": { + "Ref": "booksapiE1885304" + }, + "AuthorizationType": "AWS_IAM", + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { "Fn::Join": [ "", [ @@ -230,39 +467,31 @@ { "Ref": "AWS::Partition" }, - ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ":apigateway:", + { + "Ref": "AWS::Region" + }, + ":lambda:path/2015-03-31/functions/", + { + "Fn::GetAtt": [ + "BooksHandler3EB83358", + "Arn" + ] + }, + "/invocations" ] ] } - ] + } } }, - "BookHandlerF9638A7A": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function echoHandlerCode(event, _, callback) {\n return callback(undefined, {\n isBase64Encoded: false,\n statusCode: 200,\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(event)\n });\n}" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "BookHandlerServiceRole894768AD", - "Arn" - ] - }, - "Runtime": "nodejs8.10" - }, - "DependsOn": [ - "BookHandlerServiceRole894768AD" - ] - }, - "booksapibooksbookidGETApiPermissionrestapibooksexamplebooksapi4538F335GETbooksbookidBB91DFBD": { + "booksapibooksPOSTApiPermissionrestapibooksexamplebooksapi4538F335POSTbooksDFEC643F": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ - "BookHandlerF9638A7A", + "BooksHandler3EB83358", "Arn" ] }, @@ -291,19 +520,19 @@ { "Ref": "booksapiDeploymentStageprod55D8E03E" }, - "/GET/books/{book_id}" + "/POST/books" ] ] } } }, - "booksapibooksbookidGETApiPermissionTestrestapibooksexamplebooksapi4538F335GETbooksbookidA0230B08": { + "booksapibooksPOSTApiPermissionTestrestapibooksexamplebooksapi4538F335POSTbooks1C6D24C8": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ - "BookHandlerF9638A7A", + "BooksHandler3EB83358", "Arn" ] }, @@ -328,13 +557,65 @@ { "Ref": "booksapiE1885304" }, - "/test-invoke-stage/GET/books/{book_id}" + "/test-invoke-stage/POST/books" ] ] } } }, - "booksapibooksbookidDELETEApiPermissionrestapibooksexamplebooksapi4538F335DELETEbooksbookid76C1C947": { + "booksapibooksPOSTF6C6559D": { + "Type": "AWS::ApiGateway::Method", + "Properties": { + "HttpMethod": "POST", + "ResourceId": { + "Ref": "booksapibooks97D84727" + }, + "RestApiId": { + "Ref": "booksapiE1885304" + }, + "AuthorizationType": "AWS_IAM", + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":apigateway:", + { + "Ref": "AWS::Region" + }, + ":lambda:path/2015-03-31/functions/", + { + "Fn::GetAtt": [ + "BooksHandler3EB83358", + "Arn" + ] + }, + "/invocations" + ] + ] + } + } + } + }, + "booksapibooksbookid5264BCA2": { + "Type": "AWS::ApiGateway::Resource", + "Properties": { + "ParentId": { + "Ref": "booksapibooks97D84727" + }, + "PathPart": "{book_id}", + "RestApiId": { + "Ref": "booksapiE1885304" + } + } + }, + "booksapibooksbookidGETApiPermissionrestapibooksexamplebooksapi4538F335GETbooksbookidBB91DFBD": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", @@ -369,13 +650,13 @@ { "Ref": "booksapiDeploymentStageprod55D8E03E" }, - "/DELETE/books/{book_id}" + "/GET/books/{book_id}" ] ] } } }, - "booksapibooksbookidDELETEApiPermissionTestrestapibooksexamplebooksapi4538F335DELETEbooksbookid09D6CB8A": { + "booksapibooksbookidGETApiPermissionTestrestapibooksexamplebooksapi4538F335GETbooksbookidA0230B08": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", @@ -406,29 +687,27 @@ { "Ref": "booksapiE1885304" }, - "/test-invoke-stage/DELETE/books/{book_id}" + "/test-invoke-stage/GET/books/{book_id}" ] ] } } }, - "HelloServiceRole1E55EA16": { - "Type": "AWS::IAM::Role", + "booksapibooksbookidGETCCE21986": { + "Type": "AWS::ApiGateway::Method", "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com" - } - } - ], - "Version": "2012-10-17" + "HttpMethod": "GET", + "ResourceId": { + "Ref": "booksapibooksbookid5264BCA2" }, - "ManagedPolicyArns": [ - { + "RestApiId": { + "Ref": "booksapiE1885304" + }, + "AuthorizationType": "AWS_IAM", + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { "Fn::Join": [ "", [ @@ -436,39 +715,31 @@ { "Ref": "AWS::Partition" }, - ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ":apigateway:", + { + "Ref": "AWS::Region" + }, + ":lambda:path/2015-03-31/functions/", + { + "Fn::GetAtt": [ + "BookHandlerF9638A7A", + "Arn" + ] + }, + "/invocations" ] ] } - ] + } } }, - "Hello4A628BD4": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function helloCode(_event, _context, callback) {\n return callback(undefined, {\n statusCode: 200,\n body: 'hello, world!'\n });\n}" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "HelloServiceRole1E55EA16", - "Arn" - ] - }, - "Runtime": "nodejs8.10" - }, - "DependsOn": [ - "HelloServiceRole1E55EA16" - ] - }, - "booksapiANYApiPermissionrestapibooksexamplebooksapi4538F335ANY73B3CDDC": { + "booksapibooksbookidDELETEApiPermissionrestapibooksexamplebooksapi4538F335DELETEbooksbookid76C1C947": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ - "Hello4A628BD4", + "BookHandlerF9638A7A", "Arn" ] }, @@ -497,19 +768,19 @@ { "Ref": "booksapiDeploymentStageprod55D8E03E" }, - "/*/" + "/DELETE/books/{book_id}" ] ] } } }, - "booksapiANYApiPermissionTestrestapibooksexamplebooksapi4538F335ANYB0D7D8AC": { + "booksapibooksbookidDELETEApiPermissionTestrestapibooksexamplebooksapi4538F335DELETEbooksbookid09D6CB8A": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ - "Hello4A628BD4", + "BookHandlerF9638A7A", "Arn" ] }, @@ -534,280 +805,9 @@ { "Ref": "booksapiE1885304" }, - "/test-invoke-stage/*/" - ] - ] - } - } - }, - "booksapiE1885304": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Name": "books-api" - } - }, - "booksapiDeployment308B08F1038c4647da4cb72c7574b891fb62b77f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "booksapiE1885304" - }, - "Description": "Automatically created by the RestApi construct" - }, - "DependsOn": [ - "booksapiANYF4F0CDEB", - "booksapibooksbookidDELETE214F4059", - "booksapibooksbookidGETCCE21986", - "booksapibooksbookid5264BCA2", - "booksapibooksGETA776447A", - "booksapibooksPOSTF6C6559D", - "booksapibooks97D84727" - ] - }, - "booksapiDeploymentStageprod55D8E03E": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "RestApiId": { - "Ref": "booksapiE1885304" - }, - "DeploymentId": { - "Ref": "booksapiDeployment308B08F1038c4647da4cb72c7574b891fb62b77f" - }, - "StageName": "prod" - } - }, - "booksapiCloudWatchRole089CB225": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "apigateway.amazonaws.com" - } - } - ], - "Version": "2012-10-17" - }, - "ManagedPolicyArns": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" - ] - ] - } - ] - } - }, - "booksapiAccountDBA98FB9": { - "Type": "AWS::ApiGateway::Account", - "Properties": { - "CloudWatchRoleArn": { - "Fn::GetAtt": [ - "booksapiCloudWatchRole089CB225", - "Arn" - ] - } - }, - "DependsOn": [ - "booksapiE1885304" - ] - }, - "booksapiANYF4F0CDEB": { - "Type": "AWS::ApiGateway::Method", - "Properties": { - "HttpMethod": "ANY", - "ResourceId": { - "Fn::GetAtt": [ - "booksapiE1885304", - "RootResourceId" - ] - }, - "RestApiId": { - "Ref": "booksapiE1885304" - }, - "AuthorizationType": "NONE", - "Integration": { - "IntegrationHttpMethod": "POST", - "Type": "AWS_PROXY", - "Uri": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":apigateway:", - { - "Ref": "AWS::Region" - }, - ":lambda:path/2015-03-31/functions/", - { - "Fn::GetAtt": [ - "Hello4A628BD4", - "Arn" - ] - }, - "/invocations" - ] + "/test-invoke-stage/DELETE/books/{book_id}" ] - } - } - } - }, - "booksapibooks97D84727": { - "Type": "AWS::ApiGateway::Resource", - "Properties": { - "ParentId": { - "Fn::GetAtt": [ - "booksapiE1885304", - "RootResourceId" ] - }, - "PathPart": "books", - "RestApiId": { - "Ref": "booksapiE1885304" - } - } - }, - "booksapibooksGETA776447A": { - "Type": "AWS::ApiGateway::Method", - "Properties": { - "HttpMethod": "GET", - "ResourceId": { - "Ref": "booksapibooks97D84727" - }, - "RestApiId": { - "Ref": "booksapiE1885304" - }, - "AuthorizationType": "AWS_IAM", - "Integration": { - "IntegrationHttpMethod": "POST", - "Type": "AWS_PROXY", - "Uri": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":apigateway:", - { - "Ref": "AWS::Region" - }, - ":lambda:path/2015-03-31/functions/", - { - "Fn::GetAtt": [ - "BooksHandler3EB83358", - "Arn" - ] - }, - "/invocations" - ] - ] - } - } - } - }, - "booksapibooksPOSTF6C6559D": { - "Type": "AWS::ApiGateway::Method", - "Properties": { - "HttpMethod": "POST", - "ResourceId": { - "Ref": "booksapibooks97D84727" - }, - "RestApiId": { - "Ref": "booksapiE1885304" - }, - "AuthorizationType": "AWS_IAM", - "Integration": { - "IntegrationHttpMethod": "POST", - "Type": "AWS_PROXY", - "Uri": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":apigateway:", - { - "Ref": "AWS::Region" - }, - ":lambda:path/2015-03-31/functions/", - { - "Fn::GetAtt": [ - "BooksHandler3EB83358", - "Arn" - ] - }, - "/invocations" - ] - ] - } - } - } - }, - "booksapibooksbookid5264BCA2": { - "Type": "AWS::ApiGateway::Resource", - "Properties": { - "ParentId": { - "Ref": "booksapibooks97D84727" - }, - "PathPart": "{book_id}", - "RestApiId": { - "Ref": "booksapiE1885304" - } - } - }, - "booksapibooksbookidGETCCE21986": { - "Type": "AWS::ApiGateway::Method", - "Properties": { - "HttpMethod": "GET", - "ResourceId": { - "Ref": "booksapibooksbookid5264BCA2" - }, - "RestApiId": { - "Ref": "booksapiE1885304" - }, - "AuthorizationType": "AWS_IAM", - "Integration": { - "IntegrationHttpMethod": "POST", - "Type": "AWS_PROXY", - "Uri": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":apigateway:", - { - "Ref": "AWS::Region" - }, - ":lambda:path/2015-03-31/functions/", - { - "Fn::GetAtt": [ - "BookHandlerF9638A7A", - "Arn" - ] - }, - "/invocations" - ] - ] - } } } }, diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.expected.json b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.expected.json index 8f78dec8c5d43..7832f919726b3 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.expected.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.expected.json @@ -6,7 +6,7 @@ "Name": "my-api" } }, - "myapiDeployment92F2CB49a38a6824a90d7d4e6cc3a7f11357e163": { + "myapiDeployment92F2CB4919460d935da8177bcfbc418506e514ff": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { @@ -38,7 +38,7 @@ "CacheClusterEnabled": true, "CacheClusterSize": "0.5", "DeploymentId": { - "Ref": "myapiDeployment92F2CB49a38a6824a90d7d4e6cc3a7f11357e163" + "Ref": "myapiDeployment92F2CB4919460d935da8177bcfbc418506e514ff" }, "Description": "beta stage", "MethodSettings": [ @@ -129,6 +129,84 @@ } } }, + "myapiv1toysGETApiPermissiontestapigatewayrestapimyapi1AE401C4GETv1toysA829D1CC": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyHandler6B74D312", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "myapi4C7BF186" + }, + "/", + { + "Ref": "myapiDeploymentStagebeta96434BEB" + }, + "/GET/v1/toys" + ] + ] + } + } + }, + "myapiv1toysGETApiPermissionTesttestapigatewayrestapimyapi1AE401C4GETv1toys9E0BAE9F": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyHandler6B74D312", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "myapi4C7BF186" + }, + "/test-invoke-stage/GET/v1/toys" + ] + ] + } + } + }, "myapiv1toysGET7348114D": { "Type": "AWS::ApiGateway::Method", "Properties": { @@ -242,6 +320,84 @@ } } }, + "myapiv1booksGETApiPermissiontestapigatewayrestapimyapi1AE401C4GETv1books484ACD3F": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyHandler6B74D312", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "myapi4C7BF186" + }, + "/", + { + "Ref": "myapiDeploymentStagebeta96434BEB" + }, + "/GET/v1/books" + ] + ] + } + } + }, + "myapiv1booksGETApiPermissionTesttestapigatewayrestapimyapi1AE401C4GETv1booksE255E31A": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyHandler6B74D312", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "myapi4C7BF186" + }, + "/test-invoke-stage/GET/v1/books" + ] + ] + } + } + }, "myapiv1booksGETC6B996D0": { "Type": "AWS::ApiGateway::Method", "Properties": { @@ -282,6 +438,84 @@ } } }, + "myapiv1booksPOSTApiPermissiontestapigatewayrestapimyapi1AE401C4POSTv1books2B1BC62B": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyHandler6B74D312", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "myapi4C7BF186" + }, + "/", + { + "Ref": "myapiDeploymentStagebeta96434BEB" + }, + "/POST/v1/books" + ] + ] + } + } + }, + "myapiv1booksPOSTApiPermissionTesttestapigatewayrestapimyapi1AE401C4POSTv1books816A6B37": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyHandler6B74D312", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "myapi4C7BF186" + }, + "/test-invoke-stage/POST/v1/books" + ] + ] + } + } + }, "myapiv1booksPOST53E2832E": { "Type": "AWS::ApiGateway::Method", "Properties": { @@ -429,240 +663,6 @@ "DependsOn": [ "MyHandlerServiceRoleFFA06653" ] - }, - "myapiv1toysGETApiPermissiontestapigatewayrestapimyapi1AE401C4GETv1toysA829D1CC": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyHandler6B74D312", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "myapi4C7BF186" - }, - "/", - { - "Ref": "myapiDeploymentStagebeta96434BEB" - }, - "/GET/v1/toys" - ] - ] - } - } - }, - "myapiv1toysGETApiPermissionTesttestapigatewayrestapimyapi1AE401C4GETv1toys9E0BAE9F": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyHandler6B74D312", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "myapi4C7BF186" - }, - "/test-invoke-stage/GET/v1/toys" - ] - ] - } - } - }, - "myapiv1booksGETApiPermissiontestapigatewayrestapimyapi1AE401C4GETv1books484ACD3F": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyHandler6B74D312", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "myapi4C7BF186" - }, - "/", - { - "Ref": "myapiDeploymentStagebeta96434BEB" - }, - "/GET/v1/books" - ] - ] - } - } - }, - "myapiv1booksGETApiPermissionTesttestapigatewayrestapimyapi1AE401C4GETv1booksE255E31A": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyHandler6B74D312", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "myapi4C7BF186" - }, - "/test-invoke-stage/GET/v1/books" - ] - ] - } - } - }, - "myapiv1booksPOSTApiPermissiontestapigatewayrestapimyapi1AE401C4POSTv1books2B1BC62B": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyHandler6B74D312", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "myapi4C7BF186" - }, - "/", - { - "Ref": "myapiDeploymentStagebeta96434BEB" - }, - "/POST/v1/books" - ] - ] - } - } - }, - "myapiv1booksPOSTApiPermissionTesttestapigatewayrestapimyapi1AE401C4POSTv1books816A6B37": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyHandler6B74D312", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "myapi4C7BF186" - }, - "/test-invoke-stage/POST/v1/books" - ] - ] - } - } } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.multistack.expected.json b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.multistack.expected.json index a88c397812638..a1d7c71de1a04 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.multistack.expected.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.multistack.expected.json @@ -1,21 +1,43 @@ [ { - "Outputs": { - "ExportsOutputFnGetAttfirstLambda395F9ADEArn1A9B3BC3": { - "Export": { "Name": "FirstStack:ExportsOutputFnGetAttfirstLambda395F9ADEArn1A9B3BC3" }, - "Value": { - "Fn::GetAtt": [ "firstLambda395F9ADE", "Arn" ] - } - } - }, "Resources": { + "firstLambdaServiceRoleB6408C31": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, "firstLambda395F9ADE": { - "DependsOn": [ "firstLambdaServiceRoleB6408C31" ], + "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async function(event) {\n return {\n 'headers': { 'Content-Type': 'text/plain' },\n 'statusCode': 200\n }\n }" }, - "FunctionName": "FirstLambda", "Handler": "index.handler", "Role": { "Fn::GetAtt": [ @@ -23,18 +45,73 @@ "Arn" ] }, - "Runtime": "nodejs8.10" + "Runtime": "nodejs8.10", + "FunctionName": "FirstLambda" + }, + "DependsOn": [ + "firstLambdaServiceRoleB6408C31" + ] + } + }, + "Outputs": { + "ExportsOutputFnGetAttfirstLambda395F9ADEArn1A9B3BC3": { + "Value": { + "Fn::GetAtt": [ + "firstLambda395F9ADE", + "Arn" + ] + }, + "Export": { + "Name": "FirstStack:ExportsOutputFnGetAttfirstLambda395F9ADEArn1A9B3BC3" + } + } + } + }, + { + "Resources": { + "BooksApi60AC975F": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Name": "SecondRestAPI" + } + }, + "BooksApiDeployment86CA39AFc929a0f95f673e230c62e2c9754726f6": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "BooksApi60AC975F" + }, + "Description": "Automatically created by the RestApi construct" }, - "Type": "AWS::Lambda::Function" + "DependsOn": [ + "BooksApiANY0C4EABE3", + "BooksApibooksGET6066BF7E", + "BooksApibooks1F745538" + ] }, - "firstLambdaServiceRoleB6408C31": { + "BooksApiDeploymentStageprod0693B760": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "BooksApi60AC975F" + }, + "DeploymentId": { + "Ref": "BooksApiDeployment86CA39AFc929a0f95f673e230c62e2c9754726f6" + }, + "StageName": "prod" + } + }, + "BooksApiCloudWatchRoleB120ADBA": { + "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", - "Principal": { "Service": "lambda.amazonaws.com" } + "Principal": { + "Service": "apigateway.amazonaws.com" + } } ], "Version": "2012-10-17" @@ -45,197 +122,201 @@ "", [ "arn:", - { "Ref": "AWS::Partition" }, - ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" ] ] } ] - }, - "Type": "AWS::IAM::Role" - } - } -}, - { - "Resources": { - "BooksApi60AC975F": { - "Type":"AWS::ApiGateway::RestApi", - "Properties": { "Name":"SecondRestAPI" } + } }, - "BooksApiDeployment86CA39AF794fe41ee968b295eca9a15ee72a4a7c": { - "Type":"AWS::ApiGateway::Deployment", + "BooksApiAccount9C44AF8E": { + "Type": "AWS::ApiGateway::Account", "Properties": { - "RestApiId": { "Ref": "BooksApi60AC975F" }, - "Description": "Automatically created by the RestApi construct" }, - "DependsOn": [ - "BooksApiANY0C4EABE3", - "BooksApibooksGET6066BF7E", - "BooksApibooks1F745538" - ] - }, - "BooksApiDeploymentStageprod0693B760": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "RestApiId": { "Ref": "BooksApi60AC975F" }, - "DeploymentId": { "Ref": "BooksApiDeployment86CA39AF794fe41ee968b295eca9a15ee72a4a7c" }, - "StageName": "prod" - } - }, - "BooksApiCloudWatchRoleB120ADBA": { - "Type":"AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument":{ - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": {"Service":"apigateway.amazonaws.com"} - } - ], - "Version": "2012-10-17" - }, - "ManagedPolicyArns": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { "Ref": "AWS::Partition" }, - ":iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" - ] - ] - } + "CloudWatchRoleArn": { + "Fn::GetAtt": [ + "BooksApiCloudWatchRoleB120ADBA", + "Arn" ] } }, - "BooksApiAccount9C44AF8E": { - "Type": "AWS::ApiGateway::Account", - "Properties": { - "CloudWatchRoleArn": { - "Fn::GetAtt": [ "BooksApiCloudWatchRoleB120ADBA", "Arn" ] - } + "DependsOn": [ + "BooksApi60AC975F" + ] + }, + "BooksApiANY0C4EABE3": { + "Type": "AWS::ApiGateway::Method", + "Properties": { + "HttpMethod": "ANY", + "ResourceId": { + "Fn::GetAtt": [ + "BooksApi60AC975F", + "RootResourceId" + ] }, - "DependsOn":[ "BooksApi60AC975F" ] - }, - "BooksApiANY0C4EABE3": { - "Type": "AWS::ApiGateway::Method", - "Properties": { - "HttpMethod": "ANY", - "ResourceId": { - "Fn::GetAtt": [ "BooksApi60AC975F","RootResourceId" ] - }, - "RestApiId": { "Ref":"BooksApi60AC975F" }, - "AuthorizationType": "NONE", - "Integration": { "Type": "MOCK" } + "RestApiId": { + "Ref": "BooksApi60AC975F" + }, + "AuthorizationType": "NONE", + "Integration": { + "Type": "MOCK" } - }, - "BooksApibooks1F745538": { - "Type": "AWS::ApiGateway::Resource", - "Properties": { - "ParentId": { - "Fn::GetAtt":[ "BooksApi60AC975F", "RootResourceId" ] - }, - "PathPart": "books", - "RestApiId": { "Ref": "BooksApi60AC975F" } + } + }, + "BooksApibooks1F745538": { + "Type": "AWS::ApiGateway::Resource", + "Properties": { + "ParentId": { + "Fn::GetAtt": [ + "BooksApi60AC975F", + "RootResourceId" + ] + }, + "PathPart": "books", + "RestApiId": { + "Ref": "BooksApi60AC975F" } - }, - "BooksApibooksGET6066BF7E": { - "Type": "AWS::ApiGateway::Method", - "Properties": { - "HttpMethod": "GET", - "ResourceId": { "Ref": "BooksApibooks1F745538" }, - "RestApiId": { "Ref": "BooksApi60AC975F" }, - "AuthorizationType": "NONE", - "Integration": { - "IntegrationHttpMethod": "POST", - "Type": "AWS_PROXY", - "Uri": { - "Fn::Join": [ - "", - [ - "arn:", - { "Ref":"AWS::Partition" }, - ":apigateway:", - { "Ref": "AWS::Region" }, - ":lambda:path/2015-03-31/functions/", - { "Fn::ImportValue": "FirstStack:ExportsOutputFnGetAttfirstLambda395F9ADEArn1A9B3BC3" }, - "/invocations" - ] - ] - } - } + } + }, + "BooksApibooksGETApiPermissionSecondStackBooksApi2660DEC5GETbooksE54B6E9B": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::ImportValue": "FirstStack:ExportsOutputFnGetAttfirstLambda395F9ADEArn1A9B3BC3" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "BooksApi60AC975F" + }, + "/", + { + "Ref": "BooksApiDeploymentStageprod0693B760" + }, + "/GET/books" + ] + ] } - }, - "BooksApibooksGETApiPermissionSecondStackBooksApi2660DEC5GETbooksE54B6E9B": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { "Fn::ImportValue": "FirstStack:ExportsOutputFnGetAttfirstLambda395F9ADEArn1A9B3BC3" }, - "Principal":"apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { "Ref": "AWS::Partition" }, - ":execute-api:", - { "Ref": "AWS::Region" }, - ":", - { "Ref": "AWS::AccountId" }, - ":", - { "Ref": "BooksApi60AC975F" }, - "/", - { "Ref": "BooksApiDeploymentStageprod0693B760" }, - "/GET/books" - ] + } + }, + "BooksApibooksGETApiPermissionTestSecondStackBooksApi2660DEC5GETbooks0B7ED39D": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::ImportValue": "FirstStack:ExportsOutputFnGetAttfirstLambda395F9ADEArn1A9B3BC3" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "BooksApi60AC975F" + }, + "/test-invoke-stage/GET/books" ] - } + ] } - }, - "BooksApibooksGETApiPermissionTestSecondStackBooksApi2660DEC5GETbooks0B7ED39D": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { "Fn::ImportValue": "FirstStack:ExportsOutputFnGetAttfirstLambda395F9ADEArn1A9B3BC3" }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { + } + }, + "BooksApibooksGET6066BF7E": { + "Type": "AWS::ApiGateway::Method", + "Properties": { + "HttpMethod": "GET", + "ResourceId": { + "Ref": "BooksApibooks1F745538" + }, + "RestApiId": { + "Ref": "BooksApi60AC975F" + }, + "AuthorizationType": "NONE", + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { "Fn::Join": [ "", [ "arn:", - { "Ref": "AWS::Partition" }, - ":execute-api:", - { "Ref": "AWS::Region" }, - ":", - { "Ref": "AWS::AccountId" }, - ":", - { "Ref": "BooksApi60AC975F" }, - "/test-invoke-stage/GET/books" + { + "Ref": "AWS::Partition" + }, + ":apigateway:", + { + "Ref": "AWS::Region" + }, + ":lambda:path/2015-03-31/functions/", + { + "Fn::ImportValue": "FirstStack:ExportsOutputFnGetAttfirstLambda395F9ADEArn1A9B3BC3" + }, + "/invocations" ] ] } } } - }, - "Outputs": { - "BooksApiEndpointF2AA70A2": { - "Value": { - "Fn::Join": [ - "", - [ - "https://", - { "Ref": "BooksApi60AC975F" }, - ".execute-api.", - { "Ref": "AWS::Region" }, - ".", - { "Ref": "AWS::URLSuffix" }, - "/", - { "Ref": "BooksApiDeploymentStageprod0693B760" }, - "/" - ] + } + }, + "Outputs": { + "BooksApiEndpointF2AA70A2": { + "Value": { + "Fn::Join": [ + "", + [ + "https://", + { + "Ref": "BooksApi60AC975F" + }, + ".execute-api.", + { + "Ref": "AWS::Region" + }, + ".", + { + "Ref": "AWS::URLSuffix" + }, + "/", + { + "Ref": "BooksApiDeploymentStageprod0693B760" + }, + "/" ] - } + ] } } + } } ] \ No newline at end of file diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.multiuse.expected.json b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.multiuse.expected.json index 2a9857028ed40..4a2476fb26669 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.multiuse.expected.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.multiuse.expected.json @@ -50,169 +50,13 @@ "HelloServiceRole1E55EA16" ] }, - "helloapihelloGETApiPermissionrestapimultiuseexamplehelloapi9FD0148DGEThello2FD34BC2": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "Hello4A628BD4", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "helloapi4446A35B" - }, - "/", - { - "Ref": "helloapiDeploymentStageprod677E2C4F" - }, - "/GET/hello" - ] - ] - } - } - }, - "helloapihelloGETApiPermissionTestrestapimultiuseexamplehelloapi9FD0148DGEThelloA58B2FAE": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "Hello4A628BD4", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "helloapi4446A35B" - }, - "/test-invoke-stage/GET/hello" - ] - ] - } - } - }, - "secondapihelloGETApiPermissionrestapimultiuseexamplesecondapi5CB05B89GEThello2D6C1879": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "Hello4A628BD4", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "secondapi730EF3C7" - }, - "/", - { - "Ref": "secondapiDeploymentStageprod40491DF0" - }, - "/GET/hello" - ] - ] - } - } - }, - "secondapihelloGETApiPermissionTestrestapimultiuseexamplesecondapi5CB05B89GEThelloB0B3B749": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "Hello4A628BD4", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "secondapi730EF3C7" - }, - "/test-invoke-stage/GET/hello" - ] - ] - } - } - }, "helloapi4446A35B": { "Type": "AWS::ApiGateway::RestApi", "Properties": { "Name": "hello-api" } }, - "helloapiDeploymentFA89AEEC331621072ce7985d6b7954c9edc6b823": { + "helloapiDeploymentFA89AEEC086c88c5044fbc117bd88fffcee53ab2": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { @@ -232,7 +76,7 @@ "Ref": "helloapi4446A35B" }, "DeploymentId": { - "Ref": "helloapiDeploymentFA89AEEC331621072ce7985d6b7954c9edc6b823" + "Ref": "helloapiDeploymentFA89AEEC086c88c5044fbc117bd88fffcee53ab2" }, "StageName": "prod" } @@ -297,6 +141,84 @@ } } }, + "helloapihelloGETApiPermissionrestapimultiuseexamplehelloapi9FD0148DGEThello2FD34BC2": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "helloapi4446A35B" + }, + "/", + { + "Ref": "helloapiDeploymentStageprod677E2C4F" + }, + "/GET/hello" + ] + ] + } + } + }, + "helloapihelloGETApiPermissionTestrestapimultiuseexamplehelloapi9FD0148DGEThelloA58B2FAE": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "helloapi4446A35B" + }, + "/test-invoke-stage/GET/hello" + ] + ] + } + } + }, "helloapihelloGETE6A58337": { "Type": "AWS::ApiGateway::Method", "Properties": { @@ -343,7 +265,7 @@ "Name": "second-api" } }, - "secondapiDeployment20F2C700049800d8702d4c66b5ee8e4a9eed7b35": { + "secondapiDeployment20F2C7001932445454ace403a6bfe89c1430ff70": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { @@ -363,7 +285,7 @@ "Ref": "secondapi730EF3C7" }, "DeploymentId": { - "Ref": "secondapiDeployment20F2C700049800d8702d4c66b5ee8e4a9eed7b35" + "Ref": "secondapiDeployment20F2C7001932445454ace403a6bfe89c1430ff70" }, "StageName": "prod" } @@ -428,6 +350,84 @@ } } }, + "secondapihelloGETApiPermissionrestapimultiuseexamplesecondapi5CB05B89GEThello2D6C1879": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "secondapi730EF3C7" + }, + "/", + { + "Ref": "secondapiDeploymentStageprod40491DF0" + }, + "/GET/hello" + ] + ] + } + } + }, + "secondapihelloGETApiPermissionTestrestapimultiuseexamplesecondapi5CB05B89GEThelloB0B3B749": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "secondapi730EF3C7" + }, + "/test-invoke-stage/GET/hello" + ] + ] + } + } + }, "secondapihelloGETDC5BBB18": { "Type": "AWS::ApiGateway::Method", "Properties": { diff --git a/packages/@aws-cdk/aws-apigateway/test/lambda/index.ts b/packages/@aws-cdk/aws-apigateway/test/lambda/index.ts new file mode 100644 index 0000000000000..7d18d631a246a --- /dev/null +++ b/packages/@aws-cdk/aws-apigateway/test/lambda/index.ts @@ -0,0 +1,5 @@ +exports.handler = async (_: any) => { + return { + statusCode: 200 + }; +}; \ No newline at end of file diff --git a/packages/@aws-cdk/aws-apigateway/test/test.deployment.ts b/packages/@aws-cdk/aws-apigateway/test/test.deployment.ts index 006a88e2be8fa..0fa3990d3126c 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.deployment.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.deployment.ts @@ -1,12 +1,14 @@ import { expect, haveResource, ResourcePart, SynthUtils } from '@aws-cdk/assert'; -import cdk = require('@aws-cdk/core'); +import lambda = require('@aws-cdk/aws-lambda'); +import { CfnResource, Lazy, Stack } from '@aws-cdk/core'; import { Test } from 'nodeunit'; +import path = require('path'); import apigateway = require('../lib'); export = { 'minimal setup'(test: Test) { // GIVEN - const stack = new cdk.Stack(); + const stack = new Stack(); const api = new apigateway.RestApi(stack, 'api', { deploy: false, cloudWatchRole: false }); api.root.addMethod('GET'); @@ -57,7 +59,7 @@ export = { '"retainDeployments" can be used to control the deletion policy of the resource'(test: Test) { // GIVEN - const stack = new cdk.Stack(); + const stack = new Stack(); const api = new apigateway.RestApi(stack, 'api', { deploy: false, cloudWatchRole: false }); api.root.addMethod('GET'); @@ -110,7 +112,7 @@ export = { '"description" can be set on the deployment'(test: Test) { // GIVEN - const stack = new cdk.Stack(); + const stack = new Stack(); const api = new apigateway.RestApi(stack, 'api', { deploy: false, cloudWatchRole: false }); api.root.addMethod('GET'); @@ -127,7 +129,7 @@ export = { '"addToLogicalId" will "salt" the logical ID of the deployment resource'(test: Test) { // GIVEN - const stack = new cdk.Stack(); + const stack = new Stack(); const api = new apigateway.RestApi(stack, 'api', { deploy: false, cloudWatchRole: false }); const deployment = new apigateway.Deployment(stack, 'deployment', { api }); api.root.addMethod('GET'); @@ -145,7 +147,7 @@ export = { // tokens supported, and are resolved upon synthesis const value = 'hello hello'; - deployment.addToLogicalId({ foo: cdk.Lazy.stringValue({ produce: () => value }) }); + deployment.addToLogicalId({ foo: Lazy.stringValue({ produce: () => value }) }); const template2 = synthesize(); test.ok(template2.Resources.deployment33381975a12dfe81474913364dc31c06e37f9449); @@ -159,12 +161,12 @@ export = { '"addDependency" can be used to add a resource as a dependency'(test: Test) { // GIVEN - const stack = new cdk.Stack(); + const stack = new Stack(); const api = new apigateway.RestApi(stack, 'api', { deploy: false, cloudWatchRole: false }); const deployment = new apigateway.Deployment(stack, 'deployment', { api }); api.root.addMethod('GET'); - const dep = new cdk.CfnResource(stack, 'MyResource', { type: 'foo' }); + const dep = new CfnResource(stack, 'MyResource', { type: 'foo' }); // WHEN deployment.node.addDependency(dep); @@ -175,4 +177,39 @@ export = { test.done(); }, + + 'integration change invalidates deployment'(test: Test) { + // GIVEN + const stack1 = new Stack(); + const stack2 = new Stack(); + const handler1 = new lambda.Function(stack1, 'handler1', { + code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')), + runtime: lambda.Runtime.NODEJS_10_X, + handler: 'index.handler' + }); + const handler2 = new lambda.Function(stack2, 'handler2', { + code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')), + runtime: lambda.Runtime.NODEJS_10_X, + handler: 'index.handler' + }); + + // WHEN + const api1 = new apigateway.RestApi(stack1, 'myapi', { + defaultIntegration: new apigateway.LambdaIntegration(handler1) + }); + const api2 = new apigateway.RestApi(stack2, 'myapi', { + defaultIntegration: new apigateway.LambdaIntegration(handler2) + }); + api1.root.addMethod('GET'); + api2.root.addMethod('GET'); + + // THEN + expect(stack1).to(haveResource('AWS::ApiGateway::Stage', { + DeploymentId: { Ref: 'myapiDeploymentB7EF8EB7e0b8372768854261d2d1218739e0a307' } + })); + expect(stack2).to(haveResource('AWS::ApiGateway::Stage', { + DeploymentId: { Ref: 'myapiDeploymentB7EF8EB77c517352b0f7ab73c333e36585c8f1f3' } + })); + test.done(); + } }; diff --git a/packages/@aws-cdk/aws-route53-targets/test/integ.api-gateway-domain-name.expected.json b/packages/@aws-cdk/aws-route53-targets/test/integ.api-gateway-domain-name.expected.json index 305fe4aefc6e6..363a0fcad013c 100644 --- a/packages/@aws-cdk/aws-route53-targets/test/integ.api-gateway-domain-name.expected.json +++ b/packages/@aws-cdk/aws-route53-targets/test/integ.api-gateway-domain-name.expected.json @@ -212,7 +212,7 @@ "Name": "api" } }, - "apiDeployment149F1294105e69daf383d35e4d5131c97d37f9f8": { + "apiDeployment149F12949ab8cbc5717926c7a1a01815778330c4": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { @@ -233,7 +233,7 @@ "Ref": "apiC8550315" }, "DeploymentId": { - "Ref": "apiDeployment149F1294105e69daf383d35e4d5131c97d37f9f8" + "Ref": "apiDeployment149F12949ab8cbc5717926c7a1a01815778330c4" }, "StageName": "prod" } diff --git a/packages/decdk/test/__snapshots__/synth.test.js.snap b/packages/decdk/test/__snapshots__/synth.test.js.snap index 448db3229136d..eb08f19ae2fcc 100644 --- a/packages/decdk/test/__snapshots__/synth.test.js.snap +++ b/packages/decdk/test/__snapshots__/synth.test.js.snap @@ -423,7 +423,7 @@ Object { }, "Type": "AWS::IAM::Role", }, - "MyApiDeploymentECB0D05E2f18928c76b78fb3e3f06fb75c7e195c": Object { + "MyApiDeploymentECB0D05Ed646248a19f9620d956e9fa33de3ed89": Object { "DependsOn": Array [ "GetRootA9424890", "MyApiproxyANYFCF46C66", @@ -441,7 +441,7 @@ Object { "MyApiDeploymentStageprodE1054AF0": Object { "Properties": Object { "DeploymentId": Object { - "Ref": "MyApiDeploymentECB0D05E2f18928c76b78fb3e3f06fb75c7e195c", + "Ref": "MyApiDeploymentECB0D05Ed646248a19f9620d956e9fa33de3ed89", }, "RestApiId": Object { "Ref": "MyApi49610EDF", @@ -1194,7 +1194,7 @@ Object { }, "Type": "AWS::IAM::Role", }, - "lambdaeventsHelloWorldFunctionAB27BB65ApiEventSourceA7A86A4FDeploymentFF3F4A1A61cb9465f6a55a6eaadc6dd0ea839d94": Object { + "lambdaeventsHelloWorldFunctionAB27BB65ApiEventSourceA7A86A4FDeploymentFF3F4A1Aa119fa0e654d84489ef88606c21a73fb": Object { "DependsOn": Array [ "lambdaeventsHelloWorldFunctionAB27BB65ApiEventSourceA7A86A4FhelloGET04FBC7F6", "lambdaeventsHelloWorldFunctionAB27BB65ApiEventSourceA7A86A4FhelloPOST53F177B1", @@ -1211,7 +1211,7 @@ Object { "lambdaeventsHelloWorldFunctionAB27BB65ApiEventSourceA7A86A4FDeploymentStageprod6A86C016": Object { "Properties": Object { "DeploymentId": Object { - "Ref": "lambdaeventsHelloWorldFunctionAB27BB65ApiEventSourceA7A86A4FDeploymentFF3F4A1A61cb9465f6a55a6eaadc6dd0ea839d94", + "Ref": "lambdaeventsHelloWorldFunctionAB27BB65ApiEventSourceA7A86A4FDeploymentFF3F4A1Aa119fa0e654d84489ef88606c21a73fb", }, "RestApiId": Object { "Ref": "lambdaeventsHelloWorldFunctionAB27BB65ApiEventSourceA7A86A4F12449C5F", diff --git a/packages/decdk/test/fixture/tsconfig.json b/packages/decdk/test/fixture/tsconfig.json index ff2e74deda5ca..ff97fed386484 100644 --- a/packages/decdk/test/fixture/tsconfig.json +++ b/packages/decdk/test/fixture/tsconfig.json @@ -20,7 +20,7 @@ "resolveJsonModule": true, "strict": true, "strictNullChecks": true, - "strictPropertyInitialization": false, + "strictPropertyInitialization": true, "stripInternal": true, "target": "ES2017" },