Skip to content

Commit 96c132f

Browse files
committed
add error handling logic to ignore if rule no longer exists
1 parent 088d882 commit 96c132f

File tree

1 file changed

+27
-15
lines changed
  • src/lib/custom-resources/cdk-vpc-default-security-group/runtime/src

1 file changed

+27
-15
lines changed

src/lib/custom-resources/cdk-vpc-default-security-group/runtime/src/index.ts

+27-15
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,39 @@ async function onCreate(event: CloudFormationCustomResourceEvent) {
5656

5757
if (groupId) {
5858
if (securityGroupIngress && securityGroupIngress.length > 0) {
59-
// Deleting VPC default security group inbound rule
60-
await throttlingBackOff(() => ec2.revokeSecurityGroupIngress(buildDeleteIngressRequest({ groupId })).promise());
59+
try {
60+
// Deleting VPC default security group inbound rule
61+
await throttlingBackOff(() => ec2.revokeSecurityGroupIngress(buildDeleteIngressRequest({ groupId })).promise());
62+
} catch (error: any) {
63+
console.log('Error trying to remove default security group Ingress rule');
64+
}
6165
}
6266

6367
if (securityGroupEgress && securityGroupEgress.length > 0) {
64-
// Deleting VPC default security group outbound rule
65-
await throttlingBackOff(() => ec2.revokeSecurityGroupEgress(buildDeleteEgressRequest({ groupId })).promise());
68+
try {
69+
// Deleting VPC default security group outbound rule
70+
await throttlingBackOff(() => ec2.revokeSecurityGroupEgress(buildDeleteEgressRequest({ groupId })).promise());
71+
} catch (error: any) {
72+
console.log('Error trying to remove default security group Egress rule');
73+
}
6674
}
6775

6876
if (tags && tags.length === 0) {
69-
// Attaching tags to the VPC default security group
70-
await throttlingBackOff(() =>
71-
ec2
72-
.createTags(
73-
buildCreateTagsRequest({
74-
groupId,
75-
acceleratorName: event.ResourceProperties.acceleratorName,
76-
}),
77-
)
78-
.promise(),
79-
);
77+
try {
78+
// Attaching tags to the VPC default security group
79+
await throttlingBackOff(() =>
80+
ec2
81+
.createTags(
82+
buildCreateTagsRequest({
83+
groupId,
84+
acceleratorName: event.ResourceProperties.acceleratorName,
85+
}),
86+
)
87+
.promise(),
88+
);
89+
} catch (error: any) {
90+
console.log('Error trying to add tags to default security group');
91+
}
8092
}
8193
}
8294

0 commit comments

Comments
 (0)