diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.assets.json new file mode 100644 index 0000000000000..9963729af1964 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.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-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.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-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/cdk.out index 8ecc185e9dbee..1f0068d32659a 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/cdk.out +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"21.0.0"} \ No newline at end of file +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ-mock-websocket-integration.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ-mock-websocket-integration.assets.json index 89f3532813157..986e5b5df4d9e 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ-mock-websocket-integration.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ-mock-websocket-integration.assets.json @@ -1,7 +1,7 @@ { - "version": "20.0.0", + "version": "36.0.0", "files": { - "aabdbe840e6768f96ec51dd87886969be769aeca5a21773e27cd16f1a90367fe": { + "6b60feae70a32f40a6973349f09261825e869adf03504811cee49c59d2691e3c": { "source": { "path": "integ-mock-websocket-integration.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "aabdbe840e6768f96ec51dd87886969be769aeca5a21773e27cd16f1a90367fe.json", + "objectKey": "6b60feae70a32f40a6973349f09261825e869adf03504811cee49c59d2691e3c.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ-mock-websocket-integration.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ-mock-websocket-integration.template.json index 085584d49a05b..42bc9215b9975 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ-mock-websocket-integration.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ-mock-websocket-integration.template.json @@ -24,8 +24,8 @@ "ApiId": { "Ref": "mywsapi32E6CE11" }, - "RouteKey": "$default", "AuthorizationType": "NONE", + "RouteKey": "$default", "Target": { "Fn::Join": [ "", @@ -39,14 +39,18 @@ } } }, - "mywsapisendmessageRouteSendMessageIntegrationD29E12F9": { + "mywsapisendmessageRouteDefaultIntegration702159AD": { "Type": "AWS::ApiGatewayV2::Integration", "Properties": { "ApiId": { "Ref": "mywsapi32E6CE11" }, "IntegrationType": "MOCK", - "IntegrationUri": "" + "IntegrationUri": "", + "RequestTemplates": { + "application/json": "{\"statusCode\":200}" + }, + "TemplateSelectionExpression": "\\$default" } }, "mywsapisendmessageRouteAE873328": { @@ -55,29 +59,42 @@ "ApiId": { "Ref": "mywsapi32E6CE11" }, - "RouteKey": "sendmessage", "AuthorizationType": "NONE", + "RouteKey": "sendmessage", + "RouteResponseSelectionExpression": "$default", "Target": { "Fn::Join": [ "", [ "integrations/", { - "Ref": "mywsapisendmessageRouteSendMessageIntegrationD29E12F9" + "Ref": "mywsapisendmessageRouteDefaultIntegration702159AD" } ] ] } } }, + "mywsapisendmessageRouteResponse2ED167D2": { + "Type": "AWS::ApiGatewayV2::RouteResponse", + "Properties": { + "ApiId": { + "Ref": "mywsapi32E6CE11" + }, + "RouteId": { + "Ref": "mywsapisendmessageRouteAE873328" + }, + "RouteResponseKey": "$default" + } + }, "mystage114C35EC": { "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "mywsapi32E6CE11" }, - "StageName": "dev", - "AutoDeploy": true + "AutoDeploy": true, + "StageName": "dev" } } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ.json index e38a89b873c9c..925cbd9e68810 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/integ.json @@ -1,14 +1,12 @@ { - "version": "20.0.0", + "version": "36.0.0", "testCases": { - "integ.mock": { + "apigatewayv2-mock-integration-integ-test/DefaultTest": { "stacks": [ "integ-mock-websocket-integration" ], - "diffAssets": false, - "stackUpdateWorkflow": true + "assertionStack": "apigatewayv2-mock-integration-integ-test/DefaultTest/DeployAssert", + "assertionStackName": "apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778" } - }, - "synthContext": {}, - "enableLookups": false + } } \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/manifest.json index cf17e2f2db70c..5f61ef3d162a9 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/manifest.json @@ -1,12 +1,6 @@ { - "version": "20.0.0", + "version": "36.0.0", "artifacts": { - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - }, "integ-mock-websocket-integration.assets": { "type": "cdk:asset-manifest", "properties": { @@ -20,10 +14,11 @@ "environment": "aws://unknown-account/unknown-region", "properties": { "templateFile": "integ-mock-websocket-integration.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}/aabdbe840e6768f96ec51dd87886969be769aeca5a21773e27cd16f1a90367fe.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/6b60feae70a32f40a6973349f09261825e869adf03504811cee49c59d2691e3c.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -57,10 +52,10 @@ "data": "mywsapidefaultRouteE9382DF8" } ], - "/integ-mock-websocket-integration/mywsapi/sendmessage-Route/SendMessageIntegration/Resource": [ + "/integ-mock-websocket-integration/mywsapi/sendmessage-Route/DefaultIntegration/Resource": [ { "type": "aws:cdk:logicalId", - "data": "mywsapisendmessageRouteSendMessageIntegrationD29E12F9" + "data": "mywsapisendmessageRouteDefaultIntegration702159AD" } ], "/integ-mock-websocket-integration/mywsapi/sendmessage-Route/Resource": [ @@ -69,6 +64,12 @@ "data": "mywsapisendmessageRouteAE873328" } ], + "/integ-mock-websocket-integration/mywsapi/sendmessage-Route/Response": [ + { + "type": "aws:cdk:logicalId", + "data": "mywsapisendmessageRouteResponse2ED167D2" + } + ], "/integ-mock-websocket-integration/mystage/Resource": [ { "type": "aws:cdk:logicalId", @@ -92,9 +93,72 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } + ], + "mywsapisendmessageRouteSendMessageIntegrationD29E12F9": [ + { + "type": "aws:cdk:logicalId", + "data": "mywsapisendmessageRouteSendMessageIntegrationD29E12F9", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" + ] + } ] }, "displayName": "integ-mock-websocket-integration" + }, + "apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.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": [ + "apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.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": [ + "apigatewayv2mockintegrationintegtestDefaultTestDeployAssert3D8FA778.assets" + ], + "metadata": { + "/apigatewayv2-mock-integration-integ-test/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/apigatewayv2-mock-integration-integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "apigatewayv2-mock-integration-integ-test/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-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/tree.json index 62c47b25cc7d3..603ad0a2c563c 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.js.snapshot/tree.json @@ -4,14 +4,6 @@ "id": "App", "path": "", "children": { - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" - } - }, "integ-mock-websocket-integration": { "id": "integ-mock-websocket-integration", "path": "integ-mock-websocket-integration", @@ -32,7 +24,7 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.CfnApi", + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnApi", "version": "0.0.0" } }, @@ -58,13 +50,13 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.CfnIntegration", + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnIntegration", "version": "0.0.0" } } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.WebSocketIntegration", + "fqn": "aws-cdk-lib.aws_apigatewayv2.WebSocketIntegration", "version": "0.0.0" } }, @@ -77,8 +69,8 @@ "apiId": { "Ref": "mywsapi32E6CE11" }, - "routeKey": "$default", "authorizationType": "NONE", + "routeKey": "$default", "target": { "Fn::Join": [ "", @@ -93,13 +85,13 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.CfnRoute", + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnRoute", "version": "0.0.0" } } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.WebSocketRoute", + "fqn": "aws-cdk-lib.aws_apigatewayv2.WebSocketRoute", "version": "0.0.0" } }, @@ -107,13 +99,13 @@ "id": "sendmessage-Route", "path": "integ-mock-websocket-integration/mywsapi/sendmessage-Route", "children": { - "SendMessageIntegration": { - "id": "SendMessageIntegration", - "path": "integ-mock-websocket-integration/mywsapi/sendmessage-Route/SendMessageIntegration", + "DefaultIntegration": { + "id": "DefaultIntegration", + "path": "integ-mock-websocket-integration/mywsapi/sendmessage-Route/DefaultIntegration", "children": { "Resource": { "id": "Resource", - "path": "integ-mock-websocket-integration/mywsapi/sendmessage-Route/SendMessageIntegration/Resource", + "path": "integ-mock-websocket-integration/mywsapi/sendmessage-Route/DefaultIntegration/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::ApiGatewayV2::Integration", "aws:cdk:cloudformation:props": { @@ -121,17 +113,21 @@ "Ref": "mywsapi32E6CE11" }, "integrationType": "MOCK", - "integrationUri": "" + "integrationUri": "", + "requestTemplates": { + "application/json": "{\"statusCode\":200}" + }, + "templateSelectionExpression": "\\$default" } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.CfnIntegration", + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnIntegration", "version": "0.0.0" } } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.WebSocketIntegration", + "fqn": "aws-cdk-lib.aws_apigatewayv2.WebSocketIntegration", "version": "0.0.0" } }, @@ -144,15 +140,16 @@ "apiId": { "Ref": "mywsapi32E6CE11" }, - "routeKey": "sendmessage", "authorizationType": "NONE", + "routeKey": "sendmessage", + "routeResponseSelectionExpression": "$default", "target": { "Fn::Join": [ "", [ "integrations/", { - "Ref": "mywsapisendmessageRouteSendMessageIntegrationD29E12F9" + "Ref": "mywsapisendmessageRouteDefaultIntegration702159AD" } ] ] @@ -160,19 +157,39 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.CfnRoute", + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnRoute", + "version": "0.0.0" + } + }, + "Response": { + "id": "Response", + "path": "integ-mock-websocket-integration/mywsapi/sendmessage-Route/Response", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApiGatewayV2::RouteResponse", + "aws:cdk:cloudformation:props": { + "apiId": { + "Ref": "mywsapi32E6CE11" + }, + "routeId": { + "Ref": "mywsapisendmessageRouteAE873328" + }, + "routeResponseKey": "$default" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnRouteResponse", "version": "0.0.0" } } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.WebSocketRoute", + "fqn": "aws-cdk-lib.aws_apigatewayv2.WebSocketRoute", "version": "0.0.0" } } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.WebSocketApi", + "fqn": "aws-cdk-lib.aws_apigatewayv2.WebSocketApi", "version": "0.0.0" } }, @@ -189,18 +206,18 @@ "apiId": { "Ref": "mywsapi32E6CE11" }, - "stageName": "dev", - "autoDeploy": true + "autoDeploy": true, + "stageName": "dev" } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.CfnStage", + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnStage", "version": "0.0.0" } } }, "constructInfo": { - "fqn": "@aws-cdk/aws-apigatewayv2.WebSocketStage", + "fqn": "aws-cdk-lib.aws_apigatewayv2.WebSocketStage", "version": "0.0.0" } }, @@ -208,20 +225,98 @@ "id": "ApiEndpoint", "path": "integ-mock-websocket-integration/ApiEndpoint", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "aws-cdk-lib.CfnOutput", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "integ-mock-websocket-integration/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "integ-mock-websocket-integration/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" } } }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "apigatewayv2-mock-integration-integ-test": { + "id": "apigatewayv2-mock-integration-integ-test", + "path": "apigatewayv2-mock-integration-integ-test", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "apigatewayv2-mock-integration-integ-test/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "apigatewayv2-mock-integration-integ-test/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "apigatewayv2-mock-integration-integ-test/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "apigatewayv2-mock-integration-integ-test/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "apigatewayv2-mock-integration-integ-test/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.1.85" + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "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-apigatewayv2-integrations/test/websocket/integ.mock.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.ts index 5ae9e8d7556be..37e760937e3ac 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/websocket/integ.mock.ts @@ -1,6 +1,7 @@ import { WebSocketApi, WebSocketStage } from 'aws-cdk-lib/aws-apigatewayv2'; import { App, CfnOutput, Stack } from 'aws-cdk-lib'; import { WebSocketMockIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; /* * Stack verification steps: @@ -19,6 +20,16 @@ const stage = new WebSocketStage(stack, 'mystage', { autoDeploy: true, }); -webSocketApi.addRoute('sendmessage', { integration: new WebSocketMockIntegration('SendMessageIntegration') }); +webSocketApi.addRoute('sendmessage', { + integration: new WebSocketMockIntegration('DefaultIntegration', { + requestTemplates: { 'application/json': JSON.stringify({ statusCode: 200 }) }, + templateSelectionExpression: '\\$default', + }), + returnResponse: true, +}); new CfnOutput(stack, 'ApiEndpoint', { value: stage.url }); + +new IntegTest(app, 'apigatewayv2-mock-integration-integ-test', { + testCases: [stack], +}); diff --git a/packages/aws-cdk-lib/aws-apigatewayv2-integrations/README.md b/packages/aws-cdk-lib/aws-apigatewayv2-integrations/README.md index 9fd07172268e6..f01b36111edbc 100644 --- a/packages/aws-cdk-lib/aws-apigatewayv2-integrations/README.md +++ b/packages/aws-cdk-lib/aws-apigatewayv2-integrations/README.md @@ -11,6 +11,7 @@ - [WebSocket APIs](#websocket-apis) - [Lambda WebSocket Integration](#lambda-websocket-integration) - [AWS WebSocket Integration](#aws-websocket-integration) + - [Mock WebSocket Integration](#mock-websocket-integration) - [Import Issues](#import-issues) - [DotNet Namespace](#dotnet-namespace) - [Java Package](#java-package) @@ -312,6 +313,30 @@ webSocketApi.addRoute('$connect', { You can also set additional properties to change the behavior of your integration, such as `contentHandling`. See [Working with binary media types for WebSocket APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/websocket-api-develop-binary-media-types.html). +### Mock WebSocket Integration + +API Gateway also allows the creation of mock integrations, allowing you to generate API responses without the need for an integration backend. These responses can range in complexity from a static message to a templated response with parameters extracted from the input request or the integration's context. See [Set up data mapping for WebSocket APIs in API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-mapping-template-reference.html) and [WebSocket API mapping template reference for API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-mapping-template-reference.html) for more information. + +```ts +import { WebSocketMockIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations'; + +const webSocketApi = new apigwv2.WebSocketApi(this, 'mywsapi'); +new apigwv2.WebSocketStage(this, 'mystage', { + webSocketApi, + stageName: 'dev', + autoDeploy: true, +}); + + +webSocketApi.addRoute('sendMessage', { + integration: new WebSocketMockIntegration('DefaultIntegration', { + requestTemplates: { 'application/json': JSON.stringify({ statusCode: 200 }) }, + templateSelectionExpression: '\\$default', + }), + returnResponse: true, +}); +``` + ## Import Issues `jsiirc.json` file is missing during the stablization process of this module, which caused import issues for DotNet and Java users who attempt to use this module. Unfortunately, to guarantee backward compatibility, we cannot simply correct the namespace for DotNet or package for Java. The following outlines the workaround. diff --git a/packages/aws-cdk-lib/aws-apigatewayv2-integrations/lib/websocket/mock.ts b/packages/aws-cdk-lib/aws-apigatewayv2-integrations/lib/websocket/mock.ts index 3ebf7411930c7..9248d97e17ea5 100644 --- a/packages/aws-cdk-lib/aws-apigatewayv2-integrations/lib/websocket/mock.ts +++ b/packages/aws-cdk-lib/aws-apigatewayv2-integrations/lib/websocket/mock.ts @@ -5,6 +5,31 @@ import { WebSocketRouteIntegrationBindOptions, } from '../../../aws-apigatewayv2'; +/** + * Props for Mock type integration for a WebSocket Api. + */ +export interface WebSocketMockIntegrationProps { + /** + * A map of Apache Velocity templates that are applied on the request + * payload. + * + * ``` + * { "application/json": "{ \"statusCode\": 200 }" } + * ``` + * + * @default - No request template provided to the integration. + * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-mapping-template-reference.html + */ + readonly requestTemplates?: { [contentType: string]: string }; + + /** + * The template selection expression for the integration. + * + * @default - No template selection expression provided. + */ + readonly templateSelectionExpression?: string; +} + /** * Mock WebSocket Integration */ @@ -13,7 +38,7 @@ export class WebSocketMockIntegration extends WebSocketRouteIntegration { /** * @param id id of the underlying integration construct */ - constructor(id: string) { + constructor(id: string, private readonly props: WebSocketMockIntegrationProps = {}) { super(id); } @@ -22,6 +47,8 @@ export class WebSocketMockIntegration extends WebSocketRouteIntegration { return { type: WebSocketIntegrationType.MOCK, uri: '', + requestTemplates: this.props.requestTemplates, + templateSelectionExpression: this.props.templateSelectionExpression, }; } } diff --git a/packages/aws-cdk-lib/aws-apigatewayv2-integrations/test/websocket/mock.test.ts b/packages/aws-cdk-lib/aws-apigatewayv2-integrations/test/websocket/mock.test.ts index 46920f16c4b24..d92d131dc8ee1 100644 --- a/packages/aws-cdk-lib/aws-apigatewayv2-integrations/test/websocket/mock.test.ts +++ b/packages/aws-cdk-lib/aws-apigatewayv2-integrations/test/websocket/mock.test.ts @@ -19,4 +19,28 @@ describe('MockWebSocketIntegration', () => { IntegrationUri: '', }); }); + + test('can set custom properties', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + new WebSocketApi(stack, 'Api', { + defaultRouteOptions: { + integration: new WebSocketMockIntegration('DefaultIntegration', { + requestTemplates: { 'application/json': '{ "statusCode": 200 }' }, + templateSelectionExpression: '\\$default', + }), + returnResponse: true, + }, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Integration', { + IntegrationType: 'MOCK', + IntegrationUri: '', + RequestTemplates: { 'application/json': '{ "statusCode": 200 }' }, + TemplateSelectionExpression: '\\$default', + }); + }); });