@aws-solutions-constructs/resources 2.46.0 → 2.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +3 -5
- package/.jsii +125 -18
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/lib/key-policy-updater-custom-resource/index.d.ts +30 -0
- package/lib/key-policy-updater-custom-resource/index.js +127 -0
- package/lib/key-policy-updater.d.ts +29 -0
- package/lib/key-policy-updater.js +67 -0
- package/lib/template-writer-custom-resource/index.d.ts +21 -0
- package/lib/template-writer-custom-resource/index.js +65 -0
- package/lib/template-writer.d.ts +1 -1
- package/lib/template-writer.js +3 -16
- package/lib/utils.d.ts +14 -0
- package/lib/utils.js +34 -0
- package/package.json +13 -5
- package/test/integ.template-writer-from-asset.expected.json +1 -1
- package/test/integ.template-writer-from-large-asset.expected.json +1 -1
- package/test/kms-key-policy-updater.test.d.ts +13 -0
- package/test/kms-key-policy-updater.test.js +238 -0
- package/test/template-writer.test.js +2 -2
- package/lib/template-writer-custom-resource/index.mjs +0 -73
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
|
|
5
|
-
* with the License. A copy of the License is located at
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
|
|
10
|
-
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
|
|
11
|
-
* and limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { S3Client, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3";
|
|
15
|
-
import * as crypto from 'crypto';
|
|
16
|
-
|
|
17
|
-
const s3Client = new S3Client({ region: process.env.REGION });
|
|
18
|
-
|
|
19
|
-
export const handler = async (event, context) => {
|
|
20
|
-
let status = 'SUCCESS';
|
|
21
|
-
let responseData = {};
|
|
22
|
-
|
|
23
|
-
// These are the standard Create/Update/Delete custom resource request types defined here:
|
|
24
|
-
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requesttypes.html
|
|
25
|
-
if (event.RequestType === 'Create' || event.RequestType === 'Update') {
|
|
26
|
-
try {
|
|
27
|
-
const templateValues = JSON.parse(event.ResourceProperties.TemplateValues).templateValues;
|
|
28
|
-
const templateInputBucket = event.ResourceProperties.TemplateInputBucket;
|
|
29
|
-
const templateInputKey = event.ResourceProperties.TemplateInputKey;
|
|
30
|
-
const templateOutputBucket = event.ResourceProperties.TemplateOutputBucket;
|
|
31
|
-
const templateOutputKey = crypto.randomBytes(32).toString('hex');
|
|
32
|
-
|
|
33
|
-
const getObjectResponse = await s3Client.send(new GetObjectCommand({
|
|
34
|
-
Bucket: templateInputBucket,
|
|
35
|
-
Key: templateInputKey
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
let template = await getObjectResponse.Body?.transformToString();
|
|
39
|
-
|
|
40
|
-
templateValues.forEach(templateValue => {
|
|
41
|
-
template = template?.replace(
|
|
42
|
-
new RegExp(templateValue.id, 'g'),
|
|
43
|
-
templateValue.value
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
await s3Client.send(new PutObjectCommand({
|
|
48
|
-
Bucket: templateOutputBucket,
|
|
49
|
-
Key: templateOutputKey,
|
|
50
|
-
Body: template
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
responseData = {
|
|
54
|
-
TemplateOutputKey: templateOutputKey
|
|
55
|
-
};
|
|
56
|
-
} catch (err) {
|
|
57
|
-
status = 'FAILED';
|
|
58
|
-
responseData = {
|
|
59
|
-
Error: err
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
Status: status,
|
|
66
|
-
Reason: JSON.stringify(responseData),
|
|
67
|
-
PhysicalResourceId: event.PhysicalResourceId ?? context.logStreamName,
|
|
68
|
-
StackId: event.StackId,
|
|
69
|
-
RequestId: event.RequestId,
|
|
70
|
-
LogicalResourceId: event.LogicalResourceId,
|
|
71
|
-
Data: responseData,
|
|
72
|
-
};
|
|
73
|
-
};
|