This guide explains how to remove the resources deployed by the AI/ML Security Assessment framework.
Before deleting any stack, record the S3 bucket names from its outputs. After a stack is deleted, its outputs are no longer available.
The deployment creates these buckets, all versioned:
AssessmentBucket output of the stack
you deployed, such as aiml-security-single-account or
aiml-security-multi-account. It holds every report, so it is never empty
after a run. CloudFormation cannot delete a bucket that still contains
objects, so empty it before deleting the stack.AssessmentBucketName output of each
AWS SAM assessment stack (aiml-sec-{account_id}, aiml-security-{account_id},
or aiml-security-mgmt). These buckets use DeletionPolicy: Retain, so they
remain after the stack is deleted. Delete them yourself for a full cleanup.sam deploy --resolve-s3 in the
aws-sam-cli-managed-default stack of each assessed account. See
Optional: AWS SAM CLI Artifact Stack.To tell the stacks apart, see Confused by Multiple CloudFormation Stacks.
Delete resources in this order:
aws-sam-cli-managed-default stack and its bucket.A recursive aws s3 rm removes only current objects; a versioned bucket still
holds noncurrent versions and delete markers. The following commands remove
current objects, noncurrent versions, and delete markers, and then the bucket.
They require jq.
To list likely buckets created by the framework (single-account names start
with aiml-sec-, multi-account names with aiml-security-, and the
infrastructure bucket name contains assessmentbucket):
aws s3 ls | grep -E 'aiml-sec|assessmentbucket'
Confirm each bucket against the names you recorded from the stack outputs before deleting it.
BUCKET_NAME="<bucket-name>"
aws s3 rm "s3://${BUCKET_NAME}" --recursive
while true; do
delete_payload=$(aws s3api list-object-versions \
--bucket "${BUCKET_NAME}" \
--output json \
| jq '{Objects: (((.Versions // []) + (.DeleteMarkers // [])) | map({Key, VersionId}) | .[0:1000])}')
object_count=$(echo "${delete_payload}" | jq '.Objects | length')
if [ "${object_count}" -eq 0 ]; then
break
fi
aws s3api delete-objects \
--bucket "${BUCKET_NAME}" \
--delete "${delete_payload}"
done
aws s3 rb "s3://${BUCKET_NAME}"
Repeat for each bucket you want to remove. To empty a bucket but keep it (for
the infrastructure bucket, before deleting its stack), skip the final
aws s3 rb command.
aiml-sec-{account_id} stack (for example,
aiml-sec-123456789012).AssessmentBucketName value.aiml-security-single-account stack (or your stack name).AssessmentBucket value.aiml-security-{account_id} stack (for example,
aiml-security-123456789012). For the central account that runs
CodeBuild, select aiml-security-mgmt.AssessmentBucketName value.Choose Delete. Alternatively, with credentials for that account, use the AWS CLI:
aws cloudformation delete-stack --stack-name aiml-security-<account_id> \
--region <deployment-region>
aiml-security-multi-account stack
(or your stack name).AssessmentBucket value.deployment/1-aiml-security-member-roles.yaml (for example,
aiml-security-member-roles).CodeBuild runs sam deploy --resolve-s3, which creates an
aws-sam-cli-managed-default stack and a versioned bucket (named
aws-sam-cli-managed-default-samclisourcebucket-*) for deployment packages. It
exists in the deployment region of each assessed account: the single account,
or each scanned member account and the central account that runs CodeBuild.
Warning: This stack and bucket are shared by every AWS SAM CLI project that deploys with
--resolve-s3in the same account and region. Delete them only if nothing else in that account and region uses the AWS SAM CLI.
To remove them:
aws-sam-cli-managed-default stack, and record the SourceBucket
output.aws s3 rb.aws-sam-cli-managed-default stack.AWS Lambda and AWS CodeBuild create Amazon CloudWatch log groups during assessment runs. These log groups remain after the stacks are deleted unless you delete them or set a retention period.
Log group names follow these patterns:
/aws/lambda/aiml-security-*/aws/codebuild/AIMLSecurityCodeBuild/aws/codebuild/AIMLSecurityMultiAccountCodeBuild/aws/lambda/<infrastructure-stack-name>-CodeBuildStartBuildLambda-* (the
function that starts the first build)To list them:
aws logs describe-log-groups \
--log-group-name-prefix /aws/lambda/aiml-security-
aws logs describe-log-groups \
--log-group-name-prefix /aws/codebuild/AIMLSecurity
To delete a log group:
aws logs delete-log-group --log-group-name "<log-group-name>"