Skip to content

Commit 1b4e3a4

Browse files
committed
fix(cfnspec): v101.0.0 introduced specific types on several types that previously were typed as json (#23448)
This PR reverts all changes where a type changed from `Json` to a specific type in CfnSpec v101.0.0. See 3951f09 - [x] 000_AWS_Backup.json - [x] 000_AWS_CloudFormation.json - [x] 000_AWS_CodeGuruProfiler.json - [x] 000_AWS_Config.json - [x] 000_AWS_Connect.json - [x] 000_AWS_DataBrew.json - [x] 000_AWS_EC2.json - [x] 000_AWS_ECR.json - [x] 000_AWS_ElastiCache.json - [x] 000_AWS_FIS.json - [x] 000_AWS_Forecast.json - [x] 000_AWS_GreengrassV2.json - [x] 000_AWS_IoT.json - [ ] ~000_AWS_IoTAnalytics.json~ - [x] 000_AWS_IoTCoreDeviceAdvisor.json - [ ] ~000_AWS_IoTFleetWise.json~ - [x] 000_AWS_IoTSiteWise.json - [x] 000_AWS_IoTTwinMaker.json - [x] 000_AWS_IoTWireless.json - [ ] ~000_AWS_LakeFormation.json~ - [x] 000_AWS_Lex.json - [x] 000_AWS_LookoutEquipment.json - [ ] ~000_AWS_Macie.json~ - [x] 000_AWS_MemoryDB.json - [x] 000_AWS_Personalize.json - [x] 000_AWS_Redshift.json - [x] 000_AWS_Route53.json - [x] 000_AWS_S3.json - [x] 000_AWS_S3ObjectLambda.json - [x] 000_AWS_S3Outposts.json - [x] 000_AWS_SageMaker.json - [ ] ~000_AWS_Scheduler.json~ - [ ] ~000_AWS_StepFunctions.json~ - [ ] ~000_AWS_Timestream.json~ - [x] 000_AWS_Transfer.json - [x] 000_AWS_WAFv2.json ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1485f48 commit 1b4e3a4

File tree

19 files changed

+1261
-476
lines changed

19 files changed

+1261
-476
lines changed

packages/@aws-cdk/aws-ec2/lib/vpc-flow-logs.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ export class FlowLog extends FlowLogBase {
676676
}
677677

678678
const flowLog = new CfnFlowLog(this, 'FlowLog', {
679-
destinationOptions: renderDestinationOptions(destinationConfig.destinationOptions),
679+
destinationOptions: destinationConfig.destinationOptions,
680680
deliverLogsPermissionArn: this.iamRole ? this.iamRole.roleArn : undefined,
681681
logDestinationType: destinationConfig.logDestinationType,
682682
logGroupName: this.logGroup ? this.logGroup.logGroupName : undefined,
@@ -694,13 +694,3 @@ export class FlowLog extends FlowLogBase {
694694
this.node.defaultChild = flowLog;
695695
}
696696
}
697-
698-
function renderDestinationOptions(opts: DestinationOptions | undefined): CfnFlowLog.DestinationOptionsProperty | undefined {
699-
if (opts === undefined) { return undefined; }
700-
701-
return {
702-
fileFormat: opts.fileFormat ?? 'plain-text',
703-
hiveCompatiblePartitions: opts.hiveCompatiblePartitions ?? false,
704-
perHourPartition: opts.perHourPartition ?? false,
705-
};
706-
}

packages/@aws-cdk/aws-ec2/test/integ.vpc-flow-logs.js.snapshot/FlowLogsDefaultTestDeployAssert6AFD1854.assets.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
22
"version": "21.0.0",
33
"files": {
4-
"3074b79e05e7b98930b6449e01baa3e68b32ecff86328933c2542f7b7fe6fdac": {
4+
"b54b99043c35bd080b9d9d1afce31e3541cf15b679799ba980ed40c837dcb03b": {
55
"source": {
6-
"path": "asset.3074b79e05e7b98930b6449e01baa3e68b32ecff86328933c2542f7b7fe6fdac.bundle",
6+
"path": "asset.b54b99043c35bd080b9d9d1afce31e3541cf15b679799ba980ed40c837dcb03b.bundle",
77
"packaging": "zip"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "3074b79e05e7b98930b6449e01baa3e68b32ecff86328933c2542f7b7fe6fdac.zip",
12+
"objectKey": "b54b99043c35bd080b9d9d1afce31e3541cf15b679799ba980ed40c837dcb03b.zip",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}
1616
},
17-
"dd951509b1e22484b40a66a661cb8cebce3087b8cb381e3dcf02e641e5eb08cd": {
17+
"1dcf759cd2c8928f5b1acfbf439f1751e25367a5ac61ba5e640ff8b78fdf89f7": {
1818
"source": {
1919
"path": "FlowLogsDefaultTestDeployAssert6AFD1854.template.json",
2020
"packaging": "file"
2121
},
2222
"destinations": {
2323
"current_account-current_region": {
2424
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
25-
"objectKey": "dd951509b1e22484b40a66a661cb8cebce3087b8cb381e3dcf02e641e5eb08cd.json",
25+
"objectKey": "1dcf759cd2c8928f5b1acfbf439f1751e25367a5ac61ba5e640ff8b78fdf89f7.json",
2626
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
2727
}
2828
}

packages/@aws-cdk/aws-ec2/test/integ.vpc-flow-logs.js.snapshot/FlowLogsDefaultTestDeployAssert6AFD1854.template.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232
},
3333
"flattenResponse": "false",
34-
"salt": "1668693953813"
34+
"salt": "1666810703150"
3535
},
3636
"UpdateReplacePolicy": "Delete",
3737
"DeletionPolicy": "Delete"
@@ -115,7 +115,7 @@
115115
"S3Bucket": {
116116
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
117117
},
118-
"S3Key": "3074b79e05e7b98930b6449e01baa3e68b32ecff86328933c2542f7b7fe6fdac.zip"
118+
"S3Key": "b54b99043c35bd080b9d9d1afce31e3541cf15b679799ba980ed40c837dcb03b.zip"
119119
},
120120
"Timeout": 120,
121121
"Handler": "index.handler",

packages/@aws-cdk/aws-ec2/test/integ.vpc-flow-logs.js.snapshot/FlowLogsFeatureFlag.assets.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"version": "21.0.0",
33
"files": {
4-
"8f4f8db3ea3ad2d5f5678275c75dce7d9b67b46d8df7d92c62913bdc5a03cd3f": {
4+
"2db53e096625b4b167fb15dd7bdc246692b381f45e28c509614fef7d41c20bc9": {
55
"source": {
66
"path": "FlowLogsFeatureFlag.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "8f4f8db3ea3ad2d5f5678275c75dce7d9b67b46d8df7d92c62913bdc5a03cd3f.json",
12+
"objectKey": "2db53e096625b4b167fb15dd7bdc246692b381f45e28c509614fef7d41c20bc9.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk/aws-ec2/test/integ.vpc-flow-logs.js.snapshot/FlowLogsFeatureFlag.template.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@
524524
"Ref": "VPCB9E5F0B4"
525525
},
526526
"ResourceType": "VPC",
527+
"TrafficType": "ALL",
527528
"LogDestination": {
528529
"Fn::GetAtt": [
529530
"VPCFlowLogsS3BucketFB7DC2BE",
@@ -536,8 +537,7 @@
536537
"Key": "Name",
537538
"Value": "FlowLogsFeatureFlag/VPC"
538539
}
539-
],
540-
"TrafficType": "ALL"
540+
]
541541
}
542542
},
543543
"VPCFlowLogsS3WithDestinationOptionsBucket1B7AC456": {
@@ -673,10 +673,11 @@
673673
"Ref": "VPCB9E5F0B4"
674674
},
675675
"ResourceType": "VPC",
676+
"TrafficType": "ALL",
676677
"DestinationOptions": {
677-
"FileFormat": "plain-text",
678-
"HiveCompatiblePartitions": true,
679-
"PerHourPartition": false
678+
"fileFormat": "plain-text",
679+
"perHourPartition": false,
680+
"hiveCompatiblePartitions": true
680681
},
681682
"LogDestination": {
682683
"Fn::GetAtt": [
@@ -690,8 +691,7 @@
690691
"Key": "Name",
691692
"Value": "FlowLogsFeatureFlag/VPC"
692693
}
693-
],
694-
"TrafficType": "ALL"
694+
]
695695
}
696696
},
697697
"FlowLogsInstanceInstanceSecurityGroupF61782E0": {

packages/@aws-cdk/aws-ec2/test/integ.vpc-flow-logs.js.snapshot/FlowLogsTestStack.assets.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
22
"version": "21.0.0",
33
"files": {
4-
"33e2651435a0d472a75c1e033c9832b21321d9e56711926b04c5705e5f63874c": {
4+
"bb426cfb5fed5237e5928f871893b243ddf86a591a592b558bd29f60e28bad9d": {
55
"source": {
6-
"path": "asset.33e2651435a0d472a75c1e033c9832b21321d9e56711926b04c5705e5f63874c",
6+
"path": "asset.bb426cfb5fed5237e5928f871893b243ddf86a591a592b558bd29f60e28bad9d",
77
"packaging": "zip"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "33e2651435a0d472a75c1e033c9832b21321d9e56711926b04c5705e5f63874c.zip",
12+
"objectKey": "bb426cfb5fed5237e5928f871893b243ddf86a591a592b558bd29f60e28bad9d.zip",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}
1616
},
17-
"23955aa16c5d59106d93ecce9cedd43aa5782fbf23bb2ef8549b2119345a6f79": {
17+
"2090a74d484bc155b48d7511b99e4921b8f55e488c3fe1500cffede0cdfd33b7": {
1818
"source": {
1919
"path": "FlowLogsTestStack.template.json",
2020
"packaging": "file"
2121
},
2222
"destinations": {
2323
"current_account-current_region": {
2424
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
25-
"objectKey": "23955aa16c5d59106d93ecce9cedd43aa5782fbf23bb2ef8549b2119345a6f79.json",
25+
"objectKey": "2090a74d484bc155b48d7511b99e4921b8f55e488c3fe1500cffede0cdfd33b7.json",
2626
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
2727
}
2828
}

packages/@aws-cdk/aws-ec2/test/integ.vpc-flow-logs.js.snapshot/FlowLogsTestStack.template.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@
524524
"Ref": "VPCB9E5F0B4"
525525
},
526526
"ResourceType": "VPC",
527+
"TrafficType": "ALL",
527528
"LogDestination": {
528529
"Fn::GetAtt": [
529530
"VPCFlowLogsS3BucketFB7DC2BE",
@@ -536,8 +537,7 @@
536537
"Key": "Name",
537538
"Value": "FlowLogsTestStack/VPC"
538539
}
539-
],
540-
"TrafficType": "ALL"
540+
]
541541
}
542542
},
543543
"VPCFlowLogsS3KeyPrefixFlowLogB57F1746": {
@@ -547,6 +547,7 @@
547547
"Ref": "VPCB9E5F0B4"
548548
},
549549
"ResourceType": "VPC",
550+
"TrafficType": "ALL",
550551
"LogDestination": {
551552
"Fn::Join": [
552553
"",
@@ -567,8 +568,7 @@
567568
"Key": "Name",
568569
"Value": "FlowLogsTestStack/VPC"
569570
}
570-
],
571-
"TrafficType": "ALL"
571+
]
572572
}
573573
},
574574
"FlowLogsCWIAMRole017AD736": {
@@ -643,6 +643,7 @@
643643
"Ref": "VPCB9E5F0B4"
644644
},
645645
"ResourceType": "VPC",
646+
"TrafficType": "ALL",
646647
"DeliverLogsPermissionArn": {
647648
"Fn::GetAtt": [
648649
"FlowLogsCWIAMRole017AD736",
@@ -652,8 +653,7 @@
652653
"LogDestinationType": "cloud-watch-logs",
653654
"LogGroupName": {
654655
"Ref": "FlowLogsCWLogGroup0398E8F8"
655-
},
656-
"TrafficType": "ALL"
656+
}
657657
}
658658
},
659659
"Bucket83908E77": {
@@ -888,7 +888,7 @@
888888
"S3Bucket": {
889889
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
890890
},
891-
"S3Key": "33e2651435a0d472a75c1e033c9832b21321d9e56711926b04c5705e5f63874c.zip"
891+
"S3Key": "bb426cfb5fed5237e5928f871893b243ddf86a591a592b558bd29f60e28bad9d.zip"
892892
},
893893
"Timeout": 900,
894894
"MemorySize": 128,

packages/@aws-cdk/aws-ec2/test/integ.vpc-flow-logs.js.snapshot/asset.33e2651435a0d472a75c1e033c9832b21321d9e56711926b04c5705e5f63874c/__entrypoint__.js

-144
This file was deleted.

packages/@aws-cdk/aws-ec2/test/integ.vpc-flow-logs.js.snapshot/asset.60767da3831353fede3cfe92efef10580a600592dec8ccbb06c051e95b9c1b26/__entrypoint__.js

+118
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare function handler(event: AWSLambda.CloudFormationCustomResourceEvent): Promise<void>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
import { S3 } from 'aws-sdk';
3+
4+
const AUTO_DELETE_OBJECTS_TAG = 'aws-cdk:auto-delete-objects';
5+
6+
const s3 = new S3();
7+
8+
export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent) {
9+
switch (event.RequestType) {
10+
case 'Create':
11+
return;
12+
case 'Update':
13+
return onUpdate(event);
14+
case 'Delete':
15+
return onDelete(event.ResourceProperties?.BucketName);
16+
}
17+
}
18+
19+
async function onUpdate(event: AWSLambda.CloudFormationCustomResourceEvent) {
20+
const updateEvent = event as AWSLambda.CloudFormationCustomResourceUpdateEvent;
21+
const oldBucketName = updateEvent.OldResourceProperties?.BucketName;
22+
const newBucketName = updateEvent.ResourceProperties?.BucketName;
23+
const bucketNameHasChanged = newBucketName != null && oldBucketName != null && newBucketName !== oldBucketName;
24+
25+
/* If the name of the bucket has changed, CloudFormation will try to delete the bucket
26+
and create a new one with the new name. So we have to delete the contents of the
27+
bucket so that this operation does not fail. */
28+
if (bucketNameHasChanged) {
29+
return onDelete(oldBucketName);
30+
}
31+
}
32+
33+
/**
34+
* Recursively delete all items in the bucket
35+
*
36+
* @param bucketName the bucket name
37+
*/
38+
async function emptyBucket(bucketName: string) {
39+
const listedObjects = await s3.listObjectVersions({ Bucket: bucketName }).promise();
40+
const contents = [...listedObjects.Versions ?? [], ...listedObjects.DeleteMarkers ?? []];
41+
if (contents.length === 0) {
42+
return;
43+
}
44+
45+
const records = contents.map((record: any) => ({ Key: record.Key, VersionId: record.VersionId }));
46+
await s3.deleteObjects({ Bucket: bucketName, Delete: { Objects: records } }).promise();
47+
48+
if (listedObjects?.IsTruncated) {
49+
await emptyBucket(bucketName);
50+
}
51+
}
52+
53+
async function onDelete(bucketName?: string) {
54+
if (!bucketName) {
55+
throw new Error('No BucketName was provided.');
56+
}
57+
if (!await isBucketTaggedForDeletion(bucketName)) {
58+
process.stdout.write(`Bucket does not have '${AUTO_DELETE_OBJECTS_TAG}' tag, skipping cleaning.\n`);
59+
return;
60+
}
61+
try {
62+
await emptyBucket(bucketName);
63+
} catch (e) {
64+
if (e.code !== 'NoSuchBucket') {
65+
throw e;
66+
}
67+
// Bucket doesn't exist. Ignoring
68+
}
69+
}
70+
71+
/**
72+
* The bucket will only be tagged for deletion if it's being deleted in the same
73+
* deployment as this Custom Resource.
74+
*
75+
* If the Custom Resource is every deleted before the bucket, it must be because
76+
* `autoDeleteObjects` has been switched to false, in which case the tag would have
77+
* been removed before we get to this Delete event.
78+
*/
79+
async function isBucketTaggedForDeletion(bucketName: string) {
80+
const response = await s3.getBucketTagging({ Bucket: bucketName }).promise();
81+
return response.TagSet.some(tag => tag.Key === AUTO_DELETE_OBJECTS_TAG && tag.Value === 'true');
82+
}

0 commit comments

Comments
 (0)