Skip to content

Commit

Permalink
Added scripts to delete ECR repository, user role and lambda function
Browse files Browse the repository at this point in the history
from AWS
  • Loading branch information
harris-chris committed May 15, 2021
1 parent 6016ba0 commit 4717a48
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"aws": {
"account_id": "111111111111",
"account_id": "513118378795",
"region": "ap-northeast-1",
"role": "lambda-role"
},
Expand Down
14 changes: 4 additions & 10 deletions template/scripts/create_lambda_function.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#!/bin/bash

# Delete lambda function if it already exists
aws lambda list-functions \
| grep '"FunctionArn": "$(image.function_arn_string)"' \
>/dev/null
# Get the current path
THIS_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )

if [ $? -eq 0 ];
then
echo "Found existing function; deleting it"
aws lambda delete-function \
--function-name=$(lambda_function.name)
fi
# Delete lambda function if it already exists
bash $THIS_DIR/delete_lambda_function.sh

# Create a function based on the ECR image
read RESULT < <(aws lambda create-function \
Expand Down
8 changes: 8 additions & 0 deletions template/scripts/delete_all_from_aws.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Get the current path
THIS_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )

bash $THIS_DIR/delete_ecr_repository.sh
bash $THIS_DIR/delete_lambda_function.sh
bash $THIS_DIR/delete_lambda_user_role.sh
12 changes: 12 additions & 0 deletions template/scripts/delete_ecr_repository.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
aws ecr describe-repositories | grep '"repositoryArn": "$(image.ecr_arn_string)"' >/dev/null
if [ $? -eq 0 ];
then
aws ecr delete-repository \
--force \
--repository-name $(image.name) \
</dev/null
echo "Deleted repository $(image.name)"
else
echo "Unable to delete repository $(image.name); does not exist"
fi
14 changes: 14 additions & 0 deletions template/scripts/delete_lambda_function.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# Check if the lambda function exists
aws lambda list-functions \
| grep '"FunctionArn": "$(image.function_arn_string)"' \
>/dev/null

if [ $? -eq 0 ];
then
echo "Found existing function; deleting it"
aws lambda delete-function \
--function-name=$(lambda_function.name) >/dev/null
else
echo "Unable to delete function $(lambda_function.name); does not exist"
fi
12 changes: 12 additions & 0 deletions template/scripts/delete_lambda_user_role.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# See if the role already exists
aws iam list-roles | grep '"Arn": "$(aws.role_arn_string)"' >/dev/null
if [ $? -eq 1 ];
then
# It doesn't exist, so we can create it
echo "Unable to delete User role $(aws.role); does not exist"
else
# The role does exist; delete it
aws iam delete-role --role-name $(aws.role)
echo "Deleted user role $(aws.role)"
fi
8 changes: 0 additions & 8 deletions template/scripts/test.sh

This file was deleted.

0 comments on commit 4717a48

Please sign in to comment.