From ed8b903f4912ae6eb11d74401efdc691669252a8 Mon Sep 17 00:00:00 2001 From: Andrew Huo Date: Thu, 30 Jan 2025 20:59:57 -0800 Subject: [PATCH 1/4] feat(aws-stepfunctions-tasks): allow region override in call-rest-api task --- .../lib/apigateway/call-rest-api.ts | 13 +++-- .../test/apigateway/call-rest-api.test.ts | 53 +++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts index c3703205a34c9..27ab819aad247 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts @@ -19,6 +19,13 @@ export interface CallApiGatewayRestApiEndpointProps extends CallApiGatewayEndpoi * Name of the stage where the API is deployed to in API Gateway */ readonly stageName: string; + + /** + * AWS region, e.g. 'us-east-1', where the API is deployed. Uses the region of the Stack + * containing `api`if no region is provided. + * @default the region of the Stack of the `api` in these props + */ + readonly region?: string; } /** @@ -56,15 +63,15 @@ export class CallApiGatewayRestApiEndpoint extends CallApiGatewayEndpointBase { constructor(scope: Construct, id: string, private readonly props: CallApiGatewayRestApiEndpointProps) { super(scope, id, props); - this.apiEndpoint = this.getApiEndpoint(); + this.apiEndpoint = this.getApiEndpoint(props.region); this.arnForExecuteApi = props.api.arnForExecuteApi(props.method, props.apiPath, props.stageName); this.stageName = props.stageName; this.taskPolicies = this.createPolicyStatements(); } - private getApiEndpoint(): string { + private getApiEndpoint(region?: string): string { const apiStack = cdk.Stack.of(this.props.api); - return `${this.props.api.restApiId}.execute-api.${apiStack.region}.${apiStack.urlSuffix}`; + return `${this.props.api.restApiId}.execute-api.${region ?? apiStack.region}.${apiStack.urlSuffix}`; } } diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts index ff3349acd43ec..a2d2368d3b087 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts @@ -58,6 +58,59 @@ describe('CallApiGatewayRestApiEndpoint', () => { }); }); + test('provide region override', () => { + // GIVEN + const stack = new cdk.Stack(); + const restApi = new apigateway.RestApi(stack, 'RestApi'); + const region = 'us-west-2'; + + // WHEN + const task = new CallApiGatewayRestApiEndpoint(stack, 'Call', { + api: restApi, + method: HttpMethod.GET, + stageName: 'dev', + region: region, + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + End: true, + Parameters: { + ApiEndpoint: { + 'Fn::Join': [ + '', + [ + { + Ref: 'RestApi0C43BF4B', + }, + `.execute-api.${region}.`, + { + Ref: 'AWS::URLSuffix', + }, + ], + ], + }, + AuthType: 'NO_AUTH', + Method: 'GET', + Stage: 'dev', + }, + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::apigateway:invoke', + ], + ], + }, + }); + }); + + test('wait for task token', () => { // GIVEN const stack = new cdk.Stack(); From 56c2338bead0dbda14964cd2027dfbb4bbf5f065 Mon Sep 17 00:00:00 2001 From: Andrew Huo Date: Thu, 30 Jan 2025 20:59:57 -0800 Subject: [PATCH 2/4] feat(aws-stepfunctions-tasks): allow region override in call-rest-api task --- .../CallRestApiInteg-ApiStack.assets.json | 20 + .../CallRestApiInteg-ApiStack.template.json | 386 ++++++++++ .../CallRestApiInteg-SfnStack.assets.json | 20 + .../CallRestApiInteg-SfnStack.template.json | 36 + ...efaultTestDeployAssert2A1021D3.assets.json | 19 + ...aultTestDeployAssert2A1021D3.template.json | 36 + .../cdk.out | 1 + .../integ.json | 13 + .../manifest.json | 245 +++++++ .../tree.json | 686 ++++++++++++++++++ .../integ.call-rest-api-cross-region.ts | 58 ++ .../aws-stepfunctions-tasks/README.md | 17 + .../test/apigateway/call-rest-api.test.ts | 1 - 13 files changed, 1537 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/callrestapicrossregionDefaultTestDeployAssert2A1021D3.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/callrestapicrossregionDefaultTestDeployAssert2A1021D3.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.assets.json new file mode 100644 index 0000000000000..18f2054213a6c --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.assets.json @@ -0,0 +1,20 @@ +{ + "version": "39.0.0", + "files": { + "616dcb4adca0395435735b413925e2b0bf5438f24891731f4c263abe5dae7866": { + "source": { + "path": "CallRestApiInteg-ApiStack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-us-west-2": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-west-2", + "objectKey": "616dcb4adca0395435735b413925e2b0bf5438f24891731f4c263abe5dae7866.json", + "region": "us-west-2", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-west-2" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.template.json new file mode 100644 index 0000000000000..6013577328c95 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.template.json @@ -0,0 +1,386 @@ +{ + "Resources": { + "MyRestApi2D1F47A9": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Name": "MyRestApi" + } + }, + "MyRestApiCloudWatchRoleD4042E8E": { + "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" + ] + ] + } + ] + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + }, + "MyRestApiAccount2FB6DB7A": { + "Type": "AWS::ApiGateway::Account", + "Properties": { + "CloudWatchRoleArn": { + "Fn::GetAtt": [ + "MyRestApiCloudWatchRoleD4042E8E", + "Arn" + ] + } + }, + "DependsOn": [ + "MyRestApi2D1F47A9" + ], + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + }, + "MyRestApiDeploymentB555B5824a2dace0b77d6e14d0cc32d4d28422f3": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "Description": "Automatically created by the RestApi construct", + "RestApiId": { + "Ref": "MyRestApi2D1F47A9" + } + }, + "DependsOn": [ + "MyRestApiANY05143F93" + ] + }, + "MyRestApiDeploymentStageprodC33B8E5F": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "MyRestApiDeploymentB555B5824a2dace0b77d6e14d0cc32d4d28422f3" + }, + "RestApiId": { + "Ref": "MyRestApi2D1F47A9" + }, + "StageName": "prod" + }, + "DependsOn": [ + "MyRestApiAccount2FB6DB7A" + ] + }, + "MyRestApiANYApiPermissionCallRestApiIntegApiStackMyRestApiC2593C7AANY7E91F016": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:aws:execute-api:us-west-2:", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyRestApi2D1F47A9" + }, + "/", + { + "Ref": "MyRestApiDeploymentStageprodC33B8E5F" + }, + "/*/" + ] + ] + } + } + }, + "MyRestApiANYApiPermissionTestCallRestApiIntegApiStackMyRestApiC2593C7AANY4B5F396C": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:aws:execute-api:us-west-2:", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyRestApi2D1F47A9" + }, + "/test-invoke-stage/*/" + ] + ] + } + } + }, + "MyRestApiANY05143F93": { + "Type": "AWS::ApiGateway::Method", + "Properties": { + "AuthorizationType": "NONE", + "HttpMethod": "ANY", + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { + "Fn::Join": [ + "", + [ + "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/", + { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "/invocations" + ] + ] + } + }, + "ResourceId": { + "Fn::GetAtt": [ + "MyRestApi2D1F47A9", + "RootResourceId" + ] + }, + "RestApiId": { + "Ref": "MyRestApi2D1F47A9" + } + } + }, + "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 = async function(event, context) { return { statusCode: 200, body: \"hello, world!\" }; };" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "HelloServiceRole1E55EA16", + "Arn" + ] + }, + "Runtime": "nodejs18.x" + }, + "DependsOn": [ + "HelloServiceRole1E55EA16" + ] + }, + "StateMachineRoleB840431D": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "states.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "StateMachineRoleDefaultPolicyDF1E6607": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:execute-api:us-west-2:", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyRestApi2D1F47A9" + }, + "/prod/GET/*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRoleDefaultPolicyDF1E6607", + "Roles": [ + { + "Ref": "StateMachineRoleB840431D" + } + ] + } + }, + "StateMachine2E01A3A5": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"Call APIGW\",\"States\":{\"Call APIGW\":{\"End\":true,\"Type\":\"Task\",\"OutputPath\":\"$.ResponseBody\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::apigateway:invoke\",\"Parameters\":{\"ApiEndpoint\":\"", + { + "Ref": "MyRestApi2D1F47A9" + }, + ".execute-api.us-west-2.", + { + "Ref": "AWS::URLSuffix" + }, + "\",\"Method\":\"GET\",\"Stage\":\"prod\",\"AuthType\":\"IAM_ROLE\"}}},\"TimeoutSeconds\":30}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRoleB840431D", + "Arn" + ] + } + }, + "DependsOn": [ + "StateMachineRoleDefaultPolicyDF1E6607", + "StateMachineRoleB840431D" + ], + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + } + }, + "Outputs": { + "MyRestApiEndpoint4C55E4CB": { + "Value": { + "Fn::Join": [ + "", + [ + "https://", + { + "Ref": "MyRestApi2D1F47A9" + }, + ".execute-api.us-west-2.", + { + "Ref": "AWS::URLSuffix" + }, + "/", + { + "Ref": "MyRestApiDeploymentStageprodC33B8E5F" + }, + "/" + ] + ] + } + }, + "stateMachineArn": { + "Value": { + "Ref": "StateMachine2E01A3A5" + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json new file mode 100644 index 0000000000000..c020d890362c2 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json @@ -0,0 +1,20 @@ +{ + "version": "39.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "CallRestApiInteg-SfnStack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-us-east-1": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "region": "us-east-1", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-1" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/callrestapicrossregionDefaultTestDeployAssert2A1021D3.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/callrestapicrossregionDefaultTestDeployAssert2A1021D3.assets.json new file mode 100644 index 0000000000000..10220f226185b --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/callrestapicrossregionDefaultTestDeployAssert2A1021D3.assets.json @@ -0,0 +1,19 @@ +{ + "version": "39.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "callrestapicrossregionDefaultTestDeployAssert2A1021D3.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/callrestapicrossregionDefaultTestDeployAssert2A1021D3.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/callrestapicrossregionDefaultTestDeployAssert2A1021D3.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/callrestapicrossregionDefaultTestDeployAssert2A1021D3.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/cdk.out new file mode 100644 index 0000000000000..91e1a8b9901d5 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"39.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/integ.json new file mode 100644 index 0000000000000..ad32065ed6025 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/integ.json @@ -0,0 +1,13 @@ +{ + "version": "39.0.0", + "testCases": { + "call-rest-api-cross-region/DefaultTest": { + "stacks": [ + "CallRestApiInteg-ApiStack", + "CallRestApiInteg-SfnStack" + ], + "assertionStack": "call-rest-api-cross-region/DefaultTest/DeployAssert", + "assertionStackName": "callrestapicrossregionDefaultTestDeployAssert2A1021D3" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json new file mode 100644 index 0000000000000..2c54fe3a6adbf --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json @@ -0,0 +1,245 @@ +{ + "version": "39.0.0", + "artifacts": { + "CallRestApiInteg-ApiStack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "CallRestApiInteg-ApiStack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "CallRestApiInteg-ApiStack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/us-west-2", + "properties": { + "templateFile": "CallRestApiInteg-ApiStack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-us-west-2", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-us-west-2", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-west-2/616dcb4adca0395435735b413925e2b0bf5438f24891731f4c263abe5dae7866.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "CallRestApiInteg-ApiStack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-us-west-2", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "CallRestApiInteg-ApiStack.assets" + ], + "metadata": { + "/CallRestApiInteg-ApiStack/MyRestApi/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyRestApi2D1F47A9" + } + ], + "/CallRestApiInteg-ApiStack/MyRestApi/CloudWatchRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyRestApiCloudWatchRoleD4042E8E" + } + ], + "/CallRestApiInteg-ApiStack/MyRestApi/Account": [ + { + "type": "aws:cdk:logicalId", + "data": "MyRestApiAccount2FB6DB7A" + } + ], + "/CallRestApiInteg-ApiStack/MyRestApi/Deployment/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyRestApiDeploymentB555B5824a2dace0b77d6e14d0cc32d4d28422f3" + } + ], + "/CallRestApiInteg-ApiStack/MyRestApi/DeploymentStage.prod/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyRestApiDeploymentStageprodC33B8E5F" + } + ], + "/CallRestApiInteg-ApiStack/MyRestApi/Endpoint": [ + { + "type": "aws:cdk:logicalId", + "data": "MyRestApiEndpoint4C55E4CB" + } + ], + "/CallRestApiInteg-ApiStack/MyRestApi/Default/ANY/ApiPermission.CallRestApiIntegApiStackMyRestApiC2593C7A.ANY..": [ + { + "type": "aws:cdk:logicalId", + "data": "MyRestApiANYApiPermissionCallRestApiIntegApiStackMyRestApiC2593C7AANY7E91F016" + } + ], + "/CallRestApiInteg-ApiStack/MyRestApi/Default/ANY/ApiPermission.Test.CallRestApiIntegApiStackMyRestApiC2593C7A.ANY..": [ + { + "type": "aws:cdk:logicalId", + "data": "MyRestApiANYApiPermissionTestCallRestApiIntegApiStackMyRestApiC2593C7AANY4B5F396C" + } + ], + "/CallRestApiInteg-ApiStack/MyRestApi/Default/ANY/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyRestApiANY05143F93" + } + ], + "/CallRestApiInteg-ApiStack/Hello/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "HelloServiceRole1E55EA16" + } + ], + "/CallRestApiInteg-ApiStack/Hello/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Hello4A628BD4" + } + ], + "/CallRestApiInteg-ApiStack/StateMachine/Role/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "StateMachineRoleB840431D" + } + ], + "/CallRestApiInteg-ApiStack/StateMachine/Role/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "StateMachineRoleDefaultPolicyDF1E6607" + } + ], + "/CallRestApiInteg-ApiStack/StateMachine/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "StateMachine2E01A3A5" + } + ], + "/CallRestApiInteg-ApiStack/stateMachineArn": [ + { + "type": "aws:cdk:logicalId", + "data": "stateMachineArn" + } + ], + "/CallRestApiInteg-ApiStack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/CallRestApiInteg-ApiStack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "CallRestApiInteg-ApiStack" + }, + "CallRestApiInteg-SfnStack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "CallRestApiInteg-SfnStack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "CallRestApiInteg-SfnStack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/us-east-1", + "properties": { + "templateFile": "CallRestApiInteg-SfnStack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-us-east-1", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-us-east-1", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "CallRestApiInteg-SfnStack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-us-east-1", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "CallRestApiInteg-SfnStack.assets" + ], + "metadata": { + "/CallRestApiInteg-SfnStack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/CallRestApiInteg-SfnStack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "CallRestApiInteg-SfnStack" + }, + "callrestapicrossregionDefaultTestDeployAssert2A1021D3.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "callrestapicrossregionDefaultTestDeployAssert2A1021D3.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "callrestapicrossregionDefaultTestDeployAssert2A1021D3": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "callrestapicrossregionDefaultTestDeployAssert2A1021D3.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "callrestapicrossregionDefaultTestDeployAssert2A1021D3.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "callrestapicrossregionDefaultTestDeployAssert2A1021D3.assets" + ], + "metadata": { + "/call-rest-api-cross-region/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/call-rest-api-cross-region/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "call-rest-api-cross-region/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json new file mode 100644 index 0000000000000..e1263e2f31dbe --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json @@ -0,0 +1,686 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "CallRestApiInteg-ApiStack": { + "id": "CallRestApiInteg-ApiStack", + "path": "CallRestApiInteg-ApiStack", + "children": { + "MyRestApi": { + "id": "MyRestApi", + "path": "CallRestApiInteg-ApiStack/MyRestApi", + "children": { + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/MyRestApi/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApiGateway::RestApi", + "aws:cdk:cloudformation:props": { + "name": "MyRestApi" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.CfnRestApi", + "version": "0.0.0" + } + }, + "CloudWatchRole": { + "id": "CloudWatchRole", + "path": "CallRestApiInteg-ApiStack/MyRestApi/CloudWatchRole", + "children": { + "ImportCloudWatchRole": { + "id": "ImportCloudWatchRole", + "path": "CallRestApiInteg-ApiStack/MyRestApi/CloudWatchRole/ImportCloudWatchRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/MyRestApi/CloudWatchRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "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" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Account": { + "id": "Account", + "path": "CallRestApiInteg-ApiStack/MyRestApi/Account", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApiGateway::Account", + "aws:cdk:cloudformation:props": { + "cloudWatchRoleArn": { + "Fn::GetAtt": [ + "MyRestApiCloudWatchRoleD4042E8E", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.CfnAccount", + "version": "0.0.0" + } + }, + "Deployment": { + "id": "Deployment", + "path": "CallRestApiInteg-ApiStack/MyRestApi/Deployment", + "children": { + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/MyRestApi/Deployment/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApiGateway::Deployment", + "aws:cdk:cloudformation:props": { + "description": "Automatically created by the RestApi construct", + "restApiId": { + "Ref": "MyRestApi2D1F47A9" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.CfnDeployment", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.Deployment", + "version": "0.0.0" + } + }, + "DeploymentStage.prod": { + "id": "DeploymentStage.prod", + "path": "CallRestApiInteg-ApiStack/MyRestApi/DeploymentStage.prod", + "children": { + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/MyRestApi/DeploymentStage.prod/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApiGateway::Stage", + "aws:cdk:cloudformation:props": { + "deploymentId": { + "Ref": "MyRestApiDeploymentB555B5824a2dace0b77d6e14d0cc32d4d28422f3" + }, + "restApiId": { + "Ref": "MyRestApi2D1F47A9" + }, + "stageName": "prod" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.CfnStage", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.Stage", + "version": "0.0.0" + } + }, + "Endpoint": { + "id": "Endpoint", + "path": "CallRestApiInteg-ApiStack/MyRestApi/Endpoint", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnOutput", + "version": "0.0.0" + } + }, + "Default": { + "id": "Default", + "path": "CallRestApiInteg-ApiStack/MyRestApi/Default", + "children": { + "ANY": { + "id": "ANY", + "path": "CallRestApiInteg-ApiStack/MyRestApi/Default/ANY", + "children": { + "ApiPermission.CallRestApiIntegApiStackMyRestApiC2593C7A.ANY..": { + "id": "ApiPermission.CallRestApiIntegApiStackMyRestApiC2593C7A.ANY..", + "path": "CallRestApiInteg-ApiStack/MyRestApi/Default/ANY/ApiPermission.CallRestApiIntegApiStackMyRestApiC2593C7A.ANY..", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Permission", + "aws:cdk:cloudformation:props": { + "action": "lambda:InvokeFunction", + "functionName": { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "principal": "apigateway.amazonaws.com", + "sourceArn": { + "Fn::Join": [ + "", + [ + "arn:aws:execute-api:us-west-2:", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyRestApi2D1F47A9" + }, + "/", + { + "Ref": "MyRestApiDeploymentStageprodC33B8E5F" + }, + "/*/" + ] + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnPermission", + "version": "0.0.0" + } + }, + "ApiPermission.Test.CallRestApiIntegApiStackMyRestApiC2593C7A.ANY..": { + "id": "ApiPermission.Test.CallRestApiIntegApiStackMyRestApiC2593C7A.ANY..", + "path": "CallRestApiInteg-ApiStack/MyRestApi/Default/ANY/ApiPermission.Test.CallRestApiIntegApiStackMyRestApiC2593C7A.ANY..", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Permission", + "aws:cdk:cloudformation:props": { + "action": "lambda:InvokeFunction", + "functionName": { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "principal": "apigateway.amazonaws.com", + "sourceArn": { + "Fn::Join": [ + "", + [ + "arn:aws:execute-api:us-west-2:", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyRestApi2D1F47A9" + }, + "/test-invoke-stage/*/" + ] + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnPermission", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/MyRestApi/Default/ANY/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApiGateway::Method", + "aws:cdk:cloudformation:props": { + "authorizationType": "NONE", + "httpMethod": "ANY", + "integration": { + "type": "AWS_PROXY", + "uri": { + "Fn::Join": [ + "", + [ + "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/", + { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "/invocations" + ] + ] + }, + "integrationHttpMethod": "POST" + }, + "resourceId": { + "Fn::GetAtt": [ + "MyRestApi2D1F47A9", + "RootResourceId" + ] + }, + "restApiId": { + "Ref": "MyRestApi2D1F47A9" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.CfnMethod", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.Method", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.ResourceBase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.RestApi", + "version": "0.0.0" + } + }, + "Hello": { + "id": "Hello", + "path": "CallRestApiInteg-ApiStack/Hello", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "CallRestApiInteg-ApiStack/Hello/ServiceRole", + "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "CallRestApiInteg-ApiStack/Hello/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/Hello/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "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" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/Hello/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "zipFile": "exports.handler = async function(event, context) { return { statusCode: 200, body: \"hello, world!\" }; };" + }, + "handler": "index.handler", + "role": { + "Fn::GetAtt": [ + "HelloServiceRole1E55EA16", + "Arn" + ] + }, + "runtime": "nodejs18.x" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnFunction", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.Function", + "version": "0.0.0" + } + }, + "StateMachine": { + "id": "StateMachine", + "path": "CallRestApiInteg-ApiStack/StateMachine", + "children": { + "Role": { + "id": "Role", + "path": "CallRestApiInteg-ApiStack/StateMachine/Role", + "children": { + "ImportRole": { + "id": "ImportRole", + "path": "CallRestApiInteg-ApiStack/StateMachine/Role/ImportRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/StateMachine/Role/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "states.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "CallRestApiInteg-ApiStack/StateMachine/Role/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/StateMachine/Role/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:execute-api:us-west-2:", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyRestApi2D1F47A9" + }, + "/prod/GET/*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "StateMachineRoleDefaultPolicyDF1E6607", + "roles": [ + { + "Ref": "StateMachineRoleB840431D" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Policy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/StateMachine/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::StepFunctions::StateMachine", + "aws:cdk:cloudformation:props": { + "definitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"Call APIGW\",\"States\":{\"Call APIGW\":{\"End\":true,\"Type\":\"Task\",\"OutputPath\":\"$.ResponseBody\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::apigateway:invoke\",\"Parameters\":{\"ApiEndpoint\":\"", + { + "Ref": "MyRestApi2D1F47A9" + }, + ".execute-api.us-west-2.", + { + "Ref": "AWS::URLSuffix" + }, + "\",\"Method\":\"GET\",\"Stage\":\"prod\",\"AuthType\":\"IAM_ROLE\"}}},\"TimeoutSeconds\":30}" + ] + ] + }, + "roleArn": { + "Fn::GetAtt": [ + "StateMachineRoleB840431D", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions.CfnStateMachine", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions.StateMachine", + "version": "0.0.0" + } + }, + "stateMachineArn": { + "id": "stateMachineArn", + "path": "CallRestApiInteg-ApiStack/stateMachineArn", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnOutput", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "CallRestApiInteg-ApiStack/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "CallRestApiInteg-ApiStack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "CallRestApiInteg-SfnStack": { + "id": "CallRestApiInteg-SfnStack", + "path": "CallRestApiInteg-SfnStack", + "children": { + "Call APIGW": { + "id": "Call APIGW", + "path": "CallRestApiInteg-SfnStack/Call APIGW", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions_tasks.CallApiGatewayRestApiEndpoint", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "CallRestApiInteg-SfnStack/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "CallRestApiInteg-SfnStack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "call-rest-api-cross-region": { + "id": "call-rest-api-cross-region", + "path": "call-rest-api-cross-region", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "call-rest-api-cross-region/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "call-rest-api-cross-region/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "call-rest-api-cross-region/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "call-rest-api-cross-region/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "call-rest-api-cross-region/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts new file mode 100644 index 0000000000000..619c616cc16fc --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts @@ -0,0 +1,58 @@ +import * as apigateway from 'aws-cdk-lib/aws-apigateway'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; +import * as sfn from 'aws-cdk-lib/aws-stepfunctions'; +import * as cdk from 'aws-cdk-lib'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import { AuthType, HttpMethod, CallApiGatewayRestApiEndpoint } from 'aws-cdk-lib/aws-stepfunctions-tasks'; +import { STANDARD_NODEJS_RUNTIME } from '../../../config'; + +/* + * Stack verification steps: + * * aws stepfunctions start-execution --state-machine-arn : should return execution arn + * + * * aws stepfunctions describe-execution --execution-arn --query 'status': should return status as SUCCEEDED + * * aws stepfunctions describe-execution --execution-arn --query 'output': should return the string \"hello, world!\" + */ + +const app = new cdk.App(); +const apiStack = new cdk.Stack(app, 'CallRestApiInteg-ApiStack', { + env: { + region: 'us-west-2', + }, +}); +const sfnStack = new cdk.Stack(app, 'CallRestApiInteg-SfnStack', { + env: { + region: 'us-east-1', + }, +}); +const restApi = new apigateway.RestApi(apiStack, 'MyRestApi', { cloudWatchRole: true }); + +const hello = new apigateway.LambdaIntegration(new lambda.Function(apiStack, 'Hello', { + runtime: STANDARD_NODEJS_RUNTIME, + handler: 'index.handler', + code: new lambda.InlineCode('exports.handler = async function(event, context) { return { statusCode: 200, body: "hello, world!" }; };'), +})); +restApi.root.addMethod('ANY', hello); + +const callEndpointJob = new CallApiGatewayRestApiEndpoint(sfnStack, 'Call APIGW', { + api: restApi, + stageName: 'prod', + method: HttpMethod.GET, + authType: AuthType.IAM_ROLE, + outputPath: sfn.JsonPath.stringAt('$.ResponseBody'), +}); + +const chain = sfn.Chain.start(callEndpointJob); + +const sm = new sfn.StateMachine(apiStack, 'StateMachine', { + definition: chain, + timeout: cdk.Duration.seconds(30), +}); + +new cdk.CfnOutput(apiStack, 'stateMachineArn', { + value: sm.stateMachineArn, +}); + +new IntegTest(app, 'call-rest-api-cross-region', { + testCases: [apiStack, sfnStack], +}); diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md b/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md index 0247a7bb05be1..fad0973c674be 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md @@ -155,6 +155,23 @@ const invokeTask = new tasks.CallApiGatewayRestApiEndpoint(this, 'Call REST API' }); ``` +By default, the API endpoint URI will be constructed using the AWS region of +the stack in which the provided `api` is created. Passing in a `region` string, +such as `us-west-2`, will instead construct the endpoint with the given region: + +```ts +import * as apigateway from 'aws-cdk-lib/aws-apigateway'; +const restApi = new apigateway.RestApi(this, 'MyRestApi'); +const endpointRegion = 'us-west-2'; + +const invokeTask = new tasks.CallApiGatewayRestApiEndpoint(this, 'Call REST API', { + api: restApi, + stageName: 'prod', + method: tasks.HttpMethod.GET, + region: endpointRegion, +}); +``` + Be aware that the header values must be arrays. When passing the Task Token in the headers field `WAIT_FOR_TASK_TOKEN` integration, use `JsonPath.array()` to wrap the token in an array: diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts index a2d2368d3b087..4d530aa5367b7 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts @@ -110,7 +110,6 @@ describe('CallApiGatewayRestApiEndpoint', () => { }); }); - test('wait for task token', () => { // GIVEN const stack = new cdk.Stack(); From b16caff2f1d76a4ac242be27345adae49f4c13b7 Mon Sep 17 00:00:00 2001 From: Andrew Huo Date: Thu, 30 Jan 2025 23:46:56 -0800 Subject: [PATCH 3/4] fix cross-region rest api task integ test to actually cross regions --- .../CallRestApiInteg-ApiStack.assets.json | 18 +- .../CallRestApiInteg-ApiStack.template.json | 145 ++++++------ .../CallRestApiInteg-SfnStack.assets.json | 18 +- .../CallRestApiInteg-SfnStack.template.json | 201 ++++++++++++++++ .../__entrypoint__.js | 155 +++++++++++++ .../index.js | 5 + .../__entrypoint__.js | 155 +++++++++++++ .../index.js | 1 + .../manifest.json | 71 +++++- .../tree.json | 216 ++++++++++++++---- .../integ.call-rest-api-cross-region.ts | 8 +- 11 files changed, 866 insertions(+), 127 deletions(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b/__entrypoint__.js create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b/index.js create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d/__entrypoint__.js create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d/index.js diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.assets.json index 18f2054213a6c..4f25b81df47c1 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.assets.json @@ -1,7 +1,21 @@ { "version": "39.0.0", "files": { - "616dcb4adca0395435735b413925e2b0bf5438f24891731f4c263abe5dae7866": { + "bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b": { + "source": { + "path": "asset.bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b", + "packaging": "zip" + }, + "destinations": { + "current_account-us-west-2": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-west-2", + "objectKey": "bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b.zip", + "region": "us-west-2", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-west-2" + } + } + }, + "319feecbdd79b561ade2169ee0a835fdb91b5ecaecd5b259a64e78735ae73be0": { "source": { "path": "CallRestApiInteg-ApiStack.template.json", "packaging": "file" @@ -9,7 +23,7 @@ "destinations": { "current_account-us-west-2": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-west-2", - "objectKey": "616dcb4adca0395435735b413925e2b0bf5438f24891731f4c263abe5dae7866.json", + "objectKey": "319feecbdd79b561ade2169ee0a835fdb91b5ecaecd5b259a64e78735ae73be0.json", "region": "us-west-2", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-west-2" } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.template.json index 6013577328c95..b9ae54a163119 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-ApiStack.template.json @@ -229,95 +229,105 @@ "HelloServiceRole1E55EA16" ] }, - "StateMachineRoleB840431D": { + "ExportsWriteruseast10F67B507DDE2E818": { + "Type": "Custom::CrossRegionExportWriter", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "CustomCrossRegionExportWriterCustomResourceProviderHandlerD8786E8A", + "Arn" + ] + }, + "WriterProps": { + "region": "us-east-1", + "exports": { + "/cdk/exports/CallRestApiInteg-SfnStack/CallRestApiIntegApiStackuswest2RefMyRestApi2D1F47A94BF96318": { + "Ref": "MyRestApi2D1F47A9" + } + } + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "CustomCrossRegionExportWriterCustomResourceProviderRoleC951B1E1": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { + "Version": "2012-10-17", "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { - "Service": "states.amazonaws.com" + "Service": "lambda.amazonaws.com" } } - ], - "Version": "2012-10-17" - } - } - }, - "StateMachineRoleDefaultPolicyDF1E6607": { - "Type": "AWS::IAM::Policy", - "Properties": { - "PolicyDocument": { - "Statement": [ - { - "Action": "execute-api:Invoke", - "Effect": "Allow", - "Resource": { - "Fn::Join": [ - "", - [ - "arn:aws:execute-api:us-west-2:", - { - "Ref": "AWS::AccountId" - }, - ":", + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + } + ], + "Policies": [ + { + "PolicyName": "Inline", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Resource": [ { - "Ref": "MyRestApi2D1F47A9" - }, - "/prod/GET/*" + "Fn::Join": [ + "", + [ + "arn:aws:ssm:us-east-1:", + { + "Ref": "AWS::AccountId" + }, + ":parameter/cdk/exports/*" + ] + ] + } + ], + "Action": [ + "ssm:DeleteParameters", + "ssm:ListTagsForResource", + "ssm:GetParameters", + "ssm:PutParameter" ] - ] - } + } + ] } - ], - "Version": "2012-10-17" - }, - "PolicyName": "StateMachineRoleDefaultPolicyDF1E6607", - "Roles": [ - { - "Ref": "StateMachineRoleB840431D" } ] } }, - "StateMachine2E01A3A5": { - "Type": "AWS::StepFunctions::StateMachine", + "CustomCrossRegionExportWriterCustomResourceProviderHandlerD8786E8A": { + "Type": "AWS::Lambda::Function", "Properties": { - "DefinitionString": { - "Fn::Join": [ - "", - [ - "{\"StartAt\":\"Call APIGW\",\"States\":{\"Call APIGW\":{\"End\":true,\"Type\":\"Task\",\"OutputPath\":\"$.ResponseBody\",\"Resource\":\"arn:", - { - "Ref": "AWS::Partition" - }, - ":states:::apigateway:invoke\",\"Parameters\":{\"ApiEndpoint\":\"", - { - "Ref": "MyRestApi2D1F47A9" - }, - ".execute-api.us-west-2.", - { - "Ref": "AWS::URLSuffix" - }, - "\",\"Method\":\"GET\",\"Stage\":\"prod\",\"AuthType\":\"IAM_ROLE\"}}},\"TimeoutSeconds\":30}" - ] - ] + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-west-2" + }, + "S3Key": "bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b.zip" }, - "RoleArn": { + "Timeout": 900, + "MemorySize": 128, + "Handler": "__entrypoint__.handler", + "Role": { "Fn::GetAtt": [ - "StateMachineRoleB840431D", + "CustomCrossRegionExportWriterCustomResourceProviderRoleC951B1E1", "Arn" ] - } + }, + "Runtime": "nodejs20.x" }, "DependsOn": [ - "StateMachineRoleDefaultPolicyDF1E6607", - "StateMachineRoleB840431D" - ], - "UpdateReplacePolicy": "Delete", - "DeletionPolicy": "Delete" + "CustomCrossRegionExportWriterCustomResourceProviderRoleC951B1E1" + ] } }, "Outputs": { @@ -342,11 +352,6 @@ ] ] } - }, - "stateMachineArn": { - "Value": { - "Ref": "StateMachine2E01A3A5" - } } }, "Parameters": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json index c020d890362c2..87af1b7781dc1 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json @@ -1,7 +1,21 @@ { "version": "39.0.0", "files": { - "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d": { + "source": { + "path": "asset.d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d", + "packaging": "zip" + }, + "destinations": { + "current_account-us-east-1": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1", + "objectKey": "d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d.zip", + "region": "us-east-1", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-1" + } + } + }, + "2433e42ae1b4508c1c7fd6e07c37bb4fd69dee68ca495f3a70646d5bf05f9eb3": { "source": { "path": "CallRestApiInteg-SfnStack.template.json", "packaging": "file" @@ -9,7 +23,7 @@ "destinations": { "current_account-us-east-1": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1", - "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "objectKey": "2433e42ae1b4508c1c7fd6e07c37bb4fd69dee68ca495f3a70646d5bf05f9eb3.json", "region": "us-east-1", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-1" } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json index ad9d0fb73d1dd..198499f4a764c 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json @@ -1,4 +1,205 @@ { + "Resources": { + "StateMachineRoleB840431D": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "states.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "StateMachineRoleDefaultPolicyDF1E6607": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:execute-api:us-east-1:", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Fn::GetAtt": [ + "ExportsReader8B249524", + "/cdk/exports/CallRestApiInteg-SfnStack/CallRestApiIntegApiStackuswest2RefMyRestApi2D1F47A94BF96318" + ] + }, + "/prod/GET/*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRoleDefaultPolicyDF1E6607", + "Roles": [ + { + "Ref": "StateMachineRoleB840431D" + } + ] + } + }, + "StateMachine2E01A3A5": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"Call APIGW\",\"States\":{\"Call APIGW\":{\"End\":true,\"Type\":\"Task\",\"OutputPath\":\"$.ResponseBody\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::apigateway:invoke\",\"Parameters\":{\"ApiEndpoint\":\"", + { + "Fn::GetAtt": [ + "ExportsReader8B249524", + "/cdk/exports/CallRestApiInteg-SfnStack/CallRestApiIntegApiStackuswest2RefMyRestApi2D1F47A94BF96318" + ] + }, + ".execute-api.us-east-1.", + { + "Ref": "AWS::URLSuffix" + }, + "\",\"Method\":\"GET\",\"Stage\":\"prod\",\"AuthType\":\"IAM_ROLE\"}}},\"TimeoutSeconds\":30}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRoleB840431D", + "Arn" + ] + } + }, + "DependsOn": [ + "StateMachineRoleDefaultPolicyDF1E6607", + "StateMachineRoleB840431D" + ], + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "ExportsReader8B249524": { + "Type": "Custom::CrossRegionExportReader", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "CustomCrossRegionExportReaderCustomResourceProviderHandler46647B68", + "Arn" + ] + }, + "ReaderProps": { + "region": "us-east-1", + "prefix": "CallRestApiInteg-SfnStack", + "imports": { + "/cdk/exports/CallRestApiInteg-SfnStack/CallRestApiIntegApiStackuswest2RefMyRestApi2D1F47A94BF96318": "{{resolve:ssm:/cdk/exports/CallRestApiInteg-SfnStack/CallRestApiIntegApiStackuswest2RefMyRestApi2D1F47A94BF96318}}" + } + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "CustomCrossRegionExportReaderCustomResourceProviderRole10531BBD": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + } + ], + "Policies": [ + { + "PolicyName": "Inline", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:ssm:us-east-1:", + { + "Ref": "AWS::AccountId" + }, + ":parameter/cdk/exports/CallRestApiInteg-SfnStack/*" + ] + ] + }, + "Action": [ + "ssm:AddTagsToResource", + "ssm:RemoveTagsFromResource", + "ssm:GetParameters" + ] + } + ] + } + } + ] + } + }, + "CustomCrossRegionExportReaderCustomResourceProviderHandler46647B68": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1" + }, + "S3Key": "d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d.zip" + }, + "Timeout": 900, + "MemorySize": 128, + "Handler": "__entrypoint__.handler", + "Role": { + "Fn::GetAtt": [ + "CustomCrossRegionExportReaderCustomResourceProviderRole10531BBD", + "Arn" + ] + }, + "Runtime": "nodejs20.x" + }, + "DependsOn": [ + "CustomCrossRegionExportReaderCustomResourceProviderRole10531BBD" + ] + } + }, + "Outputs": { + "stateMachineArn": { + "Value": { + "Ref": "StateMachine2E01A3A5" + } + } + }, "Parameters": { "BootstrapVersion": { "Type": "AWS::SSM::Parameter::Value", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b/__entrypoint__.js b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b/__entrypoint__.js new file mode 100644 index 0000000000000..ff3a517fba12d --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b/__entrypoint__.js @@ -0,0 +1,155 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.external = void 0; +exports.handler = handler; +exports.withRetries = withRetries; +const https = require("https"); +const url = require("url"); +// for unit tests +exports.external = { + sendHttpRequest: defaultSendHttpRequest, + log: defaultLog, + includeStackTraces: true, + userHandlerIndex: './index', +}; +const CREATE_FAILED_PHYSICAL_ID_MARKER = 'AWSCDK::CustomResourceProviderFramework::CREATE_FAILED'; +const MISSING_PHYSICAL_ID_MARKER = 'AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID'; +async function handler(event, context) { + const sanitizedEvent = { ...event, ResponseURL: '...' }; + exports.external.log(JSON.stringify(sanitizedEvent, undefined, 2)); + // ignore DELETE event when the physical resource ID is the marker that + // indicates that this DELETE is a subsequent DELETE to a failed CREATE + // operation. + if (event.RequestType === 'Delete' && event.PhysicalResourceId === CREATE_FAILED_PHYSICAL_ID_MARKER) { + exports.external.log('ignoring DELETE event caused by a failed CREATE event'); + await submitResponse('SUCCESS', event); + return; + } + try { + // invoke the user handler. this is intentionally inside the try-catch to + // ensure that if there is an error it's reported as a failure to + // cloudformation (otherwise cfn waits). + // eslint-disable-next-line @typescript-eslint/no-require-imports + const userHandler = require(exports.external.userHandlerIndex).handler; + const result = await userHandler(sanitizedEvent, context); + // validate user response and create the combined event + const responseEvent = renderResponse(event, result); + // submit to cfn as success + await submitResponse('SUCCESS', responseEvent); + } + catch (e) { + const resp = { + ...event, + Reason: exports.external.includeStackTraces ? e.stack : e.message, + }; + if (!resp.PhysicalResourceId) { + // special case: if CREATE fails, which usually implies, we usually don't + // have a physical resource id. in this case, the subsequent DELETE + // operation does not have any meaning, and will likely fail as well. to + // address this, we use a marker so the provider framework can simply + // ignore the subsequent DELETE. + if (event.RequestType === 'Create') { + exports.external.log('CREATE failed, responding with a marker physical resource id so that the subsequent DELETE will be ignored'); + resp.PhysicalResourceId = CREATE_FAILED_PHYSICAL_ID_MARKER; + } + else { + // otherwise, if PhysicalResourceId is not specified, something is + // terribly wrong because all other events should have an ID. + exports.external.log(`ERROR: Malformed event. "PhysicalResourceId" is required: ${JSON.stringify(event)}`); + } + } + // this is an actual error, fail the activity altogether and exist. + await submitResponse('FAILED', resp); + } +} +function renderResponse(cfnRequest, handlerResponse = {}) { + // if physical ID is not returned, we have some defaults for you based + // on the request type. + const physicalResourceId = handlerResponse.PhysicalResourceId ?? cfnRequest.PhysicalResourceId ?? cfnRequest.RequestId; + // if we are in DELETE and physical ID was changed, it's an error. + if (cfnRequest.RequestType === 'Delete' && physicalResourceId !== cfnRequest.PhysicalResourceId) { + throw new Error(`DELETE: cannot change the physical resource ID from "${cfnRequest.PhysicalResourceId}" to "${handlerResponse.PhysicalResourceId}" during deletion`); + } + // merge request event and result event (result prevails). + return { + ...cfnRequest, + ...handlerResponse, + PhysicalResourceId: physicalResourceId, + }; +} +async function submitResponse(status, event) { + const json = { + Status: status, + Reason: event.Reason ?? status, + StackId: event.StackId, + RequestId: event.RequestId, + PhysicalResourceId: event.PhysicalResourceId || MISSING_PHYSICAL_ID_MARKER, + LogicalResourceId: event.LogicalResourceId, + NoEcho: event.NoEcho, + Data: event.Data, + }; + const parsedUrl = url.parse(event.ResponseURL); + const loggingSafeUrl = `${parsedUrl.protocol}//${parsedUrl.hostname}/${parsedUrl.pathname}?***`; + exports.external.log('submit response to cloudformation', loggingSafeUrl, json); + const responseBody = JSON.stringify(json); + const req = { + hostname: parsedUrl.hostname, + path: parsedUrl.path, + method: 'PUT', + headers: { + 'content-type': '', + 'content-length': Buffer.byteLength(responseBody, 'utf8'), + }, + }; + const retryOptions = { + attempts: 5, + sleep: 1000, + }; + await withRetries(retryOptions, exports.external.sendHttpRequest)(req, responseBody); +} +async function defaultSendHttpRequest(options, requestBody) { + return new Promise((resolve, reject) => { + try { + const request = https.request(options, (response) => { + response.resume(); // Consume the response but don't care about it + if (!response.statusCode || response.statusCode >= 400) { + reject(new Error(`Unsuccessful HTTP response: ${response.statusCode}`)); + } + else { + resolve(); + } + }); + request.on('error', reject); + request.write(requestBody); + request.end(); + } + catch (e) { + reject(e); + } + }); +} +function defaultLog(fmt, ...params) { + // eslint-disable-next-line no-console + console.log(fmt, ...params); +} +function withRetries(options, fn) { + return async (...xs) => { + let attempts = options.attempts; + let ms = options.sleep; + while (true) { + try { + return await fn(...xs); + } + catch (e) { + if (attempts-- <= 0) { + throw e; + } + await sleep(Math.floor(Math.random() * ms)); + ms *= 2; + } + } + }; +} +async function sleep(ms) { + return new Promise((ok) => setTimeout(ok, ms)); +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b/index.js b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b/index.js new file mode 100644 index 0000000000000..3adfdc90f2d53 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.bbfb567dc956ce71e67ac1f96589821990e2ca48307b93a577bbb345d2de441b/index.js @@ -0,0 +1,5 @@ +"use strict";var a=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var E=(s,t)=>{for(var r in t)a(s,r,{get:t[r],enumerable:!0})},R=(s,t,r,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of f(t))!S.call(s,o)&&o!==r&&a(s,o,{get:()=>t[o],enumerable:!(e=d(t,o))||e.enumerable});return s};var y=s=>R(a({},"__esModule",{value:!0}),s);var O={};E(O,{handler:()=>h});module.exports=y(O);var l=require("@aws-sdk/client-ssm");async function h(s){let t=s.ResourceProperties.WriterProps,r=t.exports,e=new l.SSM({region:t.region});try{switch(s.RequestType){case"Create":console.info(`Creating new SSM Parameter exports in region ${t.region}`),await i(e,r),await u(e,r);return;case"Update":let n=s.OldResourceProperties.WriterProps.exports,c=x(r,n),p=C(n,r);if(p.length>0)throw new Error(`Some exports have changed! +`+p.join(` +`));let g=x(n,r);await i(e,g);let w=Object.keys(g);await m(e,w),await i(e,c),console.info(`Creating new SSM Parameter exports in region ${t.region}`),await u(e,c);return;case"Delete":await i(e,r),await m(e,Object.keys(r));return;default:return}}catch(o){throw console.error("Error processing event: ",o),o}}async function u(s,t){await Promise.all(Array.from(Object.entries(t),([r,e])=>s.putParameter({Name:r,Value:e,Type:"String"})))}async function m(s,t){t.sort();for(let e=0;e0&&await s.deleteParameters({Names:o})}}async function i(s,t){let r=new Map;if(await Promise.all(Object.keys(t).map(async e=>{let o=await P(s,e);o.size>0&&r.set(e,o)})),r.size>0){let e=Array.from(r.entries()).map(o=>`${o[0]} is in use by stack(s) ${Array.from(o[1]).join(" ")}`).join(` +`);throw new Error(`Exports cannot be updated: +${e}`)}}async function P(s,t){let r=new Set;try{(await s.listTagsForResource({ResourceId:t,ResourceType:"Parameter"})).TagList?.forEach(o=>{let n=o.Key?.split(":")??[];n[0]==="aws-cdk"&&n[1]==="strong-ref"&&r.add(n[2])})}catch(e){if(e.name==="InvalidResourceId")return new Set;throw e}return r}function x(s,t){return Object.keys(s).filter(r=>!t.hasOwnProperty(r)).reduce((r,e)=>(r[e]=s[e],r),{})}function C(s,t){return Object.keys(s).filter(r=>t.hasOwnProperty(r)&&s[r]!==t[r]).reduce((r,e)=>(r.push(e),r),[])}0&&(module.exports={handler}); diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d/__entrypoint__.js b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d/__entrypoint__.js new file mode 100644 index 0000000000000..ff3a517fba12d --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d/__entrypoint__.js @@ -0,0 +1,155 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.external = void 0; +exports.handler = handler; +exports.withRetries = withRetries; +const https = require("https"); +const url = require("url"); +// for unit tests +exports.external = { + sendHttpRequest: defaultSendHttpRequest, + log: defaultLog, + includeStackTraces: true, + userHandlerIndex: './index', +}; +const CREATE_FAILED_PHYSICAL_ID_MARKER = 'AWSCDK::CustomResourceProviderFramework::CREATE_FAILED'; +const MISSING_PHYSICAL_ID_MARKER = 'AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID'; +async function handler(event, context) { + const sanitizedEvent = { ...event, ResponseURL: '...' }; + exports.external.log(JSON.stringify(sanitizedEvent, undefined, 2)); + // ignore DELETE event when the physical resource ID is the marker that + // indicates that this DELETE is a subsequent DELETE to a failed CREATE + // operation. + if (event.RequestType === 'Delete' && event.PhysicalResourceId === CREATE_FAILED_PHYSICAL_ID_MARKER) { + exports.external.log('ignoring DELETE event caused by a failed CREATE event'); + await submitResponse('SUCCESS', event); + return; + } + try { + // invoke the user handler. this is intentionally inside the try-catch to + // ensure that if there is an error it's reported as a failure to + // cloudformation (otherwise cfn waits). + // eslint-disable-next-line @typescript-eslint/no-require-imports + const userHandler = require(exports.external.userHandlerIndex).handler; + const result = await userHandler(sanitizedEvent, context); + // validate user response and create the combined event + const responseEvent = renderResponse(event, result); + // submit to cfn as success + await submitResponse('SUCCESS', responseEvent); + } + catch (e) { + const resp = { + ...event, + Reason: exports.external.includeStackTraces ? e.stack : e.message, + }; + if (!resp.PhysicalResourceId) { + // special case: if CREATE fails, which usually implies, we usually don't + // have a physical resource id. in this case, the subsequent DELETE + // operation does not have any meaning, and will likely fail as well. to + // address this, we use a marker so the provider framework can simply + // ignore the subsequent DELETE. + if (event.RequestType === 'Create') { + exports.external.log('CREATE failed, responding with a marker physical resource id so that the subsequent DELETE will be ignored'); + resp.PhysicalResourceId = CREATE_FAILED_PHYSICAL_ID_MARKER; + } + else { + // otherwise, if PhysicalResourceId is not specified, something is + // terribly wrong because all other events should have an ID. + exports.external.log(`ERROR: Malformed event. "PhysicalResourceId" is required: ${JSON.stringify(event)}`); + } + } + // this is an actual error, fail the activity altogether and exist. + await submitResponse('FAILED', resp); + } +} +function renderResponse(cfnRequest, handlerResponse = {}) { + // if physical ID is not returned, we have some defaults for you based + // on the request type. + const physicalResourceId = handlerResponse.PhysicalResourceId ?? cfnRequest.PhysicalResourceId ?? cfnRequest.RequestId; + // if we are in DELETE and physical ID was changed, it's an error. + if (cfnRequest.RequestType === 'Delete' && physicalResourceId !== cfnRequest.PhysicalResourceId) { + throw new Error(`DELETE: cannot change the physical resource ID from "${cfnRequest.PhysicalResourceId}" to "${handlerResponse.PhysicalResourceId}" during deletion`); + } + // merge request event and result event (result prevails). + return { + ...cfnRequest, + ...handlerResponse, + PhysicalResourceId: physicalResourceId, + }; +} +async function submitResponse(status, event) { + const json = { + Status: status, + Reason: event.Reason ?? status, + StackId: event.StackId, + RequestId: event.RequestId, + PhysicalResourceId: event.PhysicalResourceId || MISSING_PHYSICAL_ID_MARKER, + LogicalResourceId: event.LogicalResourceId, + NoEcho: event.NoEcho, + Data: event.Data, + }; + const parsedUrl = url.parse(event.ResponseURL); + const loggingSafeUrl = `${parsedUrl.protocol}//${parsedUrl.hostname}/${parsedUrl.pathname}?***`; + exports.external.log('submit response to cloudformation', loggingSafeUrl, json); + const responseBody = JSON.stringify(json); + const req = { + hostname: parsedUrl.hostname, + path: parsedUrl.path, + method: 'PUT', + headers: { + 'content-type': '', + 'content-length': Buffer.byteLength(responseBody, 'utf8'), + }, + }; + const retryOptions = { + attempts: 5, + sleep: 1000, + }; + await withRetries(retryOptions, exports.external.sendHttpRequest)(req, responseBody); +} +async function defaultSendHttpRequest(options, requestBody) { + return new Promise((resolve, reject) => { + try { + const request = https.request(options, (response) => { + response.resume(); // Consume the response but don't care about it + if (!response.statusCode || response.statusCode >= 400) { + reject(new Error(`Unsuccessful HTTP response: ${response.statusCode}`)); + } + else { + resolve(); + } + }); + request.on('error', reject); + request.write(requestBody); + request.end(); + } + catch (e) { + reject(e); + } + }); +} +function defaultLog(fmt, ...params) { + // eslint-disable-next-line no-console + console.log(fmt, ...params); +} +function withRetries(options, fn) { + return async (...xs) => { + let attempts = options.attempts; + let ms = options.sleep; + while (true) { + try { + return await fn(...xs); + } + catch (e) { + if (attempts-- <= 0) { + throw e; + } + await sleep(Math.floor(Math.random() * ms)); + ms *= 2; + } + } + }; +} +async function sleep(ms) { + return new Promise((ok) => setTimeout(ok, ms)); +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d/index.js b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d/index.js new file mode 100644 index 0000000000000..4df534fc1cecc --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/asset.d6fa38886a871b64de769ec5016af90a071e6429aa8e7de84f595e4e2462e17d/index.js @@ -0,0 +1 @@ +"use strict";var p=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),T=(r,e)=>{for(var t in e)p(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of b(e))!C.call(r,s)&&s!==t&&p(r,s,{get:()=>e[s],enumerable:!(o=_(e,s))||o.enumerable});return r};var q=r=>v(p({},"__esModule",{value:!0}),r);var f=g((j,h)=>{"use strict";var l=class{constructor(e){this.value=e,this.next=void 0}},d=class{constructor(){this.clear()}enqueue(e){let t=new l(e);this._head?(this._tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._size++}dequeue(){let e=this._head;if(e)return this._head=this._head.next,this._size--,e.value}clear(){this._head=void 0,this._tail=void 0,this._size=0}get size(){return this._size}*[Symbol.iterator](){let e=this._head;for(;e;)yield e.value,e=e.next}};h.exports=d});var R=g(($,y)=>{"use strict";var k=f(),z=r=>{if(!((Number.isInteger(r)||r===1/0)&&r>0))throw new TypeError("Expected `concurrency` to be a number from 1 and up");let e=new k,t=0,o=()=>{t--,e.size>0&&e.dequeue()()},s=async(n,c,...a)=>{t++;let m=(async()=>n(...a))();c(m);try{await m}catch{}o()},i=(n,c,...a)=>{e.enqueue(s.bind(null,n,c,...a)),(async()=>(await Promise.resolve(),t0&&e.dequeue()()))()},u=(n,...c)=>new Promise(a=>{i(n,a,...c)});return Object.defineProperties(u,{activeCount:{get:()=>t},pendingCount:{get:()=>e.size},clearQueue:{value:()=>{e.clear()}}}),u};y.exports=z});var I={};T(I,{handler:()=>M});module.exports=q(I);var E=require("@aws-sdk/client-ssm"),S=R();async function M(r){let e=r.ResourceProperties.ReaderProps,t=e.imports,o=Object.keys(t),s=`aws-cdk:strong-ref:${e.prefix}`,i=new E.SSM({region:e.region});try{switch(r.RequestType){case"Create":console.info("Tagging SSM Parameter imports"),await w(i,o,s);break;case"Update":let n=r.OldResourceProperties.ReaderProps.imports,c=P(o,Object.keys(n)),a=P(Object.keys(n),o);console.info("Releasing unused SSM Parameter imports"),Object.keys(a).length>0&&await x(i,a,s),console.info("Tagging new SSM Parameter imports"),await w(i,c,s);break;case"Delete":console.info("Releasing all SSM Parameter exports by removing tags"),await x(i,o,s);return}}catch(u){throw console.error("Error importing cross region stack exports: ",u),u}return{Data:t}}async function w(r,e,t){let o=S(10);await Promise.all(e.map(s=>o(async()=>{try{return await r.addTagsToResource({ResourceId:s,ResourceType:"Parameter",Tags:[{Key:t,Value:"true"}]})}catch(i){throw new Error(`Error importing ${s}: ${i}`)}})))}async function x(r,e,t){let o=S(10);await Promise.all(e.map(s=>o(async()=>{try{return await r.removeTagsFromResource({TagKeys:[t],ResourceType:"Parameter",ResourceId:s})}catch(i){if(i.name==="InvalidResourceId")return;throw new Error(`Error releasing import ${s}: ${i}`)}})))}function P(r,e){return r.filter(t=>!e.includes(t))}0&&(module.exports={handler}); diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json index 2c54fe3a6adbf..2f2d19686b5ab 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-us-west-2", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-us-west-2", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-west-2/616dcb4adca0395435735b413925e2b0bf5438f24891731f4c263abe5dae7866.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-west-2/319feecbdd79b561ade2169ee0a835fdb91b5ecaecd5b259a64e78735ae73be0.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -100,28 +100,28 @@ "data": "Hello4A628BD4" } ], - "/CallRestApiInteg-ApiStack/StateMachine/Role/Resource": [ + "/CallRestApiInteg-ApiStack/ExportsWriteruseast10F67B507/Resource/Default": [ { "type": "aws:cdk:logicalId", - "data": "StateMachineRoleB840431D" + "data": "ExportsWriteruseast10F67B507DDE2E818" } ], - "/CallRestApiInteg-ApiStack/StateMachine/Role/DefaultPolicy/Resource": [ + "/CallRestApiInteg-ApiStack/Custom::CrossRegionExportWriterCustomResourceProvider": [ { - "type": "aws:cdk:logicalId", - "data": "StateMachineRoleDefaultPolicyDF1E6607" + "type": "aws:cdk:is-custom-resource-handler-customResourceProvider", + "data": true } ], - "/CallRestApiInteg-ApiStack/StateMachine/Resource": [ + "/CallRestApiInteg-ApiStack/Custom::CrossRegionExportWriterCustomResourceProvider/Role": [ { "type": "aws:cdk:logicalId", - "data": "StateMachine2E01A3A5" + "data": "CustomCrossRegionExportWriterCustomResourceProviderRoleC951B1E1" } ], - "/CallRestApiInteg-ApiStack/stateMachineArn": [ + "/CallRestApiInteg-ApiStack/Custom::CrossRegionExportWriterCustomResourceProvider/Handler": [ { "type": "aws:cdk:logicalId", - "data": "stateMachineArn" + "data": "CustomCrossRegionExportWriterCustomResourceProviderHandlerD8786E8A" } ], "/CallRestApiInteg-ApiStack/BootstrapVersion": [ @@ -156,7 +156,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-us-east-1", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-us-east-1", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/2433e42ae1b4508c1c7fd6e07c37bb4fd69dee68ca495f3a70646d5bf05f9eb3.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -169,9 +169,58 @@ } }, "dependencies": [ + "CallRestApiInteg-ApiStack", "CallRestApiInteg-SfnStack.assets" ], "metadata": { + "/CallRestApiInteg-SfnStack/StateMachine/Role/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "StateMachineRoleB840431D" + } + ], + "/CallRestApiInteg-SfnStack/StateMachine/Role/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "StateMachineRoleDefaultPolicyDF1E6607" + } + ], + "/CallRestApiInteg-SfnStack/StateMachine/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "StateMachine2E01A3A5" + } + ], + "/CallRestApiInteg-SfnStack/stateMachineArn": [ + { + "type": "aws:cdk:logicalId", + "data": "stateMachineArn" + } + ], + "/CallRestApiInteg-SfnStack/ExportsReader/Resource/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "ExportsReader8B249524" + } + ], + "/CallRestApiInteg-SfnStack/Custom::CrossRegionExportReaderCustomResourceProvider": [ + { + "type": "aws:cdk:is-custom-resource-handler-customResourceProvider", + "data": true + } + ], + "/CallRestApiInteg-SfnStack/Custom::CrossRegionExportReaderCustomResourceProvider/Role": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomCrossRegionExportReaderCustomResourceProviderRole10531BBD" + } + ], + "/CallRestApiInteg-SfnStack/Custom::CrossRegionExportReaderCustomResourceProvider/Handler": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomCrossRegionExportReaderCustomResourceProviderHandler46647B68" + } + ], "/CallRestApiInteg-SfnStack/BootstrapVersion": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json index e1263e2f31dbe..c84a1f0b8d47f 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json @@ -405,17 +405,121 @@ "version": "0.0.0" } }, + "ExportsWriteruseast10F67B507": { + "id": "ExportsWriteruseast10F67B507", + "path": "CallRestApiInteg-ApiStack/ExportsWriteruseast10F67B507", + "children": { + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-ApiStack/ExportsWriteruseast10F67B507/Resource", + "children": { + "Default": { + "id": "Default", + "path": "CallRestApiInteg-ApiStack/ExportsWriteruseast10F67B507/Resource/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "Custom::CrossRegionExportWriterCustomResourceProvider": { + "id": "Custom::CrossRegionExportWriterCustomResourceProvider", + "path": "CallRestApiInteg-ApiStack/Custom::CrossRegionExportWriterCustomResourceProvider", + "children": { + "Staging": { + "id": "Staging", + "path": "CallRestApiInteg-ApiStack/Custom::CrossRegionExportWriterCustomResourceProvider/Staging", + "constructInfo": { + "fqn": "aws-cdk-lib.AssetStaging", + "version": "0.0.0" + } + }, + "Role": { + "id": "Role", + "path": "CallRestApiInteg-ApiStack/Custom::CrossRegionExportWriterCustomResourceProvider/Role", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + }, + "Handler": { + "id": "Handler", + "path": "CallRestApiInteg-ApiStack/Custom::CrossRegionExportWriterCustomResourceProvider/Handler", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResourceProviderBase", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "CallRestApiInteg-ApiStack/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "CallRestApiInteg-ApiStack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "CallRestApiInteg-SfnStack": { + "id": "CallRestApiInteg-SfnStack", + "path": "CallRestApiInteg-SfnStack", + "children": { + "CrossStackReferenceToApi": { + "id": "CrossStackReferenceToApi", + "path": "CallRestApiInteg-SfnStack/CrossStackReferenceToApi", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigateway.RestApiBase", + "version": "0.0.0" + } + }, + "Call APIGW": { + "id": "Call APIGW", + "path": "CallRestApiInteg-SfnStack/Call APIGW", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions_tasks.CallApiGatewayRestApiEndpoint", + "version": "0.0.0" + } + }, "StateMachine": { "id": "StateMachine", - "path": "CallRestApiInteg-ApiStack/StateMachine", + "path": "CallRestApiInteg-SfnStack/StateMachine", "children": { "Role": { "id": "Role", - "path": "CallRestApiInteg-ApiStack/StateMachine/Role", + "path": "CallRestApiInteg-SfnStack/StateMachine/Role", "children": { "ImportRole": { "id": "ImportRole", - "path": "CallRestApiInteg-ApiStack/StateMachine/Role/ImportRole", + "path": "CallRestApiInteg-SfnStack/StateMachine/Role/ImportRole", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -423,7 +527,7 @@ }, "Resource": { "id": "Resource", - "path": "CallRestApiInteg-ApiStack/StateMachine/Role/Resource", + "path": "CallRestApiInteg-SfnStack/StateMachine/Role/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::Role", "aws:cdk:cloudformation:props": { @@ -448,11 +552,11 @@ }, "DefaultPolicy": { "id": "DefaultPolicy", - "path": "CallRestApiInteg-ApiStack/StateMachine/Role/DefaultPolicy", + "path": "CallRestApiInteg-SfnStack/StateMachine/Role/DefaultPolicy", "children": { "Resource": { "id": "Resource", - "path": "CallRestApiInteg-ApiStack/StateMachine/Role/DefaultPolicy/Resource", + "path": "CallRestApiInteg-SfnStack/StateMachine/Role/DefaultPolicy/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::Policy", "aws:cdk:cloudformation:props": { @@ -465,13 +569,16 @@ "Fn::Join": [ "", [ - "arn:aws:execute-api:us-west-2:", + "arn:aws:execute-api:us-east-1:", { "Ref": "AWS::AccountId" }, ":", { - "Ref": "MyRestApi2D1F47A9" + "Fn::GetAtt": [ + "ExportsReader8B249524", + "/cdk/exports/CallRestApiInteg-SfnStack/CallRestApiIntegApiStackuswest2RefMyRestApi2D1F47A94BF96318" + ] }, "/prod/GET/*" ] @@ -508,7 +615,7 @@ }, "Resource": { "id": "Resource", - "path": "CallRestApiInteg-ApiStack/StateMachine/Resource", + "path": "CallRestApiInteg-SfnStack/StateMachine/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::StepFunctions::StateMachine", "aws:cdk:cloudformation:props": { @@ -522,9 +629,12 @@ }, ":states:::apigateway:invoke\",\"Parameters\":{\"ApiEndpoint\":\"", { - "Ref": "MyRestApi2D1F47A9" + "Fn::GetAtt": [ + "ExportsReader8B249524", + "/cdk/exports/CallRestApiInteg-SfnStack/CallRestApiIntegApiStackuswest2RefMyRestApi2D1F47A94BF96318" + ] }, - ".execute-api.us-west-2.", + ".execute-api.us-east-1.", { "Ref": "AWS::URLSuffix" }, @@ -553,43 +663,71 @@ }, "stateMachineArn": { "id": "stateMachineArn", - "path": "CallRestApiInteg-ApiStack/stateMachineArn", + "path": "CallRestApiInteg-SfnStack/stateMachineArn", "constructInfo": { "fqn": "aws-cdk-lib.CfnOutput", "version": "0.0.0" } }, - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "CallRestApiInteg-ApiStack/BootstrapVersion", + "ExportsReader": { + "id": "ExportsReader", + "path": "CallRestApiInteg-SfnStack/ExportsReader", + "children": { + "Resource": { + "id": "Resource", + "path": "CallRestApiInteg-SfnStack/ExportsReader/Resource", + "children": { + "Default": { + "id": "Default", + "path": "CallRestApiInteg-SfnStack/ExportsReader/Resource/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResource", + "version": "0.0.0" + } + } + }, "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.4.2" } }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "CallRestApiInteg-ApiStack/CheckBootstrapVersion", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" - } - }, - "CallRestApiInteg-SfnStack": { - "id": "CallRestApiInteg-SfnStack", - "path": "CallRestApiInteg-SfnStack", - "children": { - "Call APIGW": { - "id": "Call APIGW", - "path": "CallRestApiInteg-SfnStack/Call APIGW", + "Custom::CrossRegionExportReaderCustomResourceProvider": { + "id": "Custom::CrossRegionExportReaderCustomResourceProvider", + "path": "CallRestApiInteg-SfnStack/Custom::CrossRegionExportReaderCustomResourceProvider", + "children": { + "Staging": { + "id": "Staging", + "path": "CallRestApiInteg-SfnStack/Custom::CrossRegionExportReaderCustomResourceProvider/Staging", + "constructInfo": { + "fqn": "aws-cdk-lib.AssetStaging", + "version": "0.0.0" + } + }, + "Role": { + "id": "Role", + "path": "CallRestApiInteg-SfnStack/Custom::CrossRegionExportReaderCustomResourceProvider/Role", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + }, + "Handler": { + "id": "Handler", + "path": "CallRestApiInteg-SfnStack/Custom::CrossRegionExportReaderCustomResourceProvider/Handler", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_stepfunctions_tasks.CallApiGatewayRestApiEndpoint", + "fqn": "aws-cdk-lib.CustomResourceProviderBase", "version": "0.0.0" } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts index 619c616cc16fc..a7839dd20a273 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts @@ -24,6 +24,7 @@ const sfnStack = new cdk.Stack(app, 'CallRestApiInteg-SfnStack', { env: { region: 'us-east-1', }, + crossRegionReferences: true, }); const restApi = new apigateway.RestApi(apiStack, 'MyRestApi', { cloudWatchRole: true }); @@ -34,8 +35,9 @@ const hello = new apigateway.LambdaIntegration(new lambda.Function(apiStack, 'He })); restApi.root.addMethod('ANY', hello); +const importedRestApi = apigateway.RestApi.fromRestApiId(sfnStack, 'CrossStackReferenceToApi', restApi.restApiId); const callEndpointJob = new CallApiGatewayRestApiEndpoint(sfnStack, 'Call APIGW', { - api: restApi, + api: importedRestApi, stageName: 'prod', method: HttpMethod.GET, authType: AuthType.IAM_ROLE, @@ -44,12 +46,12 @@ const callEndpointJob = new CallApiGatewayRestApiEndpoint(sfnStack, 'Call APIGW' const chain = sfn.Chain.start(callEndpointJob); -const sm = new sfn.StateMachine(apiStack, 'StateMachine', { +const sm = new sfn.StateMachine(sfnStack, 'StateMachine', { definition: chain, timeout: cdk.Duration.seconds(30), }); -new cdk.CfnOutput(apiStack, 'stateMachineArn', { +new cdk.CfnOutput(sfnStack, 'stateMachineArn', { value: sm.stateMachineArn, }); From d430f9080a4468416d1fb6827cccfaf56c11e05d Mon Sep 17 00:00:00 2001 From: Andrew Huo Date: Mon, 3 Feb 2025 13:21:20 -0800 Subject: [PATCH 4/4] Update tests and docs per reviewer suggestion --- .../CallRestApiInteg-SfnStack.assets.json | 4 +- .../CallRestApiInteg-SfnStack.template.json | 2 +- .../manifest.json | 147 +++++++++++++++++- .../tree.json | 134 +++++++++++++--- .../integ.call-rest-api-cross-region.ts | 1 + .../aws-stepfunctions-tasks/README.md | 10 +- .../lib/apigateway/call-rest-api.ts | 6 +- 7 files changed, 273 insertions(+), 31 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json index 87af1b7781dc1..614c3b019259d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.assets.json @@ -15,7 +15,7 @@ } } }, - "2433e42ae1b4508c1c7fd6e07c37bb4fd69dee68ca495f3a70646d5bf05f9eb3": { + "4b53f3b1f75f7c2c40971f3e37d5448f36e7b39949926864276994f8ec2e0d6d": { "source": { "path": "CallRestApiInteg-SfnStack.template.json", "packaging": "file" @@ -23,7 +23,7 @@ "destinations": { "current_account-us-east-1": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1", - "objectKey": "2433e42ae1b4508c1c7fd6e07c37bb4fd69dee68ca495f3a70646d5bf05f9eb3.json", + "objectKey": "4b53f3b1f75f7c2c40971f3e37d5448f36e7b39949926864276994f8ec2e0d6d.json", "region": "us-east-1", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-1" } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json index 198499f4a764c..57a098d1d924d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/CallRestApiInteg-SfnStack.template.json @@ -74,7 +74,7 @@ "/cdk/exports/CallRestApiInteg-SfnStack/CallRestApiIntegApiStackuswest2RefMyRestApi2D1F47A94BF96318" ] }, - ".execute-api.us-east-1.", + ".execute-api.us-west-2.", { "Ref": "AWS::URLSuffix" }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json index 2f2d19686b5ab..57e260628d732 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/manifest.json @@ -34,12 +34,42 @@ "CallRestApiInteg-ApiStack.assets" ], "metadata": { + "/CallRestApiInteg-ApiStack/MyRestApi": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "cloudWatchRole": "*" + } + } + ], "/CallRestApiInteg-ApiStack/MyRestApi/Resource": [ { "type": "aws:cdk:logicalId", "data": "MyRestApi2D1F47A9" } ], + "/CallRestApiInteg-ApiStack/MyRestApi/CloudWatchRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + }, + "managedPolicies": [ + { + "managedPolicyArn": "*" + } + ] + } + } + ], + "/CallRestApiInteg-ApiStack/MyRestApi/CloudWatchRole/ImportCloudWatchRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/CallRestApiInteg-ApiStack/MyRestApi/CloudWatchRole/Resource": [ { "type": "aws:cdk:logicalId", @@ -52,12 +82,30 @@ "data": "MyRestApiAccount2FB6DB7A" } ], + "/CallRestApiInteg-ApiStack/MyRestApi/Deployment": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "description": "*", + "api": "*", + "retainDeployments": "*" + } + } + ], "/CallRestApiInteg-ApiStack/MyRestApi/Deployment/Resource": [ { "type": "aws:cdk:logicalId", "data": "MyRestApiDeploymentB555B5824a2dace0b77d6e14d0cc32d4d28422f3" } ], + "/CallRestApiInteg-ApiStack/MyRestApi/DeploymentStage.prod": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "deployment": "*" + } + } + ], "/CallRestApiInteg-ApiStack/MyRestApi/DeploymentStage.prod/Resource": [ { "type": "aws:cdk:logicalId", @@ -70,6 +118,23 @@ "data": "MyRestApiEndpoint4C55E4CB" } ], + "/CallRestApiInteg-ApiStack/MyRestApi/Default": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/CallRestApiInteg-ApiStack/MyRestApi/Default/ANY": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "resource": "*", + "httpMethod": "*", + "integration": "*", + "options": "*" + } + } + ], "/CallRestApiInteg-ApiStack/MyRestApi/Default/ANY/ApiPermission.CallRestApiIntegApiStackMyRestApiC2593C7A.ANY..": [ { "type": "aws:cdk:logicalId", @@ -88,6 +153,38 @@ "data": "MyRestApiANY05143F93" } ], + "/CallRestApiInteg-ApiStack/Hello": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "runtime": "*", + "handler": "*", + "code": "*" + } + } + ], + "/CallRestApiInteg-ApiStack/Hello/ServiceRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + }, + "managedPolicies": [ + { + "managedPolicyArn": "*" + } + ] + } + } + ], + "/CallRestApiInteg-ApiStack/Hello/ServiceRole/ImportServiceRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/CallRestApiInteg-ApiStack/Hello/ServiceRole/Resource": [ { "type": "aws:cdk:logicalId", @@ -100,6 +197,12 @@ "data": "Hello4A628BD4" } ], + "/CallRestApiInteg-ApiStack/ExportsWriteruseast10F67B507/Resource": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/CallRestApiInteg-ApiStack/ExportsWriteruseast10F67B507/Resource/Default": [ { "type": "aws:cdk:logicalId", @@ -156,7 +259,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-us-east-1", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-us-east-1", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/2433e42ae1b4508c1c7fd6e07c37bb4fd69dee68ca495f3a70646d5bf05f9eb3.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/4b53f3b1f75f7c2c40971f3e37d5448f36e7b39949926864276994f8ec2e0d6d.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -173,12 +276,48 @@ "CallRestApiInteg-SfnStack.assets" ], "metadata": { + "/CallRestApiInteg-SfnStack/StateMachine": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "definition": { + "id": "*", + "startState": "*", + "endStates": "*" + }, + "timeout": "*" + } + } + ], + "/CallRestApiInteg-SfnStack/StateMachine/Role": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + } + } + } + ], + "/CallRestApiInteg-SfnStack/StateMachine/Role/ImportRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/CallRestApiInteg-SfnStack/StateMachine/Role/Resource": [ { "type": "aws:cdk:logicalId", "data": "StateMachineRoleB840431D" } ], + "/CallRestApiInteg-SfnStack/StateMachine/Role/DefaultPolicy": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/CallRestApiInteg-SfnStack/StateMachine/Role/DefaultPolicy/Resource": [ { "type": "aws:cdk:logicalId", @@ -197,6 +336,12 @@ "data": "stateMachineArn" } ], + "/CallRestApiInteg-SfnStack/ExportsReader/Resource": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/CallRestApiInteg-SfnStack/ExportsReader/Resource/Default": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json index c84a1f0b8d47f..09f7aefa92a4c 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.js.snapshot/tree.json @@ -35,7 +35,10 @@ "path": "CallRestApiInteg-ApiStack/MyRestApi/CloudWatchRole/ImportCloudWatchRole", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } }, "Resource": { @@ -80,7 +83,20 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + }, + "managedPolicies": [ + { + "managedPolicyArn": "*" + } + ] + } + ] } }, "Account": { @@ -126,7 +142,14 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_apigateway.Deployment", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "description": "*", + "api": "*", + "retainDeployments": "*" + } + ] } }, "DeploymentStage.prod": { @@ -156,7 +179,12 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_apigateway.Stage", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "deployment": "*" + } + ] } }, "Endpoint": { @@ -299,19 +327,35 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_apigateway.Method", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "resource": "*", + "httpMethod": "*", + "integration": "*", + "options": "*" + } + ] } } }, "constructInfo": { "fqn": "aws-cdk-lib.aws_apigateway.ResourceBase", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } } }, "constructInfo": { "fqn": "aws-cdk-lib.aws_apigateway.RestApi", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "cloudWatchRole": "*" + } + ] } }, "Hello": { @@ -327,7 +371,10 @@ "path": "CallRestApiInteg-ApiStack/Hello/ServiceRole/ImportServiceRole", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } }, "Resource": { @@ -372,7 +419,20 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + }, + "managedPolicies": [ + { + "managedPolicyArn": "*" + } + ] + } + ] } }, "Resource": { @@ -402,7 +462,14 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_lambda.Function", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "runtime": "*", + "handler": "*", + "code": "*" + } + ] } }, "ExportsWriteruseast10F67B507": { @@ -424,7 +491,10 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.CustomResource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } } }, @@ -498,7 +568,8 @@ "path": "CallRestApiInteg-SfnStack/CrossStackReferenceToApi", "constructInfo": { "fqn": "aws-cdk-lib.aws_apigateway.RestApiBase", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [] } }, "Call APIGW": { @@ -522,7 +593,10 @@ "path": "CallRestApiInteg-SfnStack/StateMachine/Role/ImportRole", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } }, "Resource": { @@ -604,13 +678,24 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_iam.Policy", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } } }, "constructInfo": { "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + } + } + ] } }, "Resource": { @@ -634,7 +719,7 @@ "/cdk/exports/CallRestApiInteg-SfnStack/CallRestApiIntegApiStackuswest2RefMyRestApi2D1F47A94BF96318" ] }, - ".execute-api.us-east-1.", + ".execute-api.us-west-2.", { "Ref": "AWS::URLSuffix" }, @@ -658,7 +743,17 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_stepfunctions.StateMachine", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "definition": { + "id": "*", + "startState": "*", + "endStates": "*" + }, + "timeout": "*" + } + ] } }, "stateMachineArn": { @@ -688,7 +783,10 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.CustomResource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts index a7839dd20a273..8843a852f2d62 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api-cross-region.ts @@ -40,6 +40,7 @@ const callEndpointJob = new CallApiGatewayRestApiEndpoint(sfnStack, 'Call APIGW' api: importedRestApi, stageName: 'prod', method: HttpMethod.GET, + region: 'us-west-2', authType: AuthType.IAM_ROLE, outputPath: sfn.JsonPath.stringAt('$.ResponseBody'), }); diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md b/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md index fad0973c674be..b5477d3432166 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md @@ -155,20 +155,18 @@ const invokeTask = new tasks.CallApiGatewayRestApiEndpoint(this, 'Call REST API' }); ``` -By default, the API endpoint URI will be constructed using the AWS region of -the stack in which the provided `api` is created. Passing in a `region` string, -such as `us-west-2`, will instead construct the endpoint with the given region: +By default, the API endpoint URI will be constructed using the AWS region of +the stack in which the provided `api` is created. +To construct the endpoint with a different region, use the `region` parameter: ```ts import * as apigateway from 'aws-cdk-lib/aws-apigateway'; const restApi = new apigateway.RestApi(this, 'MyRestApi'); -const endpointRegion = 'us-west-2'; - const invokeTask = new tasks.CallApiGatewayRestApiEndpoint(this, 'Call REST API', { api: restApi, stageName: 'prod', method: tasks.HttpMethod.GET, - region: endpointRegion, + region: 'us-west-2', }); ``` diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts index b437700335ab5..89cf91890787e 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts @@ -21,9 +21,9 @@ export interface CallApiGatewayRestApiEndpointOptions { readonly stageName: string; /** - * AWS region, e.g. 'us-east-1', where the API is deployed. Uses the region of the Stack - * containing `api`if no region is provided. - * @default the region of the Stack of the `api` in these props + * Specify a custom Region where the API is deployed, e.g. 'us-east-1'. + * + * @default - Uses the Region of the stack containing the `api`. */ readonly region?: string; }