Teardown
Progress checklist
Overview
Section titled “Overview”This page tears down everything created in the Lambda walkthrough, in dependency order: function → access points → mount targets → file system → IAM → security groups → bucket (optional).
-
Set environment variables. Required
Re-run these in your current shell. Replace values to match what you created:
Terminal window export AWS_REGION=ap-southeast-6export BUCKET=my-s3-files-bucket # ← replace with your real bucket nameexport BUCKET_ARN=arn:aws:s3:::${BUCKET}export ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)export VPC_ID=vpc-0123456789abcdef0 # ← replace with your VPC IDexport FS_ID=$(aws s3files list-file-systems \--region $AWS_REGION \--bucket $BUCKET_ARN \--query 'fileSystems[0].fileSystemId' \--output text)echo "FS_ID=$FS_ID Account: $ACCOUNT_ID" -
Remove the file system configuration from the function and delete it. Required
Remove the file system config first, then delete the function:
Terminal window aws lambda update-function-configuration \--function-name s3files-lambda-demo \--file-system-configs [] \--region $AWS_REGIONWait for the update to complete:
Terminal window aws lambda wait function-updated \--function-name s3files-lambda-demo \--region $AWS_REGIONDelete the function:
Terminal window aws lambda delete-function \--function-name s3files-lambda-demo \--region $AWS_REGIONecho "Lambda function deleted" -
Delete all access points. Required
Terminal window AP_IDS=$(aws s3files list-access-points \--region $AWS_REGION \--file-system-id $FS_ID \--query 'accessPoints[*].accessPointId' \--output text)echo "Access points: $AP_IDS"for AP_ID in $AP_IDS; doaws s3files delete-access-point \--region $AWS_REGION \--access-point-id $AP_IDecho "Deleted access point $AP_ID"done -
Delete all mount targets. Required
The file system cannot be deleted while mount targets exist.
Terminal window MT_IDS=$(aws s3files list-mount-targets \--region $AWS_REGION \--file-system-id $FS_ID \--query 'mountTargets[*].mountTargetId' \--output text)echo "Mount targets: $MT_IDS"for MT_ID in $MT_IDS; doaws s3files delete-mount-target \--region $AWS_REGION \--mount-target-id $MT_IDecho "Deleted mount target $MT_ID"doneWait until the list is empty:
Terminal window until [ "$(aws s3files list-mount-targets \--region $AWS_REGION \--file-system-id $FS_ID \--query 'length(mountTargets)' \--output text)" = "0" ]; doecho "Waiting for mount targets to delete…"sleep 10doneecho "All mount targets deleted" -
Delete the file system. Required
Terminal window aws s3files delete-file-system \--region $AWS_REGION \--file-system-id $FS_IDecho "File system deletion initiated"Confirm deletion:
Terminal window aws s3files list-file-systems \--region $AWS_REGION \--bucket $BUCKET_ARN \--query 'fileSystems[*].{id:fileSystemId,status:status}' \--output table -
Delete IAM roles. Required
Detach managed policies and delete the Lambda execution role:
Terminal window aws iam detach-role-policy \--role-name s3files-compute-role-lambda \--policy-arn arn:aws:iam::aws:policy/AmazonS3FilesClientFullAccessaws iam detach-role-policy \--role-name s3files-compute-role-lambda \--policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRoleaws iam delete-role-policy \--role-name s3files-compute-role-lambda \--policy-name S3FilesComputeS3ReadPolicyaws iam delete-role --role-name s3files-compute-role-lambdaecho "Lambda execution role deleted"Delete the file system role:
Terminal window aws iam delete-role-policy \--role-name s3files-filesystem-role \--policy-name S3FilesFileSystemPolicyaws iam delete-role --role-name s3files-filesystem-roleecho "File system role deleted" -
Delete the compute security group. Required
The Lambda compute SG must be deleted before the mount target SG:
Terminal window COMPUTE_SG_ID=$(aws ec2 describe-security-groups \--filters "Name=group-name,Values=s3files-lambda-compute-sg" \"Name=vpc-id,Values=$VPC_ID" \--region $AWS_REGION \--query 'SecurityGroups[0].GroupId' \--output text)echo "COMPUTE_SG_ID=$COMPUTE_SG_ID"aws ec2 delete-security-group \--group-id $COMPUTE_SG_ID \--region $AWS_REGIONecho "Lambda compute SG deleted" -
Delete the mount target security group. Required
Terminal window MT_SG_ID=$(aws ec2 describe-security-groups \--filters "Name=group-name,Values=s3files-mount-target-sg" \"Name=vpc-id,Values=$VPC_ID" \--region $AWS_REGION \--query 'SecurityGroups[0].GroupId' \--output text)echo "MT_SG_ID=$MT_SG_ID"aws ec2 delete-security-group \--group-id $MT_SG_ID \--region $AWS_REGIONecho "Mount target SG deleted" -
Empty and delete the S3 bucket (optional).
Delete all versioned objects:
Terminal window aws s3api list-object-versions \--bucket $BUCKET \--output json \--query '{Objects: Versions[].{Key:Key,VersionId:VersionId}}' \| jq -c '.Objects // [] | _nwise(1000) | {Objects: ., Quiet: true}' \| while read batch; doaws s3api delete-objects --bucket $BUCKET --delete "$batch"doneDelete all delete markers:
Terminal window aws s3api list-object-versions \--bucket $BUCKET \--output json \--query '{Objects: DeleteMarkers[].{Key:Key,VersionId:VersionId}}' \| jq -c '.Objects // [] | _nwise(1000) | {Objects: ., Quiet: true}' \| while read batch; doaws s3api delete-objects --bucket $BUCKET --delete "$batch"doneDelete any incomplete multipart uploads:
Terminal window aws s3api list-multipart-uploads --bucket $BUCKET \--query 'Uploads[*].{Key:Key,UploadId:UploadId}' \--output json \| jq -r '.[] | "\(.Key) \(.UploadId)"' \| while read key upload_id; doaws s3api abort-multipart-upload \--bucket $BUCKET --key "$key" --upload-id "$upload_id"doneDelete the bucket:
Terminal window aws s3api delete-bucket --bucket $BUCKET --region $AWS_REGIONecho "Bucket $BUCKET deleted"
All Lambda walkthrough resources have been removed.