Skip to content

Commit 159e175

Browse files
committed
Merge branch 'fix-cleanup' into 'main'
Fix resources cleanup See merge request observability-bd-projects/one-observability-demo!122
2 parents e5768b1 + 71b076a commit 159e175

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

PetAdoptions/cdk/pet_stack/lib/common/container-image-builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export class ContainerImageBuilder extends Construct {
3131
const repository = new ecr.Repository(this, props.repositoryName + 'Repository', {
3232
repositoryName: props.repositoryName,
3333
imageScanOnPush: true,
34-
removalPolicy: cdk.RemovalPolicy.DESTROY
34+
removalPolicy: cdk.RemovalPolicy.DESTROY,
35+
autoDeleteImages: true,
3536
});
3637
const image = new ecrassets.DockerImageAsset(this, props.repositoryName + 'DockerImageAsset', {
3738
directory: props.dockerImageAssetDirectory

PetAdoptions/cdk/pet_stack/lib/services.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export class Services extends Stack {
6060

6161
// Creates an S3 bucket to store pet images
6262
const s3_observabilitypetadoptions = new s3.Bucket(this, 's3bucket_petadoption', {
63-
publicReadAccess: false
63+
publicReadAccess: false,
64+
autoDeleteObjects: true,
65+
removalPolicy: RemovalPolicy.DESTROY,
6466
});
6567

6668
// Creates the DynamoDB table for Petadoption data

PetAdoptions/cdk/pet_stack/resources/destroy_stack.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ echo ---------------------------------------------------------------------------
44
echo This script destroys the CDK stack
55
echo ---------------------------------------------------------------------------------------------
66

7+
if [ -z "$AWS_REGION" ]; then
8+
echo "Fatal: environment variable AWS_REGION not set. Aborting."
9+
exit 1
10+
fi
11+
712
# Disable Contributor Insights
813
DDB_CONTRIB=$(aws ssm get-parameter --name '/petstore/dynamodbtablename' | jq .Parameter.Value -r)
914
aws dynamodb update-contributor-insights --table-name $DDB_CONTRIB --contributor-insights-action DISABLE
@@ -24,21 +29,15 @@ aws eks update-kubeconfig --name PetSite
2429
kubectl delete -f https://raw.githubusercontent.com/aws-samples/one-observability-demo/main/PetAdoptions/cdk/pet_stack/resources/load_balancer/crds.yaml
2530

2631
# Get rid of all resources (Application first, then cluster or it will fail)
27-
cdk destroy $STACK_NAME_APP $STACK_NAME --force
32+
cdk destroy $STACK_NAME_APP --force
2833
cdk destroy $STACK_NAME --force
2934

3035
# Sometimes the SqlSeeder doesn't get deleted cleanly. This helps clean up the environment completely including Sqlseeder
31-
aws cloudformation delete-stack --stack-name $STACK_NAME
3236
aws cloudformation delete-stack --stack-name $STACK_NAME_APP
37+
aws cloudformation delete-stack --stack-name $STACK_NAME
3338

3439
aws cloudwatch delete-dashboards --dashboard-names "EKS_FluentBit_Dashboard"
3540

36-
# delete s3 buckets
37-
for b in $(aws s3 ls | awk '/services-s3bucketpetadoption/ {print $3}'); do
38-
echo "deleting ${b}"
39-
aws s3 rb s3://$b --force
40-
done
41-
4241
echo CDK BOOTSTRAP WAS NOT DELETED
4342

4443
echo ----- ✅ DONE --------

0 commit comments

Comments
 (0)