From ce52c7e1ac939dc2f9f08cb29fad0f2dc9714445 Mon Sep 17 00:00:00 2001 From: Michael Sambol Date: Fri, 8 Mar 2024 16:53:39 -0600 Subject: [PATCH 1/3] feat(opensearchservice): cold storage option (#29387) Closes #29366. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- ...efaultTestDeployAssert73848187.assets.json | 19 +++ ...aultTestDeployAssert73848187.template.json | 36 ++++ ...k-integ-opensearch-coldstorage.assets.json | 19 +++ ...integ-opensearch-coldstorage.template.json | 77 +++++++++ .../cdk.out | 1 + .../integ.json | 13 ++ .../manifest.json | 113 +++++++++++++ .../tree.json | 156 ++++++++++++++++++ .../test/integ.opensearch.coldstorage.ts | 30 ++++ .../aws-opensearchservice/README.md | 16 ++ .../aws-opensearchservice/lib/domain.ts | 16 ++ .../aws-opensearchservice/test/domain.test.ts | 73 ++++++++ 12 files changed, 569 insertions(+) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk-integ-opensearch-coldstorage.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk-integ-opensearch-coldstorage.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.assets.json new file mode 100644 index 0000000000000..62fc21e18c8b7 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.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-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.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-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk-integ-opensearch-coldstorage.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk-integ-opensearch-coldstorage.assets.json new file mode 100644 index 0000000000000..df1a2c07acf36 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk-integ-opensearch-coldstorage.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "7e6878d5f7b4ebd9d43019b5cc477889a4c2650e5094c35aca78e0131f9e7120": { + "source": { + "path": "cdk-integ-opensearch-coldstorage.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "7e6878d5f7b4ebd9d43019b5cc477889a4c2650e5094c35aca78e0131f9e7120.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-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk-integ-opensearch-coldstorage.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk-integ-opensearch-coldstorage.template.json new file mode 100644 index 0000000000000..1d9de13be4899 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk-integ-opensearch-coldstorage.template.json @@ -0,0 +1,77 @@ +{ + "Resources": { + "Domain66AC69E0": { + "Type": "AWS::OpenSearchService::Domain", + "Properties": { + "ClusterConfig": { + "ColdStorageOptions": { + "Enabled": true + }, + "DedicatedMasterCount": 2, + "DedicatedMasterEnabled": true, + "DedicatedMasterType": "r5.large.search", + "InstanceCount": 1, + "InstanceType": "r5.large.search", + "MultiAZWithStandbyEnabled": false, + "WarmCount": 2, + "WarmEnabled": true, + "WarmType": "ultrawarm1.medium.search", + "ZoneAwarenessEnabled": false + }, + "DomainEndpointOptions": { + "EnforceHTTPS": false, + "TLSSecurityPolicy": "Policy-Min-TLS-1-0-2019-07" + }, + "EBSOptions": { + "EBSEnabled": true, + "VolumeSize": 10, + "VolumeType": "gp2" + }, + "EncryptionAtRestOptions": { + "Enabled": false + }, + "EngineVersion": "Elasticsearch_7.10", + "LogPublishingOptions": {}, + "NodeToNodeEncryptionOptions": { + "Enabled": false + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + } + }, + "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-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/integ.json new file mode 100644 index 0000000000000..a9af5e245b578 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/integ.json @@ -0,0 +1,13 @@ +{ + "version": "36.0.0", + "testCases": { + "OpenSearchColdStorageInteg/DefaultTest": { + "stacks": [ + "cdk-integ-opensearch-coldstorage" + ], + "diffAssets": true, + "assertionStack": "OpenSearchColdStorageInteg/DefaultTest/DeployAssert", + "assertionStackName": "OpenSearchColdStorageIntegDefaultTestDeployAssert73848187" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/manifest.json new file mode 100644 index 0000000000000..72a73308a1cd9 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/manifest.json @@ -0,0 +1,113 @@ +{ + "version": "36.0.0", + "artifacts": { + "cdk-integ-opensearch-coldstorage.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "cdk-integ-opensearch-coldstorage.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "cdk-integ-opensearch-coldstorage": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "cdk-integ-opensearch-coldstorage.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}/7e6878d5f7b4ebd9d43019b5cc477889a4c2650e5094c35aca78e0131f9e7120.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "cdk-integ-opensearch-coldstorage.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": [ + "cdk-integ-opensearch-coldstorage.assets" + ], + "metadata": { + "/cdk-integ-opensearch-coldstorage/Domain/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Domain66AC69E0" + } + ], + "/cdk-integ-opensearch-coldstorage/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/cdk-integ-opensearch-coldstorage/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "cdk-integ-opensearch-coldstorage" + }, + "OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "OpenSearchColdStorageIntegDefaultTestDeployAssert73848187": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.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": [ + "OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.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": [ + "OpenSearchColdStorageIntegDefaultTestDeployAssert73848187.assets" + ], + "metadata": { + "/OpenSearchColdStorageInteg/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/OpenSearchColdStorageInteg/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "OpenSearchColdStorageInteg/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-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/tree.json new file mode 100644 index 0000000000000..79f397f06eb2f --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.js.snapshot/tree.json @@ -0,0 +1,156 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "cdk-integ-opensearch-coldstorage": { + "id": "cdk-integ-opensearch-coldstorage", + "path": "cdk-integ-opensearch-coldstorage", + "children": { + "Domain": { + "id": "Domain", + "path": "cdk-integ-opensearch-coldstorage/Domain", + "children": { + "Resource": { + "id": "Resource", + "path": "cdk-integ-opensearch-coldstorage/Domain/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::OpenSearchService::Domain", + "aws:cdk:cloudformation:props": { + "clusterConfig": { + "coldStorageOptions": { + "enabled": true + }, + "dedicatedMasterEnabled": true, + "dedicatedMasterCount": 2, + "dedicatedMasterType": "r5.large.search", + "instanceCount": 1, + "instanceType": "r5.large.search", + "multiAzWithStandbyEnabled": false, + "warmEnabled": true, + "warmCount": 2, + "warmType": "ultrawarm1.medium.search", + "zoneAwarenessEnabled": false + }, + "domainEndpointOptions": { + "enforceHttps": false, + "tlsSecurityPolicy": "Policy-Min-TLS-1-0-2019-07" + }, + "ebsOptions": { + "ebsEnabled": true, + "volumeSize": 10, + "volumeType": "gp2" + }, + "encryptionAtRestOptions": { + "enabled": false + }, + "engineVersion": "Elasticsearch_7.10", + "logPublishingOptions": {}, + "nodeToNodeEncryptionOptions": { + "enabled": false + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "cdk-integ-opensearch-coldstorage/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "cdk-integ-opensearch-coldstorage/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "OpenSearchColdStorageInteg": { + "id": "OpenSearchColdStorageInteg", + "path": "OpenSearchColdStorageInteg", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "OpenSearchColdStorageInteg/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "OpenSearchColdStorageInteg/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "OpenSearchColdStorageInteg/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "OpenSearchColdStorageInteg/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "OpenSearchColdStorageInteg/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.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.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.ts new file mode 100644 index 0000000000000..ced1ac000523f --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.coldstorage.ts @@ -0,0 +1,30 @@ +import { App, RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib'; +import { Construct } from 'constructs'; +import * as opensearch from 'aws-cdk-lib/aws-opensearchservice'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; + +class TestStack extends Stack { + constructor(scope: Construct, id: string, props?: StackProps) { + super(scope, id, props); + + new opensearch.Domain(this, 'Domain', { + removalPolicy: RemovalPolicy.DESTROY, + version: opensearch.EngineVersion.ELASTICSEARCH_7_10, + capacity: { + masterNodes: 2, + warmNodes: 2, + multiAzWithStandbyEnabled: false, + }, + coldStorageEnabled: true, + }); + } +} + +const app = new App(); +const stack = new TestStack(app, 'cdk-integ-opensearch-coldstorage'); + +new IntegTest(app, 'OpenSearchColdStorageInteg', { + testCases: [stack], + diffAssets: true, +}); +app.synth(); diff --git a/packages/aws-cdk-lib/aws-opensearchservice/README.md b/packages/aws-cdk-lib/aws-opensearchservice/README.md index f4450a3934987..e24f2df325e25 100644 --- a/packages/aws-cdk-lib/aws-opensearchservice/README.md +++ b/packages/aws-cdk-lib/aws-opensearchservice/README.md @@ -397,6 +397,22 @@ const domain = new Domain(this, 'Domain', { }); ``` +## Cold storage + +Cold storage can be enabled on the domain. You must enable UltraWarm storage to enable cold storage. + +```ts +const domain = new Domain(this, 'Domain', { + version: EngineVersion.OPENSEARCH_1_0, + capacity: { + masterNodes: 2, + warmNodes: 2, + warmInstanceType: 'ultrawarm1.medium.search', + }, + coldStorageEnabled: true, +}); +``` + ## Custom endpoint Custom endpoints can be configured to reach the domain under a custom domain name. diff --git a/packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts b/packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts index d9ae89e914459..be08ca406d525 100644 --- a/packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts +++ b/packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts @@ -687,6 +687,15 @@ export interface DomainProps { * @default - false */ readonly suppressLogsResourcePolicy?: boolean; + + /** + * Whether to enable or disable cold storage on the domain. You must enable UltraWarm storage to enable cold storage. + * + * @see https://docs.aws.amazon.com/opensearch-service/latest/developerguide/cold-storage.html + * + * @default - undefined + */ + readonly coldStorageEnabled?: boolean; } /** @@ -1700,6 +1709,10 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable { throw new Error('Dedicated master node is required when UltraWarm storage is enabled.'); } + if (props.coldStorageEnabled && !warmEnabled) { + throw new Error('You must enable UltraWarm storage to enable cold storage.'); + } + let cfnVpcOptions: CfnDomain.VPCOptionsProperty | undefined; if (securityGroups && subnets) { @@ -1834,6 +1847,9 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable { domainName: this.physicalName, engineVersion: props.version.version, clusterConfig: { + coldStorageOptions: props.coldStorageEnabled !== undefined ? { + enabled: props.coldStorageEnabled, + } : undefined, dedicatedMasterEnabled, dedicatedMasterCount: dedicatedMasterEnabled ? dedicatedMasterCount diff --git a/packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts b/packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts index 7c941c784a572..4c10e6868b70c 100644 --- a/packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts +++ b/packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts @@ -1995,6 +1995,79 @@ each(testedOpenSearchVersions).describe('custom error responses', (engineVersion })).toThrow(/UltraWarm requires Elasticsearch version 6\.8 or later or OpenSearch version 1.0 or later/); }); + test('enabling cold storage without ultrawarm throws an error', () => { + expect(() => new Domain(stack, 'Domain', { + version: engineVersion, + coldStorageEnabled: true, + })).toThrow(/You must enable UltraWarm storage to enable cold storage./); + }); + + test('can enable cold storage', () => { + new Domain(stack, 'Domain', { + version: engineVersion, + capacity: { + masterNodes: 2, + warmNodes: 2, + }, + coldStorageEnabled: true, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { + ClusterConfig: { + DedicatedMasterEnabled: true, + WarmEnabled: true, + WarmCount: 2, + WarmType: 'ultrawarm1.medium.search', + ColdStorageOptions: { + Enabled: true, + }, + }, + }); + }); + + test('can disable cold storage', () => { + new Domain(stack, 'Domain', { + version: engineVersion, + capacity: { + masterNodes: 2, + warmNodes: 2, + }, + coldStorageEnabled: false, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { + ClusterConfig: { + DedicatedMasterEnabled: true, + WarmEnabled: true, + WarmCount: 2, + WarmType: 'ultrawarm1.medium.search', + ColdStorageOptions: { + Enabled: false, + }, + }, + }); + }); + + test('cold storage default is undefined', () => { + new Domain(stack, 'Domain', { + version: engineVersion, + capacity: { + masterNodes: 2, + warmNodes: 2, + }, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', { + ClusterConfig: { + DedicatedMasterEnabled: true, + WarmEnabled: true, + WarmCount: 2, + WarmType: 'ultrawarm1.medium.search', + ColdStorageOptions: Match.absent(), + }, + }); + }); + test('error when t2 or t3 instance types are specified with UltramWarm enabled', () => { const error = /T2 and T3 instance types do not support UltraWarm storage/; expect(() => new Domain(stack, 'Domain1', { From baaa50c73ae3a88d606b62349736ef1180dcf1ad Mon Sep 17 00:00:00 2001 From: Dan Halperin Date: Fri, 8 Mar 2024 15:21:57 -0800 Subject: [PATCH 2/3] feat(ec2): add APPCONFIG and APPCONFIGDATA to InterfaceVpcEndpointAwsService (#29408) These are newly available as of [2023-12-11 (announcement)](https://aws.amazon.com/about-aws/whats-new/2023/12/aws-appconfig-supports-privatelink/) with endpoint names taken from the [AWS PrivateLink docs](https://docs.aws.amazon.com/vpc/latest/privatelink/aws-services-privatelink-support.html). Testing: tried them in our environment. This PR is modeled after https://github.com/aws/aws-cdk/pull/21401/files, but the package.json code seems to be gone, and I didn't duplicate the verbose no-op tests that the string is the string. ### Reason for this change New VPC Endpoints exist now. ### Description of changes Add the missing constants. ### Description of how you validated changes Tested `appconfigdata` in our account. ### Checklist - [X/N/A] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* Yes, and I am an AWS employee. --- packages/aws-cdk-lib/aws-ec2/lib/vpc-endpoint.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ec2/lib/vpc-endpoint.ts b/packages/aws-cdk-lib/aws-ec2/lib/vpc-endpoint.ts index f30a1a40b7b5e..3ba1f09f81dfa 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/vpc-endpoint.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/vpc-endpoint.ts @@ -268,6 +268,8 @@ export class InterfaceVpcEndpointAwsService implements IInterfaceVpcEndpointServ public static readonly APP_RUNNER = new InterfaceVpcEndpointAwsService('apprunner'); public static readonly APP_RUNNER_REQUESTS = new InterfaceVpcEndpointAwsService('apprunner.requests'); public static readonly APP_SYNC = new InterfaceVpcEndpointAwsService('appsync-api'); + public static readonly APPCONFIG = new InterfaceVpcEndpointAwsService('appconfig'); + public static readonly APPCONFIGDATA = new InterfaceVpcEndpointAwsService('appconfigdata'); public static readonly APPLICATION_AUTOSCALING = new InterfaceVpcEndpointAwsService('application-autoscaling'); public static readonly APPLICATION_MIGRATION_SERVICE = new InterfaceVpcEndpointAwsService('mgn'); public static readonly APPSTREAM_API = new InterfaceVpcEndpointAwsService('appstream.api'); From 919d16ff611ee01495ae2cb4c646c4e27378b3e3 Mon Sep 17 00:00:00 2001 From: Vandita Patidar Date: Fri, 8 Mar 2024 15:49:51 -0800 Subject: [PATCH 3/3] fix(lambda-nodejs): fixing esbuildArgs to take in account re-specified keys (#29167) ### Issue # (if applicable) Closes #25385 ### Reason for this change This PR fixes a bug in CDK where CDK does not take into account re-specified keys while doing bundling. The CLI supports flags in one of three forms: `--foo`, `--foo=bar`, or `--foo:bar`. However, the `--foo:bar` form was not initially supported. With `--foo:bar`, users can now specify flags that have multiple values and can be re-specified multiple times. ### Description of changes The code has a list of keys that can be re-specified multiple times. While assigning the flags it checks whether the key is among the list of re-specified keys, if yes, it specifies the flag with `:`. ### Description of how you validated changes The PR includes unit test and integration test both to validate the changes. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- ...efaultTestDeployAssertB1F5AACE.assets.json | 19 ++ ...aultTestDeployAssertB1F5AACE.template.json | 36 +++ .../index.js | 2 + .../index.js.map | 7 + ...nteg-lambda-nodejs-esbuildArgs.assets.json | 32 +++ ...eg-lambda-nodejs-esbuildArgs.template.json | 96 ++++++++ .../integ.esbuildArgs.js.snapshot/cdk.out | 1 + .../integ.esbuildArgs.js.snapshot/integ.json | 12 + .../manifest.json | 119 +++++++++ .../integ.esbuildArgs.js.snapshot/tree.json | 226 ++++++++++++++++++ .../test/integ.esbuildArgs.ts | 33 +++ .../aws-lambda-nodejs/lib/bundling.ts | 3 + .../aws-lambda-nodejs/test/bundling.test.ts | 3 +- 13 files changed, 588 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/asset.5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a/index.js create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/asset.5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a/index.js.map create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk-integ-lambda-nodejs-esbuildArgs.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk-integ-lambda-nodejs-esbuildArgs.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.assets.json new file mode 100644 index 0000000000000..69106eb8cc21d --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.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-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.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-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/asset.5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a/index.js b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/asset.5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a/index.js new file mode 100644 index 0000000000000..1786193f55a08 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/asset.5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a/index.js @@ -0,0 +1,2 @@ +"use strict";var u=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var l=(r,n)=>{for(var o in n)u(r,o,{get:n[o],enumerable:!0})},d=(r,n,o,m)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of i(n))!c.call(r,e)&&e!==o&&u(r,e,{get:()=>n[e],enumerable:!(m=b(n,e))||m.enumerable});return r};var f=r=>d(u({},"__esModule",{value:!0}),r);var a={};l(a,{handler:()=>p});module.exports=f(a);function t(r,n){return r*n}async function p(){console.log(t(3,4))}0&&(module.exports={handler}); +//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vaW50ZWctaGFuZGxlcnMvdHMtaGFuZGxlci50cyIsICIuLi8uLi9pbnRlZy1oYW5kbGVycy91dGlsLnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJpbXBvcnQgeyBtdWx0IH0gZnJvbSAnLi91dGlsJztcblxuZXhwb3J0IGFzeW5jIGZ1bmN0aW9uIGhhbmRsZXIoKTogUHJvbWlzZTx2b2lkPiB7XG4gIGNvbnNvbGUubG9nKG11bHQoMywgNCkpOyAvLyBlc2xpbnQtZGlzYWJsZS1saW5lIG5vLWNvbnNvbGVcbn1cbiIsICJleHBvcnQgZnVuY3Rpb24gYWRkKGE6IG51bWJlciwgYjogbnVtYmVyKTogbnVtYmVyIHtcbiAgcmV0dXJuIGEgKyBiO1xufVxuXG5leHBvcnQgZnVuY3Rpb24gbXVsdChhOiBudW1iZXIsIGI6IG51bWJlcik6IG51bWJlciB7XG4gIHJldHVybiBhICogYjtcbn1cbiJdLAogICJtYXBwaW5ncyI6ICJ5YUFBQSxJQUFBQSxFQUFBLEdBQUFDLEVBQUFELEVBQUEsYUFBQUUsSUFBQSxlQUFBQyxFQUFBSCxHQ0lPLFNBQVNJLEVBQUtDLEVBQVdDLEVBQW1CLENBQ2pELE9BQU9ELEVBQUlDLENBQ2IsQ0RKQSxlQUFzQkMsR0FBeUIsQ0FDN0MsUUFBUSxJQUFJQyxFQUFLLEVBQUcsQ0FBQyxDQUFDLENBQ3hCIiwKICAibmFtZXMiOiBbInRzX2hhbmRsZXJfZXhwb3J0cyIsICJfX2V4cG9ydCIsICJoYW5kbGVyIiwgIl9fdG9Db21tb25KUyIsICJtdWx0IiwgImEiLCAiYiIsICJoYW5kbGVyIiwgIm11bHQiXQp9Cg== diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/asset.5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a/index.js.map b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/asset.5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a/index.js.map new file mode 100644 index 0000000000000..554571d62acc3 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/asset.5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a/index.js.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["../../integ-handlers/ts-handler.ts", "../../integ-handlers/util.ts"], + "sourcesContent": ["import { mult } from './util';\n\nexport async function handler(): Promise {\n console.log(mult(3, 4)); // eslint-disable-line no-console\n}\n", "export function add(a: number, b: number): number {\n return a + b;\n}\n\nexport function mult(a: number, b: number): number {\n return a * b;\n}\n"], + "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GCIO,SAASI,EAAKC,EAAWC,EAAmB,CACjD,OAAOD,EAAIC,CACb,CDJA,eAAsBC,GAAyB,CAC7C,QAAQ,IAAIC,EAAK,EAAG,CAAC,CAAC,CACxB", + "names": ["ts_handler_exports", "__export", "handler", "__toCommonJS", "mult", "a", "b", "handler", "mult"] +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk-integ-lambda-nodejs-esbuildArgs.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk-integ-lambda-nodejs-esbuildArgs.assets.json new file mode 100644 index 0000000000000..0abeec51f0770 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk-integ-lambda-nodejs-esbuildArgs.assets.json @@ -0,0 +1,32 @@ +{ + "version": "36.0.0", + "files": { + "5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a": { + "source": { + "path": "asset.5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a", + "packaging": "zip" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a.zip", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + }, + "9320d4394a32bcea756c96f8d004743eeb0d3bfe844a15888b0ddf9ece9e9976": { + "source": { + "path": "cdk-integ-lambda-nodejs-esbuildArgs.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "9320d4394a32bcea756c96f8d004743eeb0d3bfe844a15888b0ddf9ece9e9976.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-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk-integ-lambda-nodejs-esbuildArgs.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk-integ-lambda-nodejs-esbuildArgs.template.json new file mode 100644 index 0000000000000..5039173b96b3a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk-integ-lambda-nodejs-esbuildArgs.template.json @@ -0,0 +1,96 @@ +{ + "Resources": { + "tshandlerServiceRole8876B8E7": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "tshandler4E1C6929": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "S3Key": "5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a.zip" + }, + "Environment": { + "Variables": { + "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" + } + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "tshandlerServiceRole8876B8E7", + "Arn" + ] + }, + "Runtime": "nodejs18.x" + }, + "DependsOn": [ + "tshandlerServiceRole8876B8E7" + ] + } + }, + "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-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/integ.json new file mode 100644 index 0000000000000..649607bf6993a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.0", + "testCases": { + "LambdaNodeJsEsbuildArgsInteg/DefaultTest": { + "stacks": [ + "cdk-integ-lambda-nodejs-esbuildArgs" + ], + "assertionStack": "LambdaNodeJsEsbuildArgsInteg/DefaultTest/DeployAssert", + "assertionStackName": "LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/manifest.json new file mode 100644 index 0000000000000..38140bde2e23e --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/manifest.json @@ -0,0 +1,119 @@ +{ + "version": "36.0.0", + "artifacts": { + "cdk-integ-lambda-nodejs-esbuildArgs.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "cdk-integ-lambda-nodejs-esbuildArgs.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "cdk-integ-lambda-nodejs-esbuildArgs": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "cdk-integ-lambda-nodejs-esbuildArgs.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}/9320d4394a32bcea756c96f8d004743eeb0d3bfe844a15888b0ddf9ece9e9976.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "cdk-integ-lambda-nodejs-esbuildArgs.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": [ + "cdk-integ-lambda-nodejs-esbuildArgs.assets" + ], + "metadata": { + "/cdk-integ-lambda-nodejs-esbuildArgs/ts-handler/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "tshandlerServiceRole8876B8E7" + } + ], + "/cdk-integ-lambda-nodejs-esbuildArgs/ts-handler/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "tshandler4E1C6929" + } + ], + "/cdk-integ-lambda-nodejs-esbuildArgs/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/cdk-integ-lambda-nodejs-esbuildArgs/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "cdk-integ-lambda-nodejs-esbuildArgs" + }, + "LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.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": [ + "LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.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": [ + "LambdaNodeJsEsbuildArgsIntegDefaultTestDeployAssertB1F5AACE.assets" + ], + "metadata": { + "/LambdaNodeJsEsbuildArgsInteg/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/LambdaNodeJsEsbuildArgsInteg/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "LambdaNodeJsEsbuildArgsInteg/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-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/tree.json new file mode 100644 index 0000000000000..38f8a64e86a7d --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.js.snapshot/tree.json @@ -0,0 +1,226 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "cdk-integ-lambda-nodejs-esbuildArgs": { + "id": "cdk-integ-lambda-nodejs-esbuildArgs", + "path": "cdk-integ-lambda-nodejs-esbuildArgs", + "children": { + "ts-handler": { + "id": "ts-handler", + "path": "cdk-integ-lambda-nodejs-esbuildArgs/ts-handler", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "cdk-integ-lambda-nodejs-esbuildArgs/ts-handler/ServiceRole", + "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "cdk-integ-lambda-nodejs-esbuildArgs/ts-handler/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "cdk-integ-lambda-nodejs-esbuildArgs/ts-handler/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Code": { + "id": "Code", + "path": "cdk-integ-lambda-nodejs-esbuildArgs/ts-handler/Code", + "children": { + "Stage": { + "id": "Stage", + "path": "cdk-integ-lambda-nodejs-esbuildArgs/ts-handler/Code/Stage", + "constructInfo": { + "fqn": "aws-cdk-lib.AssetStaging", + "version": "0.0.0" + } + }, + "AssetBucket": { + "id": "AssetBucket", + "path": "cdk-integ-lambda-nodejs-esbuildArgs/ts-handler/Code/AssetBucket", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_s3.BucketBase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_s3_assets.Asset", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "cdk-integ-lambda-nodejs-esbuildArgs/ts-handler/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "s3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "s3Key": "5017e4b2e278e32bc634202d075b7ed8961b0d784f75450f7918a6a4f6f7df4a.zip" + }, + "environment": { + "variables": { + "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" + } + }, + "handler": "index.handler", + "role": { + "Fn::GetAtt": [ + "tshandlerServiceRole8876B8E7", + "Arn" + ] + }, + "runtime": "nodejs18.x" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnFunction", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda_nodejs.NodejsFunction", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "cdk-integ-lambda-nodejs-esbuildArgs/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "cdk-integ-lambda-nodejs-esbuildArgs/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "LambdaNodeJsEsbuildArgsInteg": { + "id": "LambdaNodeJsEsbuildArgsInteg", + "path": "LambdaNodeJsEsbuildArgsInteg", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "LambdaNodeJsEsbuildArgsInteg/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "LambdaNodeJsEsbuildArgsInteg/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "LambdaNodeJsEsbuildArgsInteg/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "LambdaNodeJsEsbuildArgsInteg/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "LambdaNodeJsEsbuildArgsInteg/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.3.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.ts new file mode 100644 index 0000000000000..9a2f913547692 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.esbuildArgs.ts @@ -0,0 +1,33 @@ +import * as path from 'path'; +import { App, Stack, StackProps } from 'aws-cdk-lib'; +import { Construct } from 'constructs'; +import * as lambda from 'aws-cdk-lib/aws-lambda-nodejs'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import { STANDARD_NODEJS_RUNTIME } from '../../config'; + +class TestStack extends Stack { + constructor(scope: Construct, id: string, props?: StackProps) { + super(scope, id, props); + + new lambda.NodejsFunction(this, 'ts-handler', { + entry: path.join(__dirname, 'integ-handlers/ts-handler.ts'), + runtime: STANDARD_NODEJS_RUNTIME, + bundling: { + minify: true, + sourceMap: true, + sourceMapMode: lambda.SourceMapMode.BOTH, + esbuildArgs: { + '--log-limit': '0', + '--out-extension': '.js=.mjs', + }, + }, + }); + } +} + +const app = new App(); +const stack = new TestStack(app, 'cdk-integ-lambda-nodejs-esbuildArgs'); + +new IntegTest(app, 'LambdaNodeJsEsbuildArgsInteg', { + testCases: [stack], +}); diff --git a/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts b/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts index 8a6389ab08d37..b75b3285d9c68 100644 --- a/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts +++ b/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts @@ -420,10 +420,13 @@ function toTarget(runtime: Runtime): string { function toCliArgs(esbuildArgs: { [key: string]: string | boolean }): string { const args = new Array(); + const reSpecifiedKeys = ['--alias', '--drop', '--pure', '--log-override', '--out-extension']; for (const [key, value] of Object.entries(esbuildArgs)) { if (value === true || value === '') { args.push(key); + } else if (reSpecifiedKeys.includes(key)) { + args.push(`${key}:"${value}"`); } else if (value) { args.push(`${key}="${value}"`); } diff --git a/packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts b/packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts index c168335046ed2..a7cfacbeb78b2 100644 --- a/packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts +++ b/packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts @@ -245,6 +245,7 @@ test('esbuild bundling with esbuild options', () => { '--resolve-extensions': '.ts,.js', '--splitting': true, '--keep-names': '', + '--out-extension': '.js=.mjs', }, }); @@ -264,7 +265,7 @@ test('esbuild bundling with esbuild options', () => { '--log-level=silent --keep-names --tsconfig=/asset-input/lib/custom-tsconfig.ts', '--metafile=/asset-output/index.meta.json --banner:js="/* comments */" --footer:js="/* comments */"', '--main-fields=module,main --inject:./my-shim.js', - '--log-limit="0" --resolve-extensions=".ts,.js" --splitting --keep-names', + '--log-limit="0" --resolve-extensions=".ts,.js" --splitting --keep-names --out-extension:".js=.mjs"', ].join(' '), ], }),