|
| 1 | +#!/bin/bash |
| 2 | +echo "Starting cleanup." |
| 3 | + |
| 4 | +# Check if jq is in the PATH |
| 5 | +found=$(which jq) |
| 6 | +if [ -z "$found" ]; then |
| 7 | + echo "Please install jq under your PATH: http://stedolan.github.io/jq/" |
| 8 | + exit 1 |
| 9 | +fi |
| 10 | + |
| 11 | +# Ensure config.json exists |
| 12 | +if [ ! -f config.json ]; then |
| 13 | + echo "config.json not found!" |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +# Get config parmaters |
| 18 | +echo "Loading config parameters" |
| 19 | +REGION=$(jq -r '.REGION' config.json) |
| 20 | +if [ -z "$REGION" ]; then |
| 21 | + echo "config.json: REGION value is required, but missing!" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +BUCKET=$(jq -r '.BUCKET' config.json) |
| 26 | +if [ -z "$BUCKET" ]; then |
| 27 | + echo "config.json: BUCKET value is required, but missing!" |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +# Remove IAM Roles Created for Lambda functions and Cognito |
| 32 | +echo "Removing IAM Roles" |
| 33 | +aws iam delete-role-policy --role-name LambdAuthChangePassword --policy-name LambdAuthChangePassword |
| 34 | +aws iam delete-role --role-name LambdAuthChangePassword |
| 35 | + |
| 36 | +aws iam delete-role-policy --role-name LambdAuthCreateUser --policy-name LambdAuthCreateUser |
| 37 | +aws iam delete-role --role-name LambdAuthCreateUser |
| 38 | + |
| 39 | +aws iam delete-role-policy --role-name LambdAuthLogin --policy-name LambdAuthLogin |
| 40 | +aws iam delete-role --role-name LambdAuthLogin |
| 41 | + |
| 42 | +aws iam delete-role-policy --role-name LambdAuthLostPassword --policy-name LambdAuthLostPassword |
| 43 | +aws iam delete-role --role-name LambdAuthLostPassword |
| 44 | + |
| 45 | +aws iam delete-role-policy --role-name LambdAuthResetPassword --policy-name LambdAuthResetPassword |
| 46 | +aws iam delete-role --role-name LambdAuthResetPassword |
| 47 | + |
| 48 | +aws iam delete-role-policy --role-name LambdAuthVerifyUser --policy-name LambdAuthVerifyUser |
| 49 | +aws iam delete-role --role-name LambdAuthVerifyUser |
| 50 | + |
| 51 | +aws iam delete-role-policy --role-name Cognito_LambdAuthAuth_Role --policy-name Cognito_LambdAuthAuth_Role |
| 52 | +aws iam delete-role --role-name Cognito_LambdAuthAuth_Role |
| 53 | + |
| 54 | +aws iam delete-role-policy --role-name Cognito_LambdAuthUnauth_Role --policy-name Cognito_LambdAuthUnauth_Role |
| 55 | +aws iam delete-role --role-name Cognito_LambdAuthUnauth_Role |
| 56 | + |
| 57 | + |
| 58 | +# Remove Cognito Identity Pool |
| 59 | +echo "Removing Cognito Identity Pool" |
| 60 | +aws cognito-identity delete-identity-pool --identity-pool-id `aws cognito-identity list-identity-pools --max-results 2 --region $REGION | jq -r '.IdentityPools[] | select(.IdentityPoolName == "LambdAuth") .IdentityPoolId'` --region $REGION |
| 61 | + |
| 62 | +# Remove dynamodb Table |
| 63 | +echo "Removing DynamoDB table" |
| 64 | +aws dynamodb delete-table --table-name LambdAuthUsers --region $REGION |
| 65 | + |
| 66 | +# Remove the S3 Bucket |
| 67 | +echo "Removing S3 Bucket" |
| 68 | +aws s3 rm s3://$BUCKET --recursive |
| 69 | +aws s3 rb s3://$BUCKET --force |
| 70 | + |
| 71 | +# Remove Lambda functions |
| 72 | +echo "Removing Lambda functions..." |
| 73 | +aws lambda delete-function --function-name LambdAuthChangePassword --region $REGION |
| 74 | +aws lambda delete-function --function-name LambdAuthCreateUser --region $REGION |
| 75 | +aws lambda delete-function --function-name LambdAuthLogin --region $REGION |
| 76 | +aws lambda delete-function --function-name LambdAuthLostPassword --region $REGION |
| 77 | +aws lambda delete-function --function-name LambdAuthResetPassword --region $REGION |
| 78 | +aws lambda delete-function --function-name LambdAuthVerifyUser --region $REGION |
| 79 | + |
| 80 | +# Remove CloudWatch Logs and Streams |
| 81 | +for f in $(aws logs describe-log-groups --region $REGION | jq -r '.logGroups[] | select(.logGroupName | contains("LambdAuth")) .logGroupName'); do |
| 82 | + echo "Deleting Log group: $f" |
| 83 | + aws logs delete-log-group --log-group-name "$f" --region $REGION |
| 84 | +done |
| 85 | + |
| 86 | +echo "Cleanup complete." |
0 commit comments