Skip to content

Commit 399b6bb

Browse files
fix: all aws-cdk-lib custom resources now use Node18 (#26212)
Migrates all of the custom resources within aws-cdk-lib to use Node18 runtime. Also changes all handler code for these CRs to use aws-sdk v3 instead of v2 since Node18 lambda runtime ships sdk v3 in the environment. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1520d77 commit 399b6bb

File tree

1,580 files changed

+454175
-62895
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,580 files changed

+454175
-62895
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
const aws = require('aws-sdk');
3+
const { ACM, waitUntilCertificateValidated } = require('@aws-sdk/client-acm');
4+
const { Route53, waitUntilResourceRecordSetsChanged } = require('@aws-sdk/client-route-53');
45

56
const defaultSleep = function (ms) {
67
return new Promise(resolve => setTimeout(resolve, ms));
@@ -74,12 +75,12 @@ let report = function (event, context, responseStatus, physicalResourceId, respo
7475
*/
7576
const addTags = async function(certificateArn, region, tags) {
7677
const result = Array.from(Object.entries(tags)).map(([Key, Value]) => ({ Key, Value }))
77-
const acm = new aws.ACM({ region });
78+
const acm = new ACM({ region });
7879

7980
await acm.addTagsToCertificate({
8081
CertificateArn: certificateArn,
8182
Tags: result,
82-
}).promise();
83+
});
8384
}
8485

8586
/**
@@ -96,12 +97,8 @@ const addTags = async function(certificateArn, region, tags) {
9697
*/
9798
const requestCertificate = async function (requestId, domainName, subjectAlternativeNames, certificateTransparencyLoggingPreference, hostedZoneId, region, route53Endpoint) {
9899
const crypto = require('crypto');
99-
const acm = new aws.ACM({ region });
100-
const route53 = route53Endpoint ? new aws.Route53({ endpoint: route53Endpoint }) : new aws.Route53();
101-
if (waiter) {
102-
// Used by the test suite, since waiters aren't mockable yet
103-
route53.waitFor = acm.waitFor = waiter;
104-
}
100+
const acm = new ACM({ region });
101+
const route53 = route53Endpoint ? new Route53({ endpoint: route53Endpoint }) : new Route53();
105102

106103
console.log(`Requesting certificate for ${domainName}`);
107104

@@ -113,7 +110,7 @@ const requestCertificate = async function (requestId, domainName, subjectAlterna
113110
},
114111
IdempotencyToken: crypto.createHash('sha256').update(requestId).digest('hex').slice(0, 32),
115112
ValidationMethod: 'DNS'
116-
}).promise();
113+
});
117114

118115
console.log(`Certificate ARN: ${reqCertResponse.CertificateArn}`);
119116

@@ -123,7 +120,7 @@ const requestCertificate = async function (requestId, domainName, subjectAlterna
123120
for (let attempt = 0; attempt < maxAttempts && !records.length; attempt++) {
124121
const { Certificate } = await acm.describeCertificate({
125122
CertificateArn: reqCertResponse.CertificateArn
126-
}).promise();
123+
});
127124

128125
records = getDomainValidationRecords(Certificate);
129126
if (!records.length) {
@@ -143,14 +140,13 @@ const requestCertificate = async function (requestId, domainName, subjectAlterna
143140
await commitRoute53Records(route53, records, hostedZoneId);
144141

145142
console.log('Waiting for validation...');
146-
await acm.waitFor('certificateValidated', {
147-
// Wait up to 9 minutes and 30 seconds
148-
$waiter: {
149-
delay: 30,
150-
maxAttempts: 19
151-
},
143+
await waitUntilCertificateValidated({
144+
client: acm,
145+
maxAttempts: 19,
146+
delay: 30,
147+
}, {
152148
CertificateArn: reqCertResponse.CertificateArn
153-
}).promise();
149+
})
154150

155151
return reqCertResponse.CertificateArn;
156152
};
@@ -162,12 +158,8 @@ const requestCertificate = async function (requestId, domainName, subjectAlterna
162158
* @param {string} arn The certificate ARN
163159
*/
164160
const deleteCertificate = async function (arn, region, hostedZoneId, route53Endpoint, cleanupRecords) {
165-
const acm = new aws.ACM({ region });
166-
const route53 = route53Endpoint ? new aws.Route53({ endpoint: route53Endpoint }) : new aws.Route53();
167-
if (waiter) {
168-
// Used by the test suite, since waiters aren't mockable yet
169-
route53.waitFor = acm.waitFor = waiter;
170-
}
161+
const acm = new ACM({ region });
162+
const route53 = route53Endpoint ? new Route53({ endpoint: route53Endpoint }) : new Route53();
171163

172164
try {
173165
console.log(`Waiting for certificate ${arn} to become unused`);
@@ -177,7 +169,7 @@ const deleteCertificate = async function (arn, region, hostedZoneId, route53Endp
177169
for (let attempt = 0; attempt < maxAttempts; attempt++) {
178170
const { Certificate } = await acm.describeCertificate({
179171
CertificateArn: arn
180-
}).promise();
172+
});
181173

182174
if (cleanupRecords) {
183175
records = getDomainValidationRecords(Certificate);
@@ -206,7 +198,7 @@ const deleteCertificate = async function (arn, region, hostedZoneId, route53Endp
206198

207199
await acm.deleteCertificate({
208200
CertificateArn: arn
209-
}).promise();
201+
});
210202

211203
if (cleanupRecords) {
212204
console.log(`Deleting ${records.length} DNS records from zone ${hostedZoneId}:`);
@@ -268,17 +260,16 @@ async function commitRoute53Records(route53, records, hostedZoneId, action = 'UP
268260
}),
269261
},
270262
HostedZoneId: hostedZoneId
271-
}).promise();
263+
});
272264

273265
console.log('Waiting for DNS records to commit...');
274-
await route53.waitFor('resourceRecordSetsChanged', {
275-
// Wait up to 5 minutes
276-
$waiter: {
277-
delay: 30,
278-
maxAttempts: 10
279-
},
280-
Id: changeBatch.ChangeInfo.Id
281-
}).promise();
266+
await waitUntilResourceRecordSetsChanged({
267+
client: route53,
268+
delay: 30,
269+
maxAttempts: 10,
270+
}, {
271+
Id: changeBatch.ChangeInfo.Id,
272+
});
282273
}
283274

284275
/**
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"31.0.0"}
1+
{"version":"32.0.0"}

packages/@aws-cdk-testing/framework-integ/test/aws-certificatemanager/test/integ.dns-validated-certificate.js.snapshot/integ-dns-validated-certificate.assets.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
2-
"version": "31.0.0",
2+
"version": "32.0.0",
33
"files": {
4-
"ef671dfd26b6dde1f73a4325587504813605a928622ebc466f4d0de6a0f3b672": {
4+
"fb83c347f6a5e3099f787c17ce0845a70a81fd83fdc20eb2e4e1cb01961a8774": {
55
"source": {
6-
"path": "asset.ef671dfd26b6dde1f73a4325587504813605a928622ebc466f4d0de6a0f3b672",
6+
"path": "asset.fb83c347f6a5e3099f787c17ce0845a70a81fd83fdc20eb2e4e1cb01961a8774",
77
"packaging": "zip"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "ef671dfd26b6dde1f73a4325587504813605a928622ebc466f4d0de6a0f3b672.zip",
12+
"objectKey": "fb83c347f6a5e3099f787c17ce0845a70a81fd83fdc20eb2e4e1cb01961a8774.zip",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}
1616
},
17-
"1827f8b3dae882f9c01e1f56ed8c5cecc88fee8a12a8fd410bc83dd7835622bd": {
17+
"14e61dd74326fa816025a92898ba02959dd7100dccf670dec73afb2e3b13b29c": {
1818
"source": {
1919
"path": "integ-dns-validated-certificate.template.json",
2020
"packaging": "file"
2121
},
2222
"destinations": {
2323
"current_account-current_region": {
2424
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
25-
"objectKey": "1827f8b3dae882f9c01e1f56ed8c5cecc88fee8a12a8fd410bc83dd7835622bd.json",
25+
"objectKey": "14e61dd74326fa816025a92898ba02959dd7100dccf670dec73afb2e3b13b29c.json",
2626
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
2727
}
2828
}

packages/@aws-cdk-testing/framework-integ/test/aws-certificatemanager/test/integ.dns-validated-certificate.js.snapshot/integ-dns-validated-certificate.template.json

+2-113
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"S3Bucket": {
9797
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
9898
},
99-
"S3Key": "ef671dfd26b6dde1f73a4325587504813605a928622ebc466f4d0de6a0f3b672.zip"
99+
"S3Key": "fb83c347f6a5e3099f787c17ce0845a70a81fd83fdc20eb2e4e1cb01961a8774.zip"
100100
},
101101
"Role": {
102102
"Fn::GetAtt": [
@@ -105,15 +105,7 @@
105105
]
106106
},
107107
"Handler": "index.certificateRequestHandler",
108-
"Runtime": {
109-
"Fn::FindInMap": [
110-
"DefaultCrNodeVersionMap",
111-
{
112-
"Ref": "AWS::Region"
113-
},
114-
"value"
115-
]
116-
},
108+
"Runtime": "nodejs18.x",
117109
"Timeout": 900
118110
},
119111
"DependsOn": [
@@ -138,109 +130,6 @@
138130
"DeletionPolicy": "Delete"
139131
}
140132
},
141-
"Mappings": {
142-
"DefaultCrNodeVersionMap": {
143-
"af-south-1": {
144-
"value": "nodejs16.x"
145-
},
146-
"ap-east-1": {
147-
"value": "nodejs16.x"
148-
},
149-
"ap-northeast-1": {
150-
"value": "nodejs16.x"
151-
},
152-
"ap-northeast-2": {
153-
"value": "nodejs16.x"
154-
},
155-
"ap-northeast-3": {
156-
"value": "nodejs16.x"
157-
},
158-
"ap-south-1": {
159-
"value": "nodejs16.x"
160-
},
161-
"ap-south-2": {
162-
"value": "nodejs16.x"
163-
},
164-
"ap-southeast-1": {
165-
"value": "nodejs16.x"
166-
},
167-
"ap-southeast-2": {
168-
"value": "nodejs16.x"
169-
},
170-
"ap-southeast-3": {
171-
"value": "nodejs16.x"
172-
},
173-
"ca-central-1": {
174-
"value": "nodejs16.x"
175-
},
176-
"cn-north-1": {
177-
"value": "nodejs16.x"
178-
},
179-
"cn-northwest-1": {
180-
"value": "nodejs16.x"
181-
},
182-
"eu-central-1": {
183-
"value": "nodejs16.x"
184-
},
185-
"eu-central-2": {
186-
"value": "nodejs16.x"
187-
},
188-
"eu-north-1": {
189-
"value": "nodejs16.x"
190-
},
191-
"eu-south-1": {
192-
"value": "nodejs16.x"
193-
},
194-
"eu-south-2": {
195-
"value": "nodejs16.x"
196-
},
197-
"eu-west-1": {
198-
"value": "nodejs16.x"
199-
},
200-
"eu-west-2": {
201-
"value": "nodejs16.x"
202-
},
203-
"eu-west-3": {
204-
"value": "nodejs16.x"
205-
},
206-
"me-central-1": {
207-
"value": "nodejs16.x"
208-
},
209-
"me-south-1": {
210-
"value": "nodejs16.x"
211-
},
212-
"sa-east-1": {
213-
"value": "nodejs16.x"
214-
},
215-
"us-east-1": {
216-
"value": "nodejs16.x"
217-
},
218-
"us-east-2": {
219-
"value": "nodejs16.x"
220-
},
221-
"us-gov-east-1": {
222-
"value": "nodejs16.x"
223-
},
224-
"us-gov-west-1": {
225-
"value": "nodejs16.x"
226-
},
227-
"us-iso-east-1": {
228-
"value": "nodejs14.x"
229-
},
230-
"us-iso-west-1": {
231-
"value": "nodejs14.x"
232-
},
233-
"us-isob-east-1": {
234-
"value": "nodejs14.x"
235-
},
236-
"us-west-1": {
237-
"value": "nodejs16.x"
238-
},
239-
"us-west-2": {
240-
"value": "nodejs16.x"
241-
}
242-
}
243-
},
244133
"Outputs": {
245134
"CertificateArn": {
246135
"Value": {

packages/@aws-cdk-testing/framework-integ/test/aws-certificatemanager/test/integ.dns-validated-certificate.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"enableLookups": true,
3-
"version": "31.0.0",
3+
"version": "32.0.0",
44
"testCases": {
55
"integ-test/DefaultTest": {
66
"stacks": [

packages/@aws-cdk-testing/framework-integ/test/aws-certificatemanager/test/integ.dns-validated-certificate.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "31.0.0",
2+
"version": "32.0.0",
33
"files": {
44
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
55
"source": {

packages/@aws-cdk-testing/framework-integ/test/aws-certificatemanager/test/integ.dns-validated-certificate.js.snapshot/manifest.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "31.0.0",
2+
"version": "32.0.0",
33
"artifacts": {
44
"integ-dns-validated-certificate.assets": {
55
"type": "cdk:asset-manifest",
@@ -17,7 +17,7 @@
1717
"validateOnSynth": false,
1818
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
1919
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
20-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/1827f8b3dae882f9c01e1f56ed8c5cecc88fee8a12a8fd410bc83dd7835622bd.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/14e61dd74326fa816025a92898ba02959dd7100dccf670dec73afb2e3b13b29c.json",
2121
"requiresBootstrapStackVersion": 6,
2222
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2323
"additionalDependencies": [
@@ -57,12 +57,6 @@
5757
"data": "CertificateCertificateRequestorResource2890C6B7"
5858
}
5959
],
60-
"/integ-dns-validated-certificate/DefaultCrNodeVersionMap": [
61-
{
62-
"type": "aws:cdk:logicalId",
63-
"data": "DefaultCrNodeVersionMap"
64-
}
65-
],
6660
"/integ-dns-validated-certificate/CertificateArn": [
6761
{
6862
"type": "aws:cdk:logicalId",

0 commit comments

Comments
 (0)