|
3 | 3 | # Stop the script execution if an error occurs |
4 | 4 | set -e -o pipefail |
5 | 5 |
|
6 | | -alias aws="aws --profile seb" |
7 | | - |
8 | 6 | # check if docker is installed |
9 | | -which docker > /dev/null |
10 | | -if [[ $? != 0 ]]; then |
11 | | - echo "Docker is not installed. Please install Docker and try again." |
12 | | - exit 1 |
13 | | -fi |
| 7 | +which docker > /dev/null || (echo "Docker is not installed. Please install Docker and try again." && exit 1) |
| 8 | + |
| 9 | +# check if aws cli is installed |
| 10 | +which aws > /dev/null || (echo "AWS CLI is not installed. Please install AWS CLI and try again." && exit 1) |
| 11 | + |
| 12 | +# import code present in create_iam_role.sh |
| 13 | +source ./create_iam_role.sh |
14 | 14 |
|
15 | 15 | # check if user has an access key and secret access key |
16 | 16 | echo "This script creates and deploys a Lambda function on your AWS Account. |
@@ -86,45 +86,6 @@ echo "🚀 Deploy to AWS Lambda" |
86 | 86 | echo "🔑 Retrieve your AWS Account ID" |
87 | 87 | export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) |
88 | 88 |
|
89 | | -# |
90 | | -# Create an IAM role for the Lambda function |
91 | | -# |
92 | | -create_lambda_execution_role() { |
93 | | - role_name=$1 |
94 | | - |
95 | | - # Allow the Lambda service to assume the IAM role |
96 | | - cat <<EOF > trust-policy.json |
97 | | -{ |
98 | | - "Version": "2012-10-17", |
99 | | - "Statement": [ |
100 | | - { |
101 | | - "Effect": "Allow", |
102 | | - "Principal": { |
103 | | - "Service": "lambda.amazonaws.com" |
104 | | - }, |
105 | | - "Action": "sts:AssumeRole" |
106 | | - } |
107 | | - ] |
108 | | -} |
109 | | -EOF |
110 | | - |
111 | | - # Create the IAM role |
112 | | - echo "🔐 Create the IAM role for the Lambda function" |
113 | | - aws iam create-role \ |
114 | | - --role-name $role_name \ |
115 | | - --assume-role-policy-document file://trust-policy.json > /dev/null 2>&1 |
116 | | - |
117 | | - # Attach basic permissions to the role |
118 | | - # The AWSLambdaBasicExecutionRole policy grants permissions to write logs to CloudWatch Logs |
119 | | - echo "🔒 Attach basic permissions to the role" |
120 | | - aws iam attach-role-policy \ |
121 | | - --role-name $role_name \ |
122 | | - --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole > /dev/null 2>&1 |
123 | | - |
124 | | - echo "⏰ Waiting 10 secs for IAM role to propagate..." |
125 | | - sleep 10 |
126 | | -} |
127 | | - |
128 | 89 | # Check if the role already exists |
129 | 90 | echo "🔍 Check if a Lambda execution IAM role already exists" |
130 | 91 | aws iam get-role --role-name lambda_basic_execution > /dev/null 2>&1 || create_lambda_execution_role lambda_basic_execution |
|
0 commit comments