From 087114bd3be2737d39d945225538fc076524a870 Mon Sep 17 00:00:00 2001 From: Michael Kaiser Date: Fri, 18 Apr 2025 08:56:40 -0500 Subject: [PATCH 1/6] Merged --- .../.eslintrc.json | 236 --- .../ec2-instance-connect-endpoint/.npmignore | 27 - .../ec2-instance-connect-endpoint/.npmrc | 1 + .../ec2-instance-connect-endpoint/README.md | 48 +- .../{src/integ.default.ts => bin/app.ts} | 5 +- .../ec2-instance-connect-endpoint/cdk.json | 43 +- .../package.json | 36 +- .../src/endpoint.ts | 27 +- .../__snapshots__/integ.default.test.ts.snap | 1295 ----------------- .../{integ.default.test.ts => app.test.ts} | 5 +- .../tsconfig.json | 16 +- 11 files changed, 107 insertions(+), 1632 deletions(-) delete mode 100644 typescript/ec2-instance-connect-endpoint/.eslintrc.json delete mode 100644 typescript/ec2-instance-connect-endpoint/.npmignore create mode 100644 typescript/ec2-instance-connect-endpoint/.npmrc rename typescript/ec2-instance-connect-endpoint/{src/integ.default.ts => bin/app.ts} (87%) delete mode 100644 typescript/ec2-instance-connect-endpoint/test/__snapshots__/integ.default.test.ts.snap rename typescript/ec2-instance-connect-endpoint/test/{integ.default.test.ts => app.test.ts} (75%) diff --git a/typescript/ec2-instance-connect-endpoint/.eslintrc.json b/typescript/ec2-instance-connect-endpoint/.eslintrc.json deleted file mode 100644 index da79cba46f..0000000000 --- a/typescript/ec2-instance-connect-endpoint/.eslintrc.json +++ /dev/null @@ -1,236 +0,0 @@ -// ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". -{ - "env": { - "jest": true, - "node": true - }, - "root": true, - "plugins": [ - "@typescript-eslint", - "import" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module", - "project": "./tsconfig.dev.json", - "tsconfigRootDir": "typescript/ec2-instance-connect-endpoint" - }, - "extends": [ - "plugin:import/typescript" - ], - "settings": { - "import/parsers": { - "@typescript-eslint/parser": [ - ".ts", - ".tsx" - ] - }, - "import/resolver": { - "node": {}, - "typescript": { - "project": "./tsconfig.dev.json", - "alwaysTryTypes": true - } - } - }, - "ignorePatterns": [ - "*.js", - "*.d.ts", - "node_modules/", - "*.generated.ts", - "coverage", - "!.projenrc.ts", - "!projenrc/**/*.ts" - ], - "rules": { - "indent": [ - "off" - ], - "@typescript-eslint/indent": [ - "error", - 2 - ], - "quotes": [ - "error", - "single", - { - "avoidEscape": true - } - ], - "comma-dangle": [ - "error", - "always-multiline" - ], - "comma-spacing": [ - "error", - { - "before": false, - "after": true - } - ], - "no-multi-spaces": [ - "error", - { - "ignoreEOLComments": false - } - ], - "array-bracket-spacing": [ - "error", - "never" - ], - "array-bracket-newline": [ - "error", - "consistent" - ], - "object-curly-spacing": [ - "error", - "always" - ], - "object-curly-newline": [ - "error", - { - "multiline": true, - "consistent": true - } - ], - "object-property-newline": [ - "error", - { - "allowAllPropertiesOnSameLine": true - } - ], - "keyword-spacing": [ - "error" - ], - "brace-style": [ - "error", - "1tbs", - { - "allowSingleLine": true - } - ], - "space-before-blocks": [ - "error" - ], - "curly": [ - "error", - "multi-line", - "consistent" - ], - "@typescript-eslint/member-delimiter-style": [ - "error" - ], - "semi": [ - "error", - "always" - ], - "max-len": [ - "error", - { - "code": 150, - "ignoreUrls": true, - "ignoreStrings": true, - "ignoreTemplateLiterals": true, - "ignoreComments": true, - "ignoreRegExpLiterals": true - } - ], - "quote-props": [ - "error", - "consistent-as-needed" - ], - "@typescript-eslint/no-require-imports": [ - "error" - ], - "import/no-extraneous-dependencies": [ - "error", - { - "devDependencies": [ - "**/test/**", - "**/build-tools/**", - ".projenrc.ts", - "projenrc/**/*.ts" - ], - "optionalDependencies": false, - "peerDependencies": true - } - ], - "import/no-unresolved": [ - "error" - ], - "import/order": [ - "warn", - { - "groups": [ - "builtin", - "external" - ], - "alphabetize": { - "order": "asc", - "caseInsensitive": true - } - } - ], - "no-duplicate-imports": [ - "error" - ], - "no-shadow": [ - "off" - ], - "@typescript-eslint/no-shadow": [ - "error" - ], - "key-spacing": [ - "error" - ], - "no-multiple-empty-lines": [ - "error" - ], - "@typescript-eslint/no-floating-promises": [ - "error" - ], - "no-return-await": [ - "off" - ], - "@typescript-eslint/return-await": [ - "error" - ], - "no-trailing-spaces": [ - "error" - ], - "dot-notation": [ - "error" - ], - "no-bitwise": [ - "error" - ], - "@typescript-eslint/member-ordering": [ - "error", - { - "default": [ - "public-static-field", - "public-static-method", - "protected-static-field", - "protected-static-method", - "private-static-field", - "private-static-method", - "field", - "constructor", - "method" - ] - } - ] - }, - "overrides": [ - { - "files": [ - ".projenrc.ts" - ], - "rules": { - "@typescript-eslint/no-require-imports": "off", - "import/no-extraneous-dependencies": "off" - } - } - ] -} diff --git a/typescript/ec2-instance-connect-endpoint/.npmignore b/typescript/ec2-instance-connect-endpoint/.npmignore deleted file mode 100644 index 79d65ac2b7..0000000000 --- a/typescript/ec2-instance-connect-endpoint/.npmignore +++ /dev/null @@ -1,27 +0,0 @@ -# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". -/.projen/ -/test-reports/ -junit.xml -/coverage/ -permissions-backup.acl -/dist/changelog.md -/dist/version.txt -/.mergify.yml -/test/ -/tsconfig.dev.json -/src/ -!/lib/ -!/lib/**/*.js -!/lib/**/*.d.ts -dist -/tsconfig.json -/.github/ -/.vscode/ -/.idea/ -/.projenrc.js -tsconfig.tsbuildinfo -/.eslintrc.json -!.jsii -cdk.out -cdk.context.json -yarn-error.log diff --git a/typescript/ec2-instance-connect-endpoint/.npmrc b/typescript/ec2-instance-connect-endpoint/.npmrc new file mode 100644 index 0000000000..d67f374883 --- /dev/null +++ b/typescript/ec2-instance-connect-endpoint/.npmrc @@ -0,0 +1 @@ +node-linker=hoisted diff --git a/typescript/ec2-instance-connect-endpoint/README.md b/typescript/ec2-instance-connect-endpoint/README.md index c6ab8e28ab..a279c49b84 100644 --- a/typescript/ec2-instance-connect-endpoint/README.md +++ b/typescript/ec2-instance-connect-endpoint/README.md @@ -1,10 +1,8 @@ -# InstanceConnectEndpoint +# EC2 Instance Connect Endpoint -`InstanceConnectEndpoint` is a sample AWS CDK construct that allows you to build [EC2 Instance Connect Endpoint](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-using-eice.html) in your VPC with CDK custom resource. +This is a CDK construct that allows you to build [EC2 Instance Connect Endpoint](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-using-eice.html) in your VPC with a CDK custom resource. -This sample is generated with [projen](https://github.com/projen/projen) `awscdk-construct` project type so you can reference the `.projenrc.ts` and create your own CDK construct library like this with very little modification. - -# sample +## Usage ```ts // create an EIC Endpoint in an isolated subnet @@ -14,52 +12,54 @@ new InstanceConnectEndpoint(stack, 'EICEndpoint', { }); ``` -See full sample at [integ.default.ts](./src/integ.default.ts). +See full sample at [bin/app.ts](./bin/app.ts). -# deploy the default integration test +## Deploy the sample application ```sh -$ cd typescripts/ec2-instance-connect-endpoint -$ yarn install -# configure your AWS CLI -$ npx cdk diff -$ npx cdk deploy +# Install dependencies +npm install + +# Configure your AWS CLI +npm run build +npx cdk diff +npx cdk deploy ``` -On deployment completed, check the instance ID from the output: +On deployment completion, check the instance ID from the output: ``` integ-testing-eicendpoint.InstanceId = i-01d0f0c7ca761ff29 ``` -Now, connect it with AWS CLI: +Now, connect to it with AWS CLI: ```sh -$ aws ec2-instance-connect ssh --instance-id i-01d0f0c7ca761ff29 +aws ec2-instance-connect ssh --instance-id i-01d0f0c7ca761ff29 ``` -# `awssh` +## `awssh` Shortcut -Alternatively, you can create an `awssh` alias like this: +You can create an `awssh` alias for convenience: ```sh alias awssh='aws ec2-instance-connect ssh --instance-id' ``` -Now, you can just `awssh` into any ec2 instance behind the endpoint. +Now, you can quickly connect to any EC2 instance behind the endpoint: ```sh -$ awssh i-01d0f0c7ca761ff29 +awssh i-01d0f0c7ca761ff29 ``` -# run the tests +## Run tests ```sh -$ yarn test +npm test ``` -# clean up +## Clean up ```sh -$ npx cdk destroy -``` \ No newline at end of file +npx cdk destroy +``` diff --git a/typescript/ec2-instance-connect-endpoint/src/integ.default.ts b/typescript/ec2-instance-connect-endpoint/bin/app.ts similarity index 87% rename from typescript/ec2-instance-connect-endpoint/src/integ.default.ts rename to typescript/ec2-instance-connect-endpoint/bin/app.ts index 9f8d581753..c0052266f9 100644 --- a/typescript/ec2-instance-connect-endpoint/src/integ.default.ts +++ b/typescript/ec2-instance-connect-endpoint/bin/app.ts @@ -1,8 +1,9 @@ +#!/usr/bin/env node import { App, CfnOutput, Stack, aws_ec2 as ec2, } from 'aws-cdk-lib'; -import { InstanceConnectEndpoint } from './endpoint'; +import { InstanceConnectEndpoint } from '../src/endpoint'; export class IntegTesting { readonly stack: Stack[]; @@ -11,7 +12,7 @@ export class IntegTesting { const env = { region: process.env.CDK_DEFAULT_REGION, account: process.env.CDK_DEFAULT_ACCOUNT }; const stack = new Stack(app, 'integ-testing-eicendpoint', { env }); - const vpc = new ec2.Vpc(stack, 'Vpc', { subnetConfiguration: [{ cidrMask: 24, name: 'rds', subnetType: ec2. SubnetType. PRIVATE_ISOLATED }] }); + const vpc = new ec2.Vpc(stack, 'Vpc', { subnetConfiguration: [{ cidrMask: 24, name: 'rds', subnetType: ec2.SubnetType.PRIVATE_ISOLATED }] }); const instance = new ec2.Instance(stack, 'instance', { vpc, diff --git a/typescript/ec2-instance-connect-endpoint/cdk.json b/typescript/ec2-instance-connect-endpoint/cdk.json index f818b2a3da..604244024e 100644 --- a/typescript/ec2-instance-connect-endpoint/cdk.json +++ b/typescript/ec2-instance-connect-endpoint/cdk.json @@ -1,3 +1,44 @@ { - "app": "npx ts-node --prefer-ts-exts src/integ.default.ts" + "app": "npx ts-node --prefer-ts-exts bin/app.ts", + "watch": { + "include": [ + "**" + ], + "exclude": [ + "README.md", + "cdk*.json", + "**/*.d.ts", + "**/*.js", + "tsconfig.json", + "package*.json", + "yarn.lock", + "node_modules", + "test" + ] + }, + "context": { + "@aws-cdk/aws-lambda:recognizeLayerVersion": true, + "@aws-cdk/core:checkSecretUsage": true, + "@aws-cdk/core:target-partitions": [ + "aws", + "aws-cn" + ], + "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, + "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, + "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, + "@aws-cdk/aws-iam:minimizePolicies": true, + "@aws-cdk/core:validateSnapshotRemovalPolicy": true, + "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true, + "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true, + "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true, + "@aws-cdk/aws-apigateway:disableCloudWatchRole": true, + "@aws-cdk/core:enablePartitionLiterals": true, + "@aws-cdk/aws-events:eventsTargetQueueSameAccount": true, + "@aws-cdk/aws-iam:standardizedServicePrincipals": true, + "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true, + "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true, + "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true, + "@aws-cdk/aws-route53-patters:useFargateContainerForCustomResourceFunction": true, + "@aws-cdk/customresources:installLatestAwsSdkDefault": false + } } diff --git a/typescript/ec2-instance-connect-endpoint/package.json b/typescript/ec2-instance-connect-endpoint/package.json index cdcb68154f..a095e040f9 100644 --- a/typescript/ec2-instance-connect-endpoint/package.json +++ b/typescript/ec2-instance-connect-endpoint/package.json @@ -4,6 +4,8 @@ "repository": { "type": "git", "url": "https://github.com/aws-samples/aws-cdk-examples.git" + "bin": { + "ec2-instance-connect-endpoint": "bin/app.js" }, "scripts": { "build": "tsc", @@ -11,36 +13,18 @@ "test": "jest", "cdk": "cdk" }, - "author": { - "name": "Pahud Hsieh", - "email": "pahudnet@gmail.com" }, "devDependencies": { "@types/jest": "^29.5.14", "@types/node": "^16", - "@typescript-eslint/eslint-plugin": "^5", - "@typescript-eslint/parser": "^5", - "aws-cdk": "2.85.0", - "aws-cdk-lib": "2.85.0", - "constructs": "10.0.5", - "eslint": "^8", - "jest": "^29.7.0", - "ts-jest": "^29.2.5", - "ts-node": "^10.9.2", - "typescript": "~5.6.3" - }, - "peerDependencies": { - "aws-cdk-lib": "^2.85.0", - "constructs": "^10.0.5" + "aws-cdk": "2.1007.0", + "jest": "^29.5.0", + "ts-jest": "^29.1.1", + "ts-node": "^10.9.1", + "typescript": "^5.1.6" }, "dependencies": { - "@aws-cdk/aws-lambda-python-alpha": "^2.85.0-alpha.0", - "@aws-cdk/integ-tests-alpha": "^2.85.0-alpha.0" - }, - "keywords": [ - "cdk" - ], - "main": "lib/index.js", - "types": "lib/index.d.ts", - "license": "Apache-2.0" + "aws-cdk-lib": "2.189.1", + "constructs": "10.0.5" + } } diff --git a/typescript/ec2-instance-connect-endpoint/src/endpoint.ts b/typescript/ec2-instance-connect-endpoint/src/endpoint.ts index eba945b3a9..b310c8b2bf 100644 --- a/typescript/ec2-instance-connect-endpoint/src/endpoint.ts +++ b/typescript/ec2-instance-connect-endpoint/src/endpoint.ts @@ -1,5 +1,4 @@ import * as path from 'path'; -import * as lambdaPython from '@aws-cdk/aws-lambda-python-alpha'; import { Stack, aws_ec2 as ec2, @@ -8,6 +7,7 @@ import { custom_resources as cr, CustomResource, Duration, + aws_s3_assets as assets, } from 'aws-cdk-lib'; import { Construct } from 'constructs'; @@ -75,29 +75,28 @@ export class InstanceConnectEndpoint extends Construct { resources: ['*'], })); + // Create an asset for the Lambda code + const lambdaAsset = new assets.Asset(this, 'LambdaAsset', { + path: path.join(__dirname, '../lambda.d'), + }); + + // Common properties for Lambda functions const commonProps = { - entry: path.join(__dirname, '../lambda.d'), runtime: lambda.Runtime.PYTHON_3_9, - index: 'index.py', memorySize: 256, timeout: Duration.minutes(10), role, + code: lambda.Code.fromBucket(lambdaAsset.bucket, lambdaAsset.s3ObjectKey), }; - const onEventHandler = new lambdaPython.PythonFunction(this, 'onEventHandler', { + const onEventHandler = new lambda.Function(this, 'onEventHandler', { ...commonProps, - handler: 'on_event', - bundling: { - user: "1000", - }, - }); + handler: 'index.on_event', + }); - const isCompleteHandler = new lambdaPython.PythonFunction(this, 'isCompleteHandler', { + const isCompleteHandler = new lambda.Function(this, 'isCompleteHandler', { ...commonProps, - handler: 'is_complete', - bundling: { - user: "1000", - }, + handler: 'index.is_complete', }); const provider = new cr.Provider(this, 'Provider', { diff --git a/typescript/ec2-instance-connect-endpoint/test/__snapshots__/integ.default.test.ts.snap b/typescript/ec2-instance-connect-endpoint/test/__snapshots__/integ.default.test.ts.snap deleted file mode 100644 index c403c7b7b2..0000000000 --- a/typescript/ec2-instance-connect-endpoint/test/__snapshots__/integ.default.test.ts.snap +++ /dev/null @@ -1,1295 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`default validation 1`] = ` -{ - "Mappings": { - "DefaultCrNodeVersionMap": { - "af-south-1": { - "value": "nodejs16.x", - }, - "ap-east-1": { - "value": "nodejs16.x", - }, - "ap-northeast-1": { - "value": "nodejs16.x", - }, - "ap-northeast-2": { - "value": "nodejs16.x", - }, - "ap-northeast-3": { - "value": "nodejs16.x", - }, - "ap-south-1": { - "value": "nodejs16.x", - }, - "ap-south-2": { - "value": "nodejs16.x", - }, - "ap-southeast-1": { - "value": "nodejs16.x", - }, - "ap-southeast-2": { - "value": "nodejs16.x", - }, - "ap-southeast-3": { - "value": "nodejs16.x", - }, - "ca-central-1": { - "value": "nodejs16.x", - }, - "cn-north-1": { - "value": "nodejs16.x", - }, - "cn-northwest-1": { - "value": "nodejs16.x", - }, - "eu-central-1": { - "value": "nodejs16.x", - }, - "eu-central-2": { - "value": "nodejs16.x", - }, - "eu-north-1": { - "value": "nodejs16.x", - }, - "eu-south-1": { - "value": "nodejs16.x", - }, - "eu-south-2": { - "value": "nodejs16.x", - }, - "eu-west-1": { - "value": "nodejs16.x", - }, - "eu-west-2": { - "value": "nodejs16.x", - }, - "eu-west-3": { - "value": "nodejs16.x", - }, - "me-central-1": { - "value": "nodejs16.x", - }, - "me-south-1": { - "value": "nodejs16.x", - }, - "sa-east-1": { - "value": "nodejs16.x", - }, - "us-east-1": { - "value": "nodejs16.x", - }, - "us-east-2": { - "value": "nodejs16.x", - }, - "us-gov-east-1": { - "value": "nodejs16.x", - }, - "us-gov-west-1": { - "value": "nodejs16.x", - }, - "us-iso-east-1": { - "value": "nodejs14.x", - }, - "us-iso-west-1": { - "value": "nodejs14.x", - }, - "us-isob-east-1": { - "value": "nodejs14.x", - }, - "us-west-1": { - "value": "nodejs16.x", - }, - "us-west-2": { - "value": "nodejs16.x", - }, - }, - "ServiceprincipalMap": { - "af-south-1": { - "states": "states.af-south-1.amazonaws.com", - }, - "ap-east-1": { - "states": "states.ap-east-1.amazonaws.com", - }, - "ap-northeast-1": { - "states": "states.ap-northeast-1.amazonaws.com", - }, - "ap-northeast-2": { - "states": "states.ap-northeast-2.amazonaws.com", - }, - "ap-northeast-3": { - "states": "states.ap-northeast-3.amazonaws.com", - }, - "ap-south-1": { - "states": "states.ap-south-1.amazonaws.com", - }, - "ap-south-2": { - "states": "states.ap-south-2.amazonaws.com", - }, - "ap-southeast-1": { - "states": "states.ap-southeast-1.amazonaws.com", - }, - "ap-southeast-2": { - "states": "states.ap-southeast-2.amazonaws.com", - }, - "ap-southeast-3": { - "states": "states.ap-southeast-3.amazonaws.com", - }, - "ca-central-1": { - "states": "states.ca-central-1.amazonaws.com", - }, - "cn-north-1": { - "states": "states.cn-north-1.amazonaws.com", - }, - "cn-northwest-1": { - "states": "states.cn-northwest-1.amazonaws.com", - }, - "eu-central-1": { - "states": "states.eu-central-1.amazonaws.com", - }, - "eu-central-2": { - "states": "states.eu-central-2.amazonaws.com", - }, - "eu-north-1": { - "states": "states.eu-north-1.amazonaws.com", - }, - "eu-south-1": { - "states": "states.eu-south-1.amazonaws.com", - }, - "eu-south-2": { - "states": "states.eu-south-2.amazonaws.com", - }, - "eu-west-1": { - "states": "states.eu-west-1.amazonaws.com", - }, - "eu-west-2": { - "states": "states.eu-west-2.amazonaws.com", - }, - "eu-west-3": { - "states": "states.eu-west-3.amazonaws.com", - }, - "me-central-1": { - "states": "states.me-central-1.amazonaws.com", - }, - "me-south-1": { - "states": "states.me-south-1.amazonaws.com", - }, - "sa-east-1": { - "states": "states.sa-east-1.amazonaws.com", - }, - "us-east-1": { - "states": "states.us-east-1.amazonaws.com", - }, - "us-east-2": { - "states": "states.us-east-2.amazonaws.com", - }, - "us-gov-east-1": { - "states": "states.us-gov-east-1.amazonaws.com", - }, - "us-gov-west-1": { - "states": "states.us-gov-west-1.amazonaws.com", - }, - "us-iso-east-1": { - "states": "states.amazonaws.com", - }, - "us-iso-west-1": { - "states": "states.amazonaws.com", - }, - "us-isob-east-1": { - "states": "states.amazonaws.com", - }, - "us-west-1": { - "states": "states.us-west-1.amazonaws.com", - }, - "us-west-2": { - "states": "states.us-west-2.amazonaws.com", - }, - }, - }, - "Outputs": { - "InstanceId": { - "Value": { - "Ref": "instanceB7CCE687", - }, - }, - }, - "Parameters": { - "BootstrapVersion": { - "Default": "/cdk-bootstrap/hnb659fds/version", - "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]", - "Type": "AWS::SSM::Parameter::Value", - }, - "SsmParameterValueawsserviceamiamazonlinuxlatestal2023amikernel61x8664C96584B6F00A464EAD1953AFF4B05118Parameter": { - "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", - "Type": "AWS::SSM::Parameter::Value", - }, - }, - "Resources": { - "EICEndpointEICEndpointResourceBED54177": { - "DeletionPolicy": "Delete", - "Properties": { - "PreserveClientIp": false, - "ServiceToken": { - "Fn::GetAtt": [ - "EICEndpointProviderframeworkonEventB48896C9", - "Arn", - ], - }, - "SubnetId": { - "Ref": "VpcrdsSubnet1SubnetC2926CEA", - }, - }, - "Type": "Custom::EC2InstanceConnectEndpoint", - "UpdateReplacePolicy": "Delete", - }, - "EICEndpointProviderframeworkisCompleteB1442B18": { - "DependsOn": [ - "EICEndpointProviderframeworkisCompleteServiceRoleDefaultPolicy5E52B832", - "EICEndpointProviderframeworkisCompleteServiceRole0E0A4C51", - ], - "Properties": { - "Code": { - "S3Bucket": { - "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", - }, - "S3Key": "NORMALIZED_ASSET_HASH.zip", - }, - "Description": "AWS CDK resource provider framework - isComplete (integ-testing-eicendpoint/EICEndpoint/Provider)", - "Environment": { - "Variables": { - "USER_IS_COMPLETE_FUNCTION_ARN": { - "Fn::GetAtt": [ - "EICEndpointisCompleteHandler0273707A", - "Arn", - ], - }, - "USER_ON_EVENT_FUNCTION_ARN": { - "Fn::GetAtt": [ - "EICEndpointonEventHandlerC2E1F5F2", - "Arn", - ], - }, - }, - }, - "Handler": "framework.isComplete", - "Role": { - "Fn::GetAtt": [ - "EICEndpointProviderframeworkisCompleteServiceRole0E0A4C51", - "Arn", - ], - }, - "Runtime": { - "Fn::FindInMap": [ - "DefaultCrNodeVersionMap", - { - "Ref": "AWS::Region", - }, - "value", - ], - }, - "Timeout": 900, - }, - "Type": "AWS::Lambda::Function", - }, - "EICEndpointProviderframeworkisCompleteServiceRole0E0A4C51": { - "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", - ], - ], - }, - ], - }, - "Type": "AWS::IAM::Role", - }, - "EICEndpointProviderframeworkisCompleteServiceRoleDefaultPolicy5E52B832": { - "Properties": { - "PolicyDocument": { - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Effect": "Allow", - "Resource": [ - { - "Fn::GetAtt": [ - "EICEndpointonEventHandlerC2E1F5F2", - "Arn", - ], - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "EICEndpointonEventHandlerC2E1F5F2", - "Arn", - ], - }, - ":*", - ], - ], - }, - ], - }, - { - "Action": "lambda:InvokeFunction", - "Effect": "Allow", - "Resource": [ - { - "Fn::GetAtt": [ - "EICEndpointisCompleteHandler0273707A", - "Arn", - ], - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "EICEndpointisCompleteHandler0273707A", - "Arn", - ], - }, - ":*", - ], - ], - }, - ], - }, - ], - "Version": "2012-10-17", - }, - "PolicyName": "EICEndpointProviderframeworkisCompleteServiceRoleDefaultPolicy5E52B832", - "Roles": [ - { - "Ref": "EICEndpointProviderframeworkisCompleteServiceRole0E0A4C51", - }, - ], - }, - "Type": "AWS::IAM::Policy", - }, - "EICEndpointProviderframeworkonEventB48896C9": { - "DependsOn": [ - "EICEndpointProviderframeworkonEventServiceRoleDefaultPolicy254E2AF6", - "EICEndpointProviderframeworkonEventServiceRoleC0D29A73", - ], - "Properties": { - "Code": { - "S3Bucket": { - "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", - }, - "S3Key": "NORMALIZED_ASSET_HASH.zip", - }, - "Description": "AWS CDK resource provider framework - onEvent (integ-testing-eicendpoint/EICEndpoint/Provider)", - "Environment": { - "Variables": { - "USER_IS_COMPLETE_FUNCTION_ARN": { - "Fn::GetAtt": [ - "EICEndpointisCompleteHandler0273707A", - "Arn", - ], - }, - "USER_ON_EVENT_FUNCTION_ARN": { - "Fn::GetAtt": [ - "EICEndpointonEventHandlerC2E1F5F2", - "Arn", - ], - }, - "WAITER_STATE_MACHINE_ARN": { - "Ref": "EICEndpointProviderwaiterstatemachine1A139B58", - }, - }, - }, - "Handler": "framework.onEvent", - "Role": { - "Fn::GetAtt": [ - "EICEndpointProviderframeworkonEventServiceRoleC0D29A73", - "Arn", - ], - }, - "Runtime": { - "Fn::FindInMap": [ - "DefaultCrNodeVersionMap", - { - "Ref": "AWS::Region", - }, - "value", - ], - }, - "Timeout": 900, - }, - "Type": "AWS::Lambda::Function", - }, - "EICEndpointProviderframeworkonEventServiceRoleC0D29A73": { - "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", - ], - ], - }, - ], - }, - "Type": "AWS::IAM::Role", - }, - "EICEndpointProviderframeworkonEventServiceRoleDefaultPolicy254E2AF6": { - "Properties": { - "PolicyDocument": { - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Effect": "Allow", - "Resource": [ - { - "Fn::GetAtt": [ - "EICEndpointonEventHandlerC2E1F5F2", - "Arn", - ], - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "EICEndpointonEventHandlerC2E1F5F2", - "Arn", - ], - }, - ":*", - ], - ], - }, - ], - }, - { - "Action": "lambda:InvokeFunction", - "Effect": "Allow", - "Resource": [ - { - "Fn::GetAtt": [ - "EICEndpointisCompleteHandler0273707A", - "Arn", - ], - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "EICEndpointisCompleteHandler0273707A", - "Arn", - ], - }, - ":*", - ], - ], - }, - ], - }, - { - "Action": "states:StartExecution", - "Effect": "Allow", - "Resource": { - "Ref": "EICEndpointProviderwaiterstatemachine1A139B58", - }, - }, - ], - "Version": "2012-10-17", - }, - "PolicyName": "EICEndpointProviderframeworkonEventServiceRoleDefaultPolicy254E2AF6", - "Roles": [ - { - "Ref": "EICEndpointProviderframeworkonEventServiceRoleC0D29A73", - }, - ], - }, - "Type": "AWS::IAM::Policy", - }, - "EICEndpointProviderframeworkonTimeout83318112": { - "DependsOn": [ - "EICEndpointProviderframeworkonTimeoutServiceRoleDefaultPolicyEDFD873D", - "EICEndpointProviderframeworkonTimeoutServiceRole904320AB", - ], - "Properties": { - "Code": { - "S3Bucket": { - "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", - }, - "S3Key": "NORMALIZED_ASSET_HASH.zip", - }, - "Description": "AWS CDK resource provider framework - onTimeout (integ-testing-eicendpoint/EICEndpoint/Provider)", - "Environment": { - "Variables": { - "USER_IS_COMPLETE_FUNCTION_ARN": { - "Fn::GetAtt": [ - "EICEndpointisCompleteHandler0273707A", - "Arn", - ], - }, - "USER_ON_EVENT_FUNCTION_ARN": { - "Fn::GetAtt": [ - "EICEndpointonEventHandlerC2E1F5F2", - "Arn", - ], - }, - }, - }, - "Handler": "framework.onTimeout", - "Role": { - "Fn::GetAtt": [ - "EICEndpointProviderframeworkonTimeoutServiceRole904320AB", - "Arn", - ], - }, - "Runtime": { - "Fn::FindInMap": [ - "DefaultCrNodeVersionMap", - { - "Ref": "AWS::Region", - }, - "value", - ], - }, - "Timeout": 900, - }, - "Type": "AWS::Lambda::Function", - }, - "EICEndpointProviderframeworkonTimeoutServiceRole904320AB": { - "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", - ], - ], - }, - ], - }, - "Type": "AWS::IAM::Role", - }, - "EICEndpointProviderframeworkonTimeoutServiceRoleDefaultPolicyEDFD873D": { - "Properties": { - "PolicyDocument": { - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Effect": "Allow", - "Resource": [ - { - "Fn::GetAtt": [ - "EICEndpointonEventHandlerC2E1F5F2", - "Arn", - ], - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "EICEndpointonEventHandlerC2E1F5F2", - "Arn", - ], - }, - ":*", - ], - ], - }, - ], - }, - { - "Action": "lambda:InvokeFunction", - "Effect": "Allow", - "Resource": [ - { - "Fn::GetAtt": [ - "EICEndpointisCompleteHandler0273707A", - "Arn", - ], - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "EICEndpointisCompleteHandler0273707A", - "Arn", - ], - }, - ":*", - ], - ], - }, - ], - }, - ], - "Version": "2012-10-17", - }, - "PolicyName": "EICEndpointProviderframeworkonTimeoutServiceRoleDefaultPolicyEDFD873D", - "Roles": [ - { - "Ref": "EICEndpointProviderframeworkonTimeoutServiceRole904320AB", - }, - ], - }, - "Type": "AWS::IAM::Policy", - }, - "EICEndpointProviderwaiterstatemachine1A139B58": { - "DependsOn": [ - "EICEndpointProviderwaiterstatemachineRoleDefaultPolicy5AAF9088", - "EICEndpointProviderwaiterstatemachineRole5E284D23", - ], - "Properties": { - "DefinitionString": { - "Fn::Join": [ - "", - [ - "{"StartAt":"framework-isComplete-task","States":{"framework-isComplete-task":{"End":true,"Retry":[{"ErrorEquals":["States.ALL"],"IntervalSeconds":5,"MaxAttempts":360,"BackoffRate":1}],"Catch":[{"ErrorEquals":["States.ALL"],"Next":"framework-onTimeout-task"}],"Type":"Task","Resource":"", - { - "Fn::GetAtt": [ - "EICEndpointProviderframeworkisCompleteB1442B18", - "Arn", - ], - }, - ""},"framework-onTimeout-task":{"End":true,"Type":"Task","Resource":"", - { - "Fn::GetAtt": [ - "EICEndpointProviderframeworkonTimeout83318112", - "Arn", - ], - }, - ""}}}", - ], - ], - }, - "RoleArn": { - "Fn::GetAtt": [ - "EICEndpointProviderwaiterstatemachineRole5E284D23", - "Arn", - ], - }, - }, - "Type": "AWS::StepFunctions::StateMachine", - }, - "EICEndpointProviderwaiterstatemachineRole5E284D23": { - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": { - "Fn::FindInMap": [ - "ServiceprincipalMap", - { - "Ref": "AWS::Region", - }, - "states", - ], - }, - }, - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::IAM::Role", - }, - "EICEndpointProviderwaiterstatemachineRoleDefaultPolicy5AAF9088": { - "Properties": { - "PolicyDocument": { - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Effect": "Allow", - "Resource": [ - { - "Fn::GetAtt": [ - "EICEndpointProviderframeworkisCompleteB1442B18", - "Arn", - ], - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "EICEndpointProviderframeworkisCompleteB1442B18", - "Arn", - ], - }, - ":*", - ], - ], - }, - ], - }, - { - "Action": "lambda:InvokeFunction", - "Effect": "Allow", - "Resource": [ - { - "Fn::GetAtt": [ - "EICEndpointProviderframeworkonTimeout83318112", - "Arn", - ], - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "EICEndpointProviderframeworkonTimeout83318112", - "Arn", - ], - }, - ":*", - ], - ], - }, - ], - }, - ], - "Version": "2012-10-17", - }, - "PolicyName": "EICEndpointProviderwaiterstatemachineRoleDefaultPolicy5AAF9088", - "Roles": [ - { - "Ref": "EICEndpointProviderwaiterstatemachineRole5E284D23", - }, - ], - }, - "Type": "AWS::IAM::Policy", - }, - "EICEndpointRole7DC4D43E": { - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com", - }, - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::IAM::Role", - }, - "EICEndpointRoleDefaultPolicy9C78FE54": { - "Properties": { - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "ec2:CreateInstanceConnectEndpoint", - "ec2:DeleteInstanceConnectEndpoint", - "ec2:CreateTags", - "ec2:CreateNetworkInterface", - ], - "Effect": "Allow", - "Resource": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition", - }, - ":ec2:", - { - "Ref": "AWS::Region", - }, - ":", - { - "Ref": "AWS::AccountId", - }, - ":instance-connect-endpoint/*", - ], - ], - }, - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition", - }, - ":ec2:", - { - "Ref": "AWS::Region", - }, - ":", - { - "Ref": "AWS::AccountId", - }, - ":network-interface/*", - ], - ], - }, - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition", - }, - ":ec2:", - { - "Ref": "AWS::Region", - }, - ":", - { - "Ref": "AWS::AccountId", - }, - ":subnet/*", - ], - ], - }, - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition", - }, - ":ec2:", - { - "Ref": "AWS::Region", - }, - ":", - { - "Ref": "AWS::AccountId", - }, - ":security-group/*", - ], - ], - }, - ], - }, - { - "Action": "ec2:DescribeInstanceConnectEndpoints", - "Effect": "Allow", - "Resource": "*", - }, - { - "Action": "iam:CreateServiceLinkedRole", - "Effect": "Allow", - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - "PolicyName": "EICEndpointRoleDefaultPolicy9C78FE54", - "Roles": [ - { - "Ref": "EICEndpointRole7DC4D43E", - }, - ], - }, - "Type": "AWS::IAM::Policy", - }, - "EICEndpointisCompleteHandler0273707A": { - "DependsOn": [ - "EICEndpointRoleDefaultPolicy9C78FE54", - "EICEndpointRole7DC4D43E", - ], - "Properties": { - "Code": { - "S3Bucket": { - "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", - }, - "S3Key": "NORMALIZED_ASSET_HASH.zip", - }, - "Handler": "index.is_complete", - "MemorySize": 256, - "Role": { - "Fn::GetAtt": [ - "EICEndpointRole7DC4D43E", - "Arn", - ], - }, - "Runtime": "python3.9", - "Timeout": 600, - }, - "Type": "AWS::Lambda::Function", - }, - "EICEndpointonEventHandlerC2E1F5F2": { - "DependsOn": [ - "EICEndpointRoleDefaultPolicy9C78FE54", - "EICEndpointRole7DC4D43E", - ], - "Properties": { - "Code": { - "S3Bucket": { - "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", - }, - "S3Key": "NORMALIZED_ASSET_HASH.zip", - }, - "Handler": "index.on_event", - "MemorySize": 256, - "Role": { - "Fn::GetAtt": [ - "EICEndpointRole7DC4D43E", - "Arn", - ], - }, - "Runtime": "python3.9", - "Timeout": 600, - }, - "Type": "AWS::Lambda::Function", - }, - "Vpc8378EB38": { - "Properties": { - "CidrBlock": "10.0.0.0/16", - "EnableDnsHostnames": true, - "EnableDnsSupport": true, - "InstanceTenancy": "default", - "Tags": [ - { - "Key": "Name", - "Value": "integ-testing-eicendpoint/Vpc", - }, - ], - }, - "Type": "AWS::EC2::VPC", - }, - "VpcrdsSubnet1RouteTableAssociationE01668F2": { - "Properties": { - "RouteTableId": { - "Ref": "VpcrdsSubnet1RouteTableE62E4ED6", - }, - "SubnetId": { - "Ref": "VpcrdsSubnet1SubnetC2926CEA", - }, - }, - "Type": "AWS::EC2::SubnetRouteTableAssociation", - }, - "VpcrdsSubnet1RouteTableE62E4ED6": { - "Properties": { - "Tags": [ - { - "Key": "Name", - "Value": "integ-testing-eicendpoint/Vpc/rdsSubnet1", - }, - ], - "VpcId": { - "Ref": "Vpc8378EB38", - }, - }, - "Type": "AWS::EC2::RouteTable", - }, - "VpcrdsSubnet1SubnetC2926CEA": { - "Properties": { - "AvailabilityZone": { - "Fn::Select": [ - 0, - { - "Fn::GetAZs": "", - }, - ], - }, - "CidrBlock": "10.0.0.0/24", - "MapPublicIpOnLaunch": false, - "Tags": [ - { - "Key": "aws-cdk:subnet-name", - "Value": "rds", - }, - { - "Key": "aws-cdk:subnet-type", - "Value": "Isolated", - }, - { - "Key": "Name", - "Value": "integ-testing-eicendpoint/Vpc/rdsSubnet1", - }, - ], - "VpcId": { - "Ref": "Vpc8378EB38", - }, - }, - "Type": "AWS::EC2::Subnet", - }, - "VpcrdsSubnet2RouteTable3E531D9B": { - "Properties": { - "Tags": [ - { - "Key": "Name", - "Value": "integ-testing-eicendpoint/Vpc/rdsSubnet2", - }, - ], - "VpcId": { - "Ref": "Vpc8378EB38", - }, - }, - "Type": "AWS::EC2::RouteTable", - }, - "VpcrdsSubnet2RouteTableAssociation25A7BD68": { - "Properties": { - "RouteTableId": { - "Ref": "VpcrdsSubnet2RouteTable3E531D9B", - }, - "SubnetId": { - "Ref": "VpcrdsSubnet2Subnet70A835C8", - }, - }, - "Type": "AWS::EC2::SubnetRouteTableAssociation", - }, - "VpcrdsSubnet2Subnet70A835C8": { - "Properties": { - "AvailabilityZone": { - "Fn::Select": [ - 1, - { - "Fn::GetAZs": "", - }, - ], - }, - "CidrBlock": "10.0.1.0/24", - "MapPublicIpOnLaunch": false, - "Tags": [ - { - "Key": "aws-cdk:subnet-name", - "Value": "rds", - }, - { - "Key": "aws-cdk:subnet-type", - "Value": "Isolated", - }, - { - "Key": "Name", - "Value": "integ-testing-eicendpoint/Vpc/rdsSubnet2", - }, - ], - "VpcId": { - "Ref": "Vpc8378EB38", - }, - }, - "Type": "AWS::EC2::Subnet", - }, - "instanceB7CCE687": { - "DependsOn": [ - "instanceInstanceRoleF436EE92", - ], - "Properties": { - "AvailabilityZone": { - "Fn::Select": [ - 0, - { - "Fn::GetAZs": "", - }, - ], - }, - "IamInstanceProfile": { - "Ref": "instanceInstanceProfile931F14E3", - }, - "ImageId": { - "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestal2023amikernel61x8664C96584B6F00A464EAD1953AFF4B05118Parameter", - }, - "InstanceType": "t3.large", - "SecurityGroupIds": [ - { - "Fn::GetAtt": [ - "instanceInstanceSecurityGroup725C795D", - "GroupId", - ], - }, - ], - "SubnetId": { - "Ref": "VpcrdsSubnet1SubnetC2926CEA", - }, - "Tags": [ - { - "Key": "Name", - "Value": "integ-testing-eicendpoint/instance", - }, - ], - "UserData": { - "Fn::Base64": "#!/bin/bash", - }, - }, - "Type": "AWS::EC2::Instance", - }, - "instanceInstanceProfile931F14E3": { - "Properties": { - "Roles": [ - { - "Ref": "instanceInstanceRoleF436EE92", - }, - ], - }, - "Type": "AWS::IAM::InstanceProfile", - }, - "instanceInstanceRoleF436EE92": { - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "ec2.amazonaws.com", - }, - }, - ], - "Version": "2012-10-17", - }, - "Tags": [ - { - "Key": "Name", - "Value": "integ-testing-eicendpoint/instance", - }, - ], - }, - "Type": "AWS::IAM::Role", - }, - "instanceInstanceSecurityGroup725C795D": { - "Properties": { - "GroupDescription": "integ-testing-eicendpoint/instance/InstanceSecurityGroup", - "SecurityGroupEgress": [ - { - "CidrIp": "0.0.0.0/0", - "Description": "Allow all outbound traffic by default", - "IpProtocol": "-1", - }, - ], - "SecurityGroupIngress": [ - { - "CidrIp": { - "Fn::GetAtt": [ - "Vpc8378EB38", - "CidrBlock", - ], - }, - "Description": { - "Fn::Join": [ - "", - [ - "from ", - { - "Fn::GetAtt": [ - "Vpc8378EB38", - "CidrBlock", - ], - }, - ":ALL TRAFFIC", - ], - ], - }, - "IpProtocol": "-1", - }, - ], - "Tags": [ - { - "Key": "Name", - "Value": "integ-testing-eicendpoint/instance", - }, - ], - "VpcId": { - "Ref": "Vpc8378EB38", - }, - }, - "Type": "AWS::EC2::SecurityGroup", - }, - }, - "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.", - }, - ], - }, - }, -} -`; diff --git a/typescript/ec2-instance-connect-endpoint/test/integ.default.test.ts b/typescript/ec2-instance-connect-endpoint/test/app.test.ts similarity index 75% rename from typescript/ec2-instance-connect-endpoint/test/integ.default.test.ts rename to typescript/ec2-instance-connect-endpoint/test/app.test.ts index 5350884124..5a27e84927 100644 --- a/typescript/ec2-instance-connect-endpoint/test/integ.default.test.ts +++ b/typescript/ec2-instance-connect-endpoint/test/app.test.ts @@ -1,6 +1,5 @@ import { Template } from 'aws-cdk-lib/assertions'; -import { IntegTesting } from '../src/integ.default'; -import { normalizeTemplate } from '../../test-utils/normalize-template'; +import { IntegTesting } from '../bin/app'; test('default validation', () => { const integ = new IntegTesting(); @@ -11,4 +10,4 @@ test('default validation', () => { // should match snapshot expect(normalizedTemplate).toMatchSnapshot(); }); -}); \ No newline at end of file +}); diff --git a/typescript/ec2-instance-connect-endpoint/tsconfig.json b/typescript/ec2-instance-connect-endpoint/tsconfig.json index dc6a7b03f6..e20b2b4957 100644 --- a/typescript/ec2-instance-connect-endpoint/tsconfig.json +++ b/typescript/ec2-instance-connect-endpoint/tsconfig.json @@ -2,7 +2,9 @@ "compilerOptions": { "target": "ES2018", "module": "commonjs", - "lib": ["es2018"], + "lib": [ + "es2018" + ], "declaration": true, "strict": true, "noImplicitAny": true, @@ -17,8 +19,14 @@ "inlineSources": true, "experimentalDecorators": true, "strictPropertyInitialization": false, - "typeRoots": ["./node_modules/@types"], - "outDir": "dist" + "typeRoots": [ + "./node_modules/@types" + ], + "outDir": "lib", + "rootDir": "." }, - "exclude": ["node_modules", "cdk.out"] + "exclude": [ + "node_modules", + "cdk.out" + ] } From de29e475b95bf420a53686069779c3b5c7b449d7 Mon Sep 17 00:00:00 2001 From: Michael Kaiser Date: Fri, 18 Apr 2025 08:50:00 -0500 Subject: [PATCH 2/6] Fix: Jest to run locally --- .../ec2-instance-connect-endpoint/API.md | 229 --- .../package.json | 4 +- .../test/__snapshots__/app.test.ts.snap | 1319 +++++++++++++++++ 3 files changed, 1321 insertions(+), 231 deletions(-) delete mode 100644 typescript/ec2-instance-connect-endpoint/API.md create mode 100644 typescript/ec2-instance-connect-endpoint/test/__snapshots__/app.test.ts.snap diff --git a/typescript/ec2-instance-connect-endpoint/API.md b/typescript/ec2-instance-connect-endpoint/API.md deleted file mode 100644 index 4b9668e588..0000000000 --- a/typescript/ec2-instance-connect-endpoint/API.md +++ /dev/null @@ -1,229 +0,0 @@ -# InstanceConnectEndpoint - -`InstanceConnectEndpoint` is a sample AWS CDK construct that allows you to build [EC2 Instance Connect Endpoint](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-using-eice.html) in your VPC with CDK custom resource. - -This sample is generated with [projen](https://github.com/projen/projen) `awscdk-construct` project type so you can reference the `.projenrc.ts` and create your own CDK construct library like this with very little modification. - -# sample - -```ts -// create an EIC Endpoint in an isolated subnet -new InstanceConnectEndpoint(stack, 'EICEndpoint', { - subnet: vpc.isolatedSubnets[0], - preserveClientIp: false, -}); -``` - -See full sample at [integ.default.ts](./src/integ.default.ts). - -# deploy the default integration test - -```sh -$ cd typescripts/ec2-instance-connect-endpoint -$ yarn install -# configure your AWS CLI -$ npx cdk diff -$ npx cdk deploy -``` - -On deployment completed, check the instance ID from the output: - -``` -integ-testing-eicendpoint.InstanceId = i-01d0f0c7ca761ff29 -``` - -Now, connect it with AWS CLI: - -```sh -$ aws ec2-instance-connect ssh --instance-id i-01d0f0c7ca761ff29 -``` - -# `awssh` - -Alternatively, you can create an `awssh` alias like this: - -```sh -alias awssh='aws ec2-instance-connect ssh --instance-id' -``` - -Now, you can just `awssh` into any ec2 instance behind the endpoint. - -```sh -$ awssh i-01d0f0c7ca761ff29 -``` - -# run the tests - -```sh -$ yarn test -``` - -# clean up - -```sh -$ npx cdk destroy -``` -# API Reference - -## Constructs - -### InstanceConnectEndpoint - -#### Initializers - -```typescript -import { InstanceConnectEndpoint } from 'ec2-instance-connect-endpoint' - -new InstanceConnectEndpoint(scope: Construct, id: string, props: InstanceConnectEndpointProps) -``` - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| scope | constructs.Construct | *No description.* | -| id | string | *No description.* | -| props | InstanceConnectEndpointProps | *No description.* | - ---- - -##### `scope`Required - -- *Type:* constructs.Construct - ---- - -##### `id`Required - -- *Type:* string - ---- - -##### `props`Required - -- *Type:* InstanceConnectEndpointProps - ---- - -#### Methods - -| **Name** | **Description** | -| --- | --- | -| toString | Returns a string representation of this construct. | - ---- - -##### `toString` - -```typescript -public toString(): string -``` - -Returns a string representation of this construct. - -#### Static Functions - -| **Name** | **Description** | -| --- | --- | -| isConstruct | Checks if `x` is a construct. | - ---- - -##### ~~`isConstruct`~~ - -```typescript -import { InstanceConnectEndpoint } from 'ec2-instance-connect-endpoint' - -InstanceConnectEndpoint.isConstruct(x: any) -``` - -Checks if `x` is a construct. - -###### `x`Required - -- *Type:* any - -Any object. - ---- - -#### Properties - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| node | constructs.Node | The tree node. | - ---- - -##### `node`Required - -```typescript -public readonly node: Node; -``` - -- *Type:* constructs.Node - -The tree node. - ---- - - -## Structs - -### InstanceConnectEndpointProps - -#### Initializer - -```typescript -import { InstanceConnectEndpointProps } from 'ec2-instance-connect-endpoint' - -const instanceConnectEndpointProps: InstanceConnectEndpointProps = { ... } -``` - -#### Properties - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| subnet | aws-cdk-lib.aws_ec2.ISubnet | EC2 subnet for this endpoint. | -| preserveClientIp | boolean | whether to enable the preserveClientIp. | -| securityGroup | aws-cdk-lib.aws_ec2.ISecurityGroup[] | Security groups of this endpoint. | - ---- - -##### `subnet`Required - -```typescript -public readonly subnet: ISubnet; -``` - -- *Type:* aws-cdk-lib.aws_ec2.ISubnet - -EC2 subnet for this endpoint. - ---- - -##### `preserveClientIp`Optional - -```typescript -public readonly preserveClientIp: boolean; -``` - -- *Type:* boolean -- *Default:* true - -whether to enable the preserveClientIp. - ---- - -##### `securityGroup`Optional - -```typescript -public readonly securityGroup: ISecurityGroup[]; -``` - -- *Type:* aws-cdk-lib.aws_ec2.ISecurityGroup[] - -Security groups of this endpoint. - ---- - - - diff --git a/typescript/ec2-instance-connect-endpoint/package.json b/typescript/ec2-instance-connect-endpoint/package.json index a095e040f9..674ddd6562 100644 --- a/typescript/ec2-instance-connect-endpoint/package.json +++ b/typescript/ec2-instance-connect-endpoint/package.json @@ -17,14 +17,14 @@ "devDependencies": { "@types/jest": "^29.5.14", "@types/node": "^16", - "aws-cdk": "2.1007.0", + "aws-cdk": "2.85.0", "jest": "^29.5.0", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", "typescript": "^5.1.6" }, "dependencies": { - "aws-cdk-lib": "2.189.1", + "aws-cdk-lib": "2.85.0", "constructs": "10.0.5" } } diff --git a/typescript/ec2-instance-connect-endpoint/test/__snapshots__/app.test.ts.snap b/typescript/ec2-instance-connect-endpoint/test/__snapshots__/app.test.ts.snap new file mode 100644 index 0000000000..66e619f290 --- /dev/null +++ b/typescript/ec2-instance-connect-endpoint/test/__snapshots__/app.test.ts.snap @@ -0,0 +1,1319 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`default validation 1`] = ` +{ + "Mappings": { + "LatestNodeRuntimeMap": { + "af-south-1": { + "value": "nodejs20.x", + }, + "ap-east-1": { + "value": "nodejs20.x", + }, + "ap-northeast-1": { + "value": "nodejs20.x", + }, + "ap-northeast-2": { + "value": "nodejs20.x", + }, + "ap-northeast-3": { + "value": "nodejs20.x", + }, + "ap-south-1": { + "value": "nodejs20.x", + }, + "ap-south-2": { + "value": "nodejs20.x", + }, + "ap-southeast-1": { + "value": "nodejs20.x", + }, + "ap-southeast-2": { + "value": "nodejs20.x", + }, + "ap-southeast-3": { + "value": "nodejs20.x", + }, + "ap-southeast-4": { + "value": "nodejs20.x", + }, + "ap-southeast-5": { + "value": "nodejs20.x", + }, + "ap-southeast-7": { + "value": "nodejs20.x", + }, + "ca-central-1": { + "value": "nodejs20.x", + }, + "ca-west-1": { + "value": "nodejs20.x", + }, + "cn-north-1": { + "value": "nodejs20.x", + }, + "cn-northwest-1": { + "value": "nodejs20.x", + }, + "eu-central-1": { + "value": "nodejs20.x", + }, + "eu-central-2": { + "value": "nodejs20.x", + }, + "eu-isoe-west-1": { + "value": "nodejs18.x", + }, + "eu-north-1": { + "value": "nodejs20.x", + }, + "eu-south-1": { + "value": "nodejs20.x", + }, + "eu-south-2": { + "value": "nodejs20.x", + }, + "eu-west-1": { + "value": "nodejs20.x", + }, + "eu-west-2": { + "value": "nodejs20.x", + }, + "eu-west-3": { + "value": "nodejs20.x", + }, + "il-central-1": { + "value": "nodejs20.x", + }, + "me-central-1": { + "value": "nodejs20.x", + }, + "me-south-1": { + "value": "nodejs20.x", + }, + "mx-central-1": { + "value": "nodejs20.x", + }, + "sa-east-1": { + "value": "nodejs20.x", + }, + "us-east-1": { + "value": "nodejs20.x", + }, + "us-east-2": { + "value": "nodejs20.x", + }, + "us-gov-east-1": { + "value": "nodejs20.x", + }, + "us-gov-west-1": { + "value": "nodejs20.x", + }, + "us-iso-east-1": { + "value": "nodejs18.x", + }, + "us-iso-west-1": { + "value": "nodejs18.x", + }, + "us-isob-east-1": { + "value": "nodejs18.x", + }, + "us-west-1": { + "value": "nodejs20.x", + }, + "us-west-2": { + "value": "nodejs20.x", + }, + }, + }, + "Outputs": { + "InstanceId": { + "Value": { + "Ref": "instanceB7CCE687", + }, + }, + }, + "Parameters": { + "BootstrapVersion": { + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]", + "Type": "AWS::SSM::Parameter::Value", + }, + "SsmParameterValueawsserviceamiamazonlinuxlatestal2023amikernel61x8664C96584B6F00A464EAD1953AFF4B05118Parameter": { + "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "Type": "AWS::SSM::Parameter::Value", + }, + }, + "Resources": { + "EICEndpointEICEndpointResourceBED54177": { + "DeletionPolicy": "Delete", + "Properties": { + "PreserveClientIp": false, + "ServiceToken": { + "Fn::GetAtt": [ + "EICEndpointProviderframeworkonEventB48896C9", + "Arn", + ], + }, + "SubnetId": { + "Ref": "VpcrdsSubnet1SubnetC2926CEA", + }, + }, + "Type": "Custom::EC2InstanceConnectEndpoint", + "UpdateReplacePolicy": "Delete", + }, + "EICEndpointProviderframeworkisCompleteB1442B18": { + "DependsOn": [ + "EICEndpointProviderframeworkisCompleteServiceRoleDefaultPolicy5E52B832", + "EICEndpointProviderframeworkisCompleteServiceRole0E0A4C51", + ], + "Properties": { + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", + }, + "S3Key": "bdc104ed9cab1b5b6421713c8155f0b753380595356f710400609664d3635eca.zip", + }, + "Description": "AWS CDK resource provider framework - isComplete (integ-testing-eicendpoint/EICEndpoint/Provider)", + "Environment": { + "Variables": { + "USER_IS_COMPLETE_FUNCTION_ARN": { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + "USER_ON_EVENT_FUNCTION_ARN": { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + }, + }, + "Handler": "framework.isComplete", + "Role": { + "Fn::GetAtt": [ + "EICEndpointProviderframeworkisCompleteServiceRole0E0A4C51", + "Arn", + ], + }, + "Runtime": { + "Fn::FindInMap": [ + "LatestNodeRuntimeMap", + { + "Ref": "AWS::Region", + }, + "value", + ], + }, + "Timeout": 900, + }, + "Type": "AWS::Lambda::Function", + }, + "EICEndpointProviderframeworkisCompleteServiceRole0E0A4C51": { + "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", + ], + ], + }, + ], + }, + "Type": "AWS::IAM::Role", + }, + "EICEndpointProviderframeworkisCompleteServiceRoleDefaultPolicy5E52B832": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + ":*", + ], + ], + }, + ], + }, + { + "Action": "lambda:GetFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + }, + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + ":*", + ], + ], + }, + ], + }, + { + "Action": "lambda:GetFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "EICEndpointProviderframeworkisCompleteServiceRoleDefaultPolicy5E52B832", + "Roles": [ + { + "Ref": "EICEndpointProviderframeworkisCompleteServiceRole0E0A4C51", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + "EICEndpointProviderframeworkonEventB48896C9": { + "DependsOn": [ + "EICEndpointProviderframeworkonEventServiceRoleDefaultPolicy254E2AF6", + "EICEndpointProviderframeworkonEventServiceRoleC0D29A73", + ], + "Properties": { + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", + }, + "S3Key": "bdc104ed9cab1b5b6421713c8155f0b753380595356f710400609664d3635eca.zip", + }, + "Description": "AWS CDK resource provider framework - onEvent (integ-testing-eicendpoint/EICEndpoint/Provider)", + "Environment": { + "Variables": { + "USER_IS_COMPLETE_FUNCTION_ARN": { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + "USER_ON_EVENT_FUNCTION_ARN": { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + "WAITER_STATE_MACHINE_ARN": { + "Ref": "EICEndpointProviderwaiterstatemachine1A139B58", + }, + }, + }, + "Handler": "framework.onEvent", + "Role": { + "Fn::GetAtt": [ + "EICEndpointProviderframeworkonEventServiceRoleC0D29A73", + "Arn", + ], + }, + "Runtime": { + "Fn::FindInMap": [ + "LatestNodeRuntimeMap", + { + "Ref": "AWS::Region", + }, + "value", + ], + }, + "Timeout": 900, + }, + "Type": "AWS::Lambda::Function", + }, + "EICEndpointProviderframeworkonEventServiceRoleC0D29A73": { + "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", + ], + ], + }, + ], + }, + "Type": "AWS::IAM::Role", + }, + "EICEndpointProviderframeworkonEventServiceRoleDefaultPolicy254E2AF6": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + ":*", + ], + ], + }, + ], + }, + { + "Action": "lambda:GetFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + }, + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + ":*", + ], + ], + }, + ], + }, + { + "Action": "lambda:GetFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + }, + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "EICEndpointProviderwaiterstatemachine1A139B58", + }, + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "EICEndpointProviderframeworkonEventServiceRoleDefaultPolicy254E2AF6", + "Roles": [ + { + "Ref": "EICEndpointProviderframeworkonEventServiceRoleC0D29A73", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + "EICEndpointProviderframeworkonTimeout83318112": { + "DependsOn": [ + "EICEndpointProviderframeworkonTimeoutServiceRoleDefaultPolicyEDFD873D", + "EICEndpointProviderframeworkonTimeoutServiceRole904320AB", + ], + "Properties": { + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", + }, + "S3Key": "bdc104ed9cab1b5b6421713c8155f0b753380595356f710400609664d3635eca.zip", + }, + "Description": "AWS CDK resource provider framework - onTimeout (integ-testing-eicendpoint/EICEndpoint/Provider)", + "Environment": { + "Variables": { + "USER_IS_COMPLETE_FUNCTION_ARN": { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + "USER_ON_EVENT_FUNCTION_ARN": { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + }, + }, + "Handler": "framework.onTimeout", + "Role": { + "Fn::GetAtt": [ + "EICEndpointProviderframeworkonTimeoutServiceRole904320AB", + "Arn", + ], + }, + "Runtime": { + "Fn::FindInMap": [ + "LatestNodeRuntimeMap", + { + "Ref": "AWS::Region", + }, + "value", + ], + }, + "Timeout": 900, + }, + "Type": "AWS::Lambda::Function", + }, + "EICEndpointProviderframeworkonTimeoutServiceRole904320AB": { + "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", + ], + ], + }, + ], + }, + "Type": "AWS::IAM::Role", + }, + "EICEndpointProviderframeworkonTimeoutServiceRoleDefaultPolicyEDFD873D": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + ":*", + ], + ], + }, + ], + }, + { + "Action": "lambda:GetFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "EICEndpointonEventHandlerC2E1F5F2", + "Arn", + ], + }, + }, + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + ":*", + ], + ], + }, + ], + }, + { + "Action": "lambda:GetFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "EICEndpointisCompleteHandler0273707A", + "Arn", + ], + }, + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "EICEndpointProviderframeworkonTimeoutServiceRoleDefaultPolicyEDFD873D", + "Roles": [ + { + "Ref": "EICEndpointProviderframeworkonTimeoutServiceRole904320AB", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + "EICEndpointProviderwaiterstatemachine1A139B58": { + "DependsOn": [ + "EICEndpointProviderwaiterstatemachineRoleDefaultPolicy5AAF9088", + "EICEndpointProviderwaiterstatemachineRole5E284D23", + ], + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "", + [ + "{"StartAt":"framework-isComplete-task","States":{"framework-isComplete-task":{"End":true,"Retry":[{"ErrorEquals":["States.ALL"],"IntervalSeconds":5,"MaxAttempts":360,"BackoffRate":1}],"Catch":[{"ErrorEquals":["States.ALL"],"Next":"framework-onTimeout-task"}],"Type":"Task","Resource":"", + { + "Fn::GetAtt": [ + "EICEndpointProviderframeworkisCompleteB1442B18", + "Arn", + ], + }, + ""},"framework-onTimeout-task":{"End":true,"Type":"Task","Resource":"", + { + "Fn::GetAtt": [ + "EICEndpointProviderframeworkonTimeout83318112", + "Arn", + ], + }, + ""}}}", + ], + ], + }, + "LoggingConfiguration": { + "Destinations": [ + { + "CloudWatchLogsLogGroup": { + "LogGroupArn": { + "Fn::GetAtt": [ + "EICEndpointProviderwaiterstatemachineLogGroupA14674E7", + "Arn", + ], + }, + }, + }, + ], + "IncludeExecutionData": false, + "Level": "ERROR", + }, + "RoleArn": { + "Fn::GetAtt": [ + "EICEndpointProviderwaiterstatemachineRole5E284D23", + "Arn", + ], + }, + }, + "Type": "AWS::StepFunctions::StateMachine", + }, + "EICEndpointProviderwaiterstatemachineLogGroupA14674E7": { + "DeletionPolicy": "Retain", + "Properties": { + "LogGroupName": { + "Fn::Join": [ + "", + [ + "/aws/vendedlogs/states/waiter-state-machine-", + { + "Ref": "EICEndpointProviderframeworkisCompleteB1442B18", + }, + "-c8d3e609467293bed52b842a64c4ccf79555d8f837", + ], + ], + }, + "RetentionInDays": 731, + }, + "Type": "AWS::Logs::LogGroup", + "UpdateReplacePolicy": "Retain", + }, + "EICEndpointProviderwaiterstatemachineRole5E284D23": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "states.amazonaws.com", + }, + }, + ], + "Version": "2012-10-17", + }, + }, + "Type": "AWS::IAM::Role", + }, + "EICEndpointProviderwaiterstatemachineRoleDefaultPolicy5AAF9088": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "EICEndpointProviderframeworkisCompleteB1442B18", + "Arn", + ], + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "EICEndpointProviderframeworkisCompleteB1442B18", + "Arn", + ], + }, + ":*", + ], + ], + }, + ], + }, + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "EICEndpointProviderframeworkonTimeout83318112", + "Arn", + ], + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "EICEndpointProviderframeworkonTimeout83318112", + "Arn", + ], + }, + ":*", + ], + ], + }, + ], + }, + { + "Action": [ + "logs:CreateLogDelivery", + "logs:CreateLogStream", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + "logs:PutLogEvents", + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups", + ], + "Effect": "Allow", + "Resource": "*", + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "EICEndpointProviderwaiterstatemachineRoleDefaultPolicy5AAF9088", + "Roles": [ + { + "Ref": "EICEndpointProviderwaiterstatemachineRole5E284D23", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + "EICEndpointRole7DC4D43E": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com", + }, + }, + ], + "Version": "2012-10-17", + }, + }, + "Type": "AWS::IAM::Role", + }, + "EICEndpointRoleDefaultPolicy9C78FE54": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "ec2:CreateInstanceConnectEndpoint", + "ec2:DeleteInstanceConnectEndpoint", + "ec2:CreateTags", + "ec2:CreateNetworkInterface", + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition", + }, + ":ec2:", + { + "Ref": "AWS::Region", + }, + ":", + { + "Ref": "AWS::AccountId", + }, + ":instance-connect-endpoint/*", + ], + ], + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition", + }, + ":ec2:", + { + "Ref": "AWS::Region", + }, + ":", + { + "Ref": "AWS::AccountId", + }, + ":network-interface/*", + ], + ], + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition", + }, + ":ec2:", + { + "Ref": "AWS::Region", + }, + ":", + { + "Ref": "AWS::AccountId", + }, + ":subnet/*", + ], + ], + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition", + }, + ":ec2:", + { + "Ref": "AWS::Region", + }, + ":", + { + "Ref": "AWS::AccountId", + }, + ":security-group/*", + ], + ], + }, + ], + }, + { + "Action": "ec2:DescribeInstanceConnectEndpoints", + "Effect": "Allow", + "Resource": "*", + }, + { + "Action": "iam:CreateServiceLinkedRole", + "Effect": "Allow", + "Resource": "*", + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "EICEndpointRoleDefaultPolicy9C78FE54", + "Roles": [ + { + "Ref": "EICEndpointRole7DC4D43E", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + "EICEndpointisCompleteHandler0273707A": { + "DependsOn": [ + "EICEndpointRoleDefaultPolicy9C78FE54", + "EICEndpointRole7DC4D43E", + ], + "Properties": { + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", + }, + "S3Key": "580e7199f29d3a4ba21264e35db2b99e791d0c4bc8d5e635d4bc85da65923391.zip", + }, + "Handler": "index.is_complete", + "MemorySize": 256, + "Role": { + "Fn::GetAtt": [ + "EICEndpointRole7DC4D43E", + "Arn", + ], + }, + "Runtime": "python3.9", + "Timeout": 600, + }, + "Type": "AWS::Lambda::Function", + }, + "EICEndpointonEventHandlerC2E1F5F2": { + "DependsOn": [ + "EICEndpointRoleDefaultPolicy9C78FE54", + "EICEndpointRole7DC4D43E", + ], + "Properties": { + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", + }, + "S3Key": "580e7199f29d3a4ba21264e35db2b99e791d0c4bc8d5e635d4bc85da65923391.zip", + }, + "Handler": "index.on_event", + "MemorySize": 256, + "Role": { + "Fn::GetAtt": [ + "EICEndpointRole7DC4D43E", + "Arn", + ], + }, + "Runtime": "python3.9", + "Timeout": 600, + }, + "Type": "AWS::Lambda::Function", + }, + "Vpc8378EB38": { + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "integ-testing-eicendpoint/Vpc", + }, + ], + }, + "Type": "AWS::EC2::VPC", + }, + "VpcrdsSubnet1RouteTableAssociationE01668F2": { + "Properties": { + "RouteTableId": { + "Ref": "VpcrdsSubnet1RouteTableE62E4ED6", + }, + "SubnetId": { + "Ref": "VpcrdsSubnet1SubnetC2926CEA", + }, + }, + "Type": "AWS::EC2::SubnetRouteTableAssociation", + }, + "VpcrdsSubnet1RouteTableE62E4ED6": { + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "integ-testing-eicendpoint/Vpc/rdsSubnet1", + }, + ], + "VpcId": { + "Ref": "Vpc8378EB38", + }, + }, + "Type": "AWS::EC2::RouteTable", + }, + "VpcrdsSubnet1SubnetC2926CEA": { + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "", + }, + ], + }, + "CidrBlock": "10.0.0.0/24", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "rds", + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Isolated", + }, + { + "Key": "Name", + "Value": "integ-testing-eicendpoint/Vpc/rdsSubnet1", + }, + ], + "VpcId": { + "Ref": "Vpc8378EB38", + }, + }, + "Type": "AWS::EC2::Subnet", + }, + "VpcrdsSubnet2RouteTable3E531D9B": { + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "integ-testing-eicendpoint/Vpc/rdsSubnet2", + }, + ], + "VpcId": { + "Ref": "Vpc8378EB38", + }, + }, + "Type": "AWS::EC2::RouteTable", + }, + "VpcrdsSubnet2RouteTableAssociation25A7BD68": { + "Properties": { + "RouteTableId": { + "Ref": "VpcrdsSubnet2RouteTable3E531D9B", + }, + "SubnetId": { + "Ref": "VpcrdsSubnet2Subnet70A835C8", + }, + }, + "Type": "AWS::EC2::SubnetRouteTableAssociation", + }, + "VpcrdsSubnet2Subnet70A835C8": { + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "", + }, + ], + }, + "CidrBlock": "10.0.1.0/24", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "rds", + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Isolated", + }, + { + "Key": "Name", + "Value": "integ-testing-eicendpoint/Vpc/rdsSubnet2", + }, + ], + "VpcId": { + "Ref": "Vpc8378EB38", + }, + }, + "Type": "AWS::EC2::Subnet", + }, + "instanceB7CCE687": { + "DependsOn": [ + "instanceInstanceRoleF436EE92", + ], + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "", + }, + ], + }, + "IamInstanceProfile": { + "Ref": "instanceInstanceProfile931F14E3", + }, + "ImageId": { + "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestal2023amikernel61x8664C96584B6F00A464EAD1953AFF4B05118Parameter", + }, + "InstanceType": "t3.large", + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "instanceInstanceSecurityGroup725C795D", + "GroupId", + ], + }, + ], + "SubnetId": { + "Ref": "VpcrdsSubnet1SubnetC2926CEA", + }, + "Tags": [ + { + "Key": "Name", + "Value": "integ-testing-eicendpoint/instance", + }, + ], + "UserData": { + "Fn::Base64": "#!/bin/bash", + }, + }, + "Type": "AWS::EC2::Instance", + }, + "instanceInstanceProfile931F14E3": { + "Properties": { + "Roles": [ + { + "Ref": "instanceInstanceRoleF436EE92", + }, + ], + }, + "Type": "AWS::IAM::InstanceProfile", + }, + "instanceInstanceRoleF436EE92": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com", + }, + }, + ], + "Version": "2012-10-17", + }, + "Tags": [ + { + "Key": "Name", + "Value": "integ-testing-eicendpoint/instance", + }, + ], + }, + "Type": "AWS::IAM::Role", + }, + "instanceInstanceSecurityGroup725C795D": { + "Properties": { + "GroupDescription": "integ-testing-eicendpoint/instance/InstanceSecurityGroup", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1", + }, + ], + "SecurityGroupIngress": [ + { + "CidrIp": { + "Fn::GetAtt": [ + "Vpc8378EB38", + "CidrBlock", + ], + }, + "Description": { + "Fn::Join": [ + "", + [ + "from ", + { + "Fn::GetAtt": [ + "Vpc8378EB38", + "CidrBlock", + ], + }, + ":ALL TRAFFIC", + ], + ], + }, + "IpProtocol": "-1", + }, + ], + "Tags": [ + { + "Key": "Name", + "Value": "integ-testing-eicendpoint/instance", + }, + ], + "VpcId": { + "Ref": "Vpc8378EB38", + }, + }, + "Type": "AWS::EC2::SecurityGroup", + }, + }, + "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.", + }, + ], + }, + }, +} +`; From 336d7d7891a3fa51e07d167320b908168179f5df Mon Sep 17 00:00:00 2001 From: Michael Kaiser Date: Fri, 18 Apr 2025 09:03:26 -0500 Subject: [PATCH 3/6] Fix: Update normalized testing --- .../ec2-instance-connect-endpoint/API.md | 229 ++++++++++++++++++ .../package.json | 2 +- .../test/__snapshots__/app.test.ts.snap | 10 +- .../test/app.test.ts | 1 + 4 files changed, 236 insertions(+), 6 deletions(-) create mode 100644 typescript/ec2-instance-connect-endpoint/API.md diff --git a/typescript/ec2-instance-connect-endpoint/API.md b/typescript/ec2-instance-connect-endpoint/API.md new file mode 100644 index 0000000000..4b9668e588 --- /dev/null +++ b/typescript/ec2-instance-connect-endpoint/API.md @@ -0,0 +1,229 @@ +# InstanceConnectEndpoint + +`InstanceConnectEndpoint` is a sample AWS CDK construct that allows you to build [EC2 Instance Connect Endpoint](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-using-eice.html) in your VPC with CDK custom resource. + +This sample is generated with [projen](https://github.com/projen/projen) `awscdk-construct` project type so you can reference the `.projenrc.ts` and create your own CDK construct library like this with very little modification. + +# sample + +```ts +// create an EIC Endpoint in an isolated subnet +new InstanceConnectEndpoint(stack, 'EICEndpoint', { + subnet: vpc.isolatedSubnets[0], + preserveClientIp: false, +}); +``` + +See full sample at [integ.default.ts](./src/integ.default.ts). + +# deploy the default integration test + +```sh +$ cd typescripts/ec2-instance-connect-endpoint +$ yarn install +# configure your AWS CLI +$ npx cdk diff +$ npx cdk deploy +``` + +On deployment completed, check the instance ID from the output: + +``` +integ-testing-eicendpoint.InstanceId = i-01d0f0c7ca761ff29 +``` + +Now, connect it with AWS CLI: + +```sh +$ aws ec2-instance-connect ssh --instance-id i-01d0f0c7ca761ff29 +``` + +# `awssh` + +Alternatively, you can create an `awssh` alias like this: + +```sh +alias awssh='aws ec2-instance-connect ssh --instance-id' +``` + +Now, you can just `awssh` into any ec2 instance behind the endpoint. + +```sh +$ awssh i-01d0f0c7ca761ff29 +``` + +# run the tests + +```sh +$ yarn test +``` + +# clean up + +```sh +$ npx cdk destroy +``` +# API Reference + +## Constructs + +### InstanceConnectEndpoint + +#### Initializers + +```typescript +import { InstanceConnectEndpoint } from 'ec2-instance-connect-endpoint' + +new InstanceConnectEndpoint(scope: Construct, id: string, props: InstanceConnectEndpointProps) +``` + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| scope | constructs.Construct | *No description.* | +| id | string | *No description.* | +| props | InstanceConnectEndpointProps | *No description.* | + +--- + +##### `scope`Required + +- *Type:* constructs.Construct + +--- + +##### `id`Required + +- *Type:* string + +--- + +##### `props`Required + +- *Type:* InstanceConnectEndpointProps + +--- + +#### Methods + +| **Name** | **Description** | +| --- | --- | +| toString | Returns a string representation of this construct. | + +--- + +##### `toString` + +```typescript +public toString(): string +``` + +Returns a string representation of this construct. + +#### Static Functions + +| **Name** | **Description** | +| --- | --- | +| isConstruct | Checks if `x` is a construct. | + +--- + +##### ~~`isConstruct`~~ + +```typescript +import { InstanceConnectEndpoint } from 'ec2-instance-connect-endpoint' + +InstanceConnectEndpoint.isConstruct(x: any) +``` + +Checks if `x` is a construct. + +###### `x`Required + +- *Type:* any + +Any object. + +--- + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| node | constructs.Node | The tree node. | + +--- + +##### `node`Required + +```typescript +public readonly node: Node; +``` + +- *Type:* constructs.Node + +The tree node. + +--- + + +## Structs + +### InstanceConnectEndpointProps + +#### Initializer + +```typescript +import { InstanceConnectEndpointProps } from 'ec2-instance-connect-endpoint' + +const instanceConnectEndpointProps: InstanceConnectEndpointProps = { ... } +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| subnet | aws-cdk-lib.aws_ec2.ISubnet | EC2 subnet for this endpoint. | +| preserveClientIp | boolean | whether to enable the preserveClientIp. | +| securityGroup | aws-cdk-lib.aws_ec2.ISecurityGroup[] | Security groups of this endpoint. | + +--- + +##### `subnet`Required + +```typescript +public readonly subnet: ISubnet; +``` + +- *Type:* aws-cdk-lib.aws_ec2.ISubnet + +EC2 subnet for this endpoint. + +--- + +##### `preserveClientIp`Optional + +```typescript +public readonly preserveClientIp: boolean; +``` + +- *Type:* boolean +- *Default:* true + +whether to enable the preserveClientIp. + +--- + +##### `securityGroup`Optional + +```typescript +public readonly securityGroup: ISecurityGroup[]; +``` + +- *Type:* aws-cdk-lib.aws_ec2.ISecurityGroup[] + +Security groups of this endpoint. + +--- + + + diff --git a/typescript/ec2-instance-connect-endpoint/package.json b/typescript/ec2-instance-connect-endpoint/package.json index 674ddd6562..262ef7792e 100644 --- a/typescript/ec2-instance-connect-endpoint/package.json +++ b/typescript/ec2-instance-connect-endpoint/package.json @@ -4,6 +4,7 @@ "repository": { "type": "git", "url": "https://github.com/aws-samples/aws-cdk-examples.git" + }, "bin": { "ec2-instance-connect-endpoint": "bin/app.js" }, @@ -13,7 +14,6 @@ "test": "jest", "cdk": "cdk" }, - }, "devDependencies": { "@types/jest": "^29.5.14", "@types/node": "^16", diff --git a/typescript/ec2-instance-connect-endpoint/test/__snapshots__/app.test.ts.snap b/typescript/ec2-instance-connect-endpoint/test/__snapshots__/app.test.ts.snap index 66e619f290..5f0bc8eb81 100644 --- a/typescript/ec2-instance-connect-endpoint/test/__snapshots__/app.test.ts.snap +++ b/typescript/ec2-instance-connect-endpoint/test/__snapshots__/app.test.ts.snap @@ -172,7 +172,7 @@ exports[`default validation 1`] = ` "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", }, - "S3Key": "bdc104ed9cab1b5b6421713c8155f0b753380595356f710400609664d3635eca.zip", + "S3Key": "NORMALIZED_ASSET_HASH.zip", }, "Description": "AWS CDK resource provider framework - isComplete (integ-testing-eicendpoint/EICEndpoint/Provider)", "Environment": { @@ -340,7 +340,7 @@ exports[`default validation 1`] = ` "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", }, - "S3Key": "bdc104ed9cab1b5b6421713c8155f0b753380595356f710400609664d3635eca.zip", + "S3Key": "NORMALIZED_ASSET_HASH.zip", }, "Description": "AWS CDK resource provider framework - onEvent (integ-testing-eicendpoint/EICEndpoint/Provider)", "Environment": { @@ -518,7 +518,7 @@ exports[`default validation 1`] = ` "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", }, - "S3Key": "bdc104ed9cab1b5b6421713c8155f0b753380595356f710400609664d3635eca.zip", + "S3Key": "NORMALIZED_ASSET_HASH.zip", }, "Description": "AWS CDK resource provider framework - onTimeout (integ-testing-eicendpoint/EICEndpoint/Provider)", "Environment": { @@ -994,7 +994,7 @@ exports[`default validation 1`] = ` "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", }, - "S3Key": "580e7199f29d3a4ba21264e35db2b99e791d0c4bc8d5e635d4bc85da65923391.zip", + "S3Key": "NORMALIZED_ASSET_HASH.zip", }, "Handler": "index.is_complete", "MemorySize": 256, @@ -1019,7 +1019,7 @@ exports[`default validation 1`] = ` "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", }, - "S3Key": "580e7199f29d3a4ba21264e35db2b99e791d0c4bc8d5e635d4bc85da65923391.zip", + "S3Key": "NORMALIZED_ASSET_HASH.zip", }, "Handler": "index.on_event", "MemorySize": 256, diff --git a/typescript/ec2-instance-connect-endpoint/test/app.test.ts b/typescript/ec2-instance-connect-endpoint/test/app.test.ts index 5a27e84927..9dc86c7291 100644 --- a/typescript/ec2-instance-connect-endpoint/test/app.test.ts +++ b/typescript/ec2-instance-connect-endpoint/test/app.test.ts @@ -1,5 +1,6 @@ import { Template } from 'aws-cdk-lib/assertions'; import { IntegTesting } from '../bin/app'; +import { normalizeTemplate } from '../../test-utils/normalize-template'; test('default validation', () => { const integ = new IntegTesting(); From 2b236c33483853df6065f3a06eaaf02d332b8da7 Mon Sep 17 00:00:00 2001 From: Michael Kaiser Date: Fri, 18 Apr 2025 09:13:51 -0500 Subject: [PATCH 4/6] Fix: Rootdir path --- .../ec2-instance-connect-endpoint/tsconfig.json | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/typescript/ec2-instance-connect-endpoint/tsconfig.json b/typescript/ec2-instance-connect-endpoint/tsconfig.json index e20b2b4957..7f8f927e0f 100644 --- a/typescript/ec2-instance-connect-endpoint/tsconfig.json +++ b/typescript/ec2-instance-connect-endpoint/tsconfig.json @@ -23,10 +23,19 @@ "./node_modules/@types" ], "outDir": "lib", - "rootDir": "." + "rootDir": "../..", + "baseUrl": ".", + "paths": { + "../../test-utils/*": ["../../test-utils/*"] + } }, "exclude": [ "node_modules", - "cdk.out" + "cdk.out", + "lib" + ], + "include": [ + "**/*.ts", + "../../test-utils/**/*.ts" ] } From 0bba4d1d3469d2aea45c46c11e2711deb00a46ae Mon Sep 17 00:00:00 2001 From: Michael Kaiser Date: Fri, 18 Apr 2025 09:17:56 -0500 Subject: [PATCH 5/6] doc:Update snapshot testing for tsconfig changes --- SNAPSHOT_TESTING.md | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/SNAPSHOT_TESTING.md b/SNAPSHOT_TESTING.md index 26c80caca7..d3d5d13142 100644 --- a/SNAPSHOT_TESTING.md +++ b/SNAPSHOT_TESTING.md @@ -53,6 +53,92 @@ After adding the normalization to your tests, update your snapshots: npm test -- -u ``` +### 4. TypeScript Configuration for External Utilities + +When referencing the normalize-template utility from outside your project directory, you may need to update your `tsconfig.json` file: + +```json +{ + "compilerOptions": { + // Other options... + "rootDir": "../..", + "baseUrl": ".", + "paths": { + "../../test-utils/*": ["../../test-utils/*"] + } + }, + "exclude": [ + "node_modules", + "cdk.out", + "lib" + ], + "include": [ + "**/*.ts", + "../../test-utils/**/*.ts" + ] +} +``` + +Key changes: +- Set `rootDir` to include parent directories containing shared utilities +- Add `paths` mapping to resolve imports correctly +- Include the external utility files in the `include` section + +This configuration allows TypeScript to compile files that reference utilities outside your project directory. + +## What Gets Normalized + +The utility currently normalizes: + +1. **S3 Asset Keys**: Replaces asset hashes in S3Key properties + - Pattern with extension: `[64 hex chars].zip` → `NORMALIZED_ASSET_HASH.zip` + - Pattern without extension: `[64 hex chars]` → `NORMALIZED_ASSET_HASH` + +2. **Docker Image Digests**: Replaces image digests + - Pattern: `sha256:[digest]` → `NORMALIZED_IMAGE_DIGEST` + +## Adding New Test Files + +When creating new test files that use snapshot testing: + +1. Import the normalization utility +2. Apply it to your template before comparing with snapshots +3. Update your snapshots with the `-u` flag + +## Extending the Utility + +If you encounter other environment-specific values that need normalization, you can extend the utility at `typescript/test-utils/normalize-template.ts`. + +Example of adding a new normalization rule: + +```typescript +// Inside the normalizeValues function +if (key === 'NewPropertyToNormalize' && typeof obj[key] === 'string' && /pattern-to-match/.test(obj[key])) { + obj[key] = 'NORMALIZED_VALUE'; +} +``` + +## Troubleshooting + +If you're still seeing snapshot test failures: + +1. **Check for new patterns**: There might be new types of asset hashes or environment-specific values that need normalization +2. **Verify imports**: Make sure you're importing and using the utility correctly +3. **Check snapshot updates**: Ensure you've updated your snapshots after adding normalization +4. **TypeScript configuration**: If you're getting compilation errors about files outside your project directory, check your tsconfig.json settings + +## Best Practices + +1. **Always normalize before snapshot comparison**: This ensures consistent results +2. **Update snapshots deliberately**: Only use the `-u` flag when you expect changes +3. **Review snapshot diffs**: When updating snapshots, review the changes to ensure they're expected +4. **Keep the utility updated**: As new patterns emerge, add them to the normalization utility + +## Additional Resources + +- [Jest Snapshot Testing Documentation](https://jestjs.io/docs/snapshot-testing) +- [AWS CDK Testing Documentation](https://docs.aws.amazon.com/cdk/v2/guide/testing.html) + ## What Gets Normalized The utility currently normalizes: From 7112ffbf085ddb9d8004e4fc7ddab440bb472dd0 Mon Sep 17 00:00:00 2001 From: Michael Kaiser Date: Fri, 18 Apr 2025 09:26:52 -0500 Subject: [PATCH 6/6] Chore: Update cdk libs --- typescript/ec2-instance-connect-endpoint/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typescript/ec2-instance-connect-endpoint/package.json b/typescript/ec2-instance-connect-endpoint/package.json index 262ef7792e..373cdab559 100644 --- a/typescript/ec2-instance-connect-endpoint/package.json +++ b/typescript/ec2-instance-connect-endpoint/package.json @@ -17,14 +17,14 @@ "devDependencies": { "@types/jest": "^29.5.14", "@types/node": "^16", - "aws-cdk": "2.85.0", + "aws-cdk": "2.1007.0", "jest": "^29.5.0", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", "typescript": "^5.1.6" }, "dependencies": { - "aws-cdk-lib": "2.85.0", + "aws-cdk-lib": "2.189.1", "constructs": "10.0.5" } }