Skip to content

Commit 40f7aa7

Browse files
committed
Updates to ensure error instance output is formatted cleaner. Allow AWS
deploy key and access secret to use pre-defined configurations (slightly more secure).
1 parent 5a7d90b commit 40f7aa7

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ The following executables are installed:
7474

7575
#### Step 2: [Configuring AWS](http://docs.aws.amazon.com/cli/latest/reference/configure/index.html)
7676

77-
This step ensures that configuration parameters for AWS cli are properly set.
77+
This step ensures that configuration parameters for AWS CLI are properly set.
7878

7979
Environment Variables:
8080

aws-code-deploy.sh

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ jsonValue() {
8686
}
8787

8888
# Check variables
89-
if [ -z "$AWS_CODE_DEPLOY_KEY" ]; then
90-
error "Please set the \"\$AWS_CODE_DEPLOY_KEY\" variable"
91-
exit 1
92-
fi
93-
94-
if [ -z "$AWS_CODE_DEPLOY_SECRET" ]; then
95-
error "Please set the \"\$AWS_CODE_DEPLOY_SECRET\" variable"
96-
exit 1
97-
fi
9889

9990
if [ -z "$AWS_CODE_DEPLOY_APPLICATION_NAME" ]; then
10091
error "Please set the \"\$AWS_CODE_DEPLOY_APPLICATION_NAME\" variable"
@@ -130,7 +121,7 @@ if ! typeExists "aws"; then
130121
runCommand "sudo pip install awscli"
131122
success "Installing AWS CLI (`aws --version`) succeeded"
132123
else
133-
success "Dependencies met."
124+
success "Depenencies met."
134125
fi
135126

136127

@@ -141,17 +132,47 @@ fi
141132
# ----------------------
142133

143134
h1 "Step 2: Configuring AWS"
144-
h2 "Configuring AWS Access Key ID"
145-
CONFIGURE_KEY_OUTPUT=$(aws configure set aws_access_key_id $AWS_CODE_DEPLOY_KEY 2>&1)
146-
success "Configuring AWS Access Key ID succeeded"
147-
h2 "Configuring AWS Secret Access Key"
148-
CONFIGURE_SECRET_OUTPUT=$(aws configure set aws_secret_access_key $AWS_CODE_DEPLOY_SECRET 2>&1)
149-
success "Configuring AWS Secret Access Key succeeded"
150-
151-
if [ -n "$AWS_CODE_DEPLOY_REGION" ]; then
152-
h2 "Configuring AWS default region"
135+
if [ -z "$AWS_CODE_DEPLOY_KEY" ]; then
136+
if [ ! -e ~/.aws/config ]; then
137+
error "Please configure AWS credentials or explicitly set the \"\$AWS_CODE_DEPLOY_KEY\" variable"
138+
exit 1
139+
fi
140+
if [ $(grep aws_access_key_id ~/.aws/config | wc -l) -lt 1 ]; then
141+
error "Unable to find \"aws_access_key_id\" in ~/.aws/config. Please configure AWS credentials or explicitly set the \"\$AWS_CODE_DEPLOY_KEY\" variable"
142+
exit 1
143+
fi
144+
success "AWS Access Key already configured."
145+
else
146+
CONFIGURE_KEY_OUTPUT=$(aws configure set aws_access_key_id $AWS_CODE_DEPLOY_KEY 2>&1)
147+
success "Successfully configured AWS Access Key ID."
148+
fi
149+
150+
if [ -z "$AWS_CODE_DEPLOY_SECRET" ]; then
151+
if [ ! -e ~/.aws/config ]; then
152+
error "Please configure AWS credentials or explicitly set the \"\$AWS_CODE_DEPLOY_SECRET\" variable"
153+
exit 1
154+
fi
155+
if [ $(grep aws_secret_access_key ~/.aws/config | wc -l) -lt 1 ]; then
156+
error "Unable to find \"aws_secret_access_key\" in ~/.aws/config. Please configure AWS credentials or explicitly set the \"\$AWS_CODE_DEPLOY_SECRET\" variable"
157+
exit 1
158+
fi
159+
success "AWS Secret Access Key already configured."
160+
else
161+
CONFIGURE_KEY_OUTPUT=$(aws configure set aws_secret_access_key $AWS_CODE_DEPLOY_SECRET 2>&1)
162+
success "Successfully configured AWS Secret Access Key ID."
163+
fi
164+
165+
if [ -z "$AWS_CODE_DEPLOY_REGION" ]; then
166+
if [ -e ~/.aws/config ]; then
167+
if [ $(grep region ~/.aws/config | wc -l) -lt 1 ]; then
168+
warnNotice "Unable to configure AWS region."
169+
else
170+
success "AWS Region already configured."
171+
fi
172+
fi
173+
else
153174
CONFIGURE_REGION_OUTPUT=$(aws configure set default.region $AWS_CODE_DEPLOY_REGION 2>&1)
154-
success "Configuring AWS default region succeeded"
175+
success "Successfully configured AWS default region."
155176
fi
156177

157178

@@ -381,8 +402,6 @@ runCommand "$REGISTER_APP_CMD" \
381402
# see documentation http://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html
382403
# ----------------------
383404
DEPLOYMENT_DESCRIPTION="$AWS_CODE_DEPLOY_DEPLOYMENT_DESCRIPTION"
384-
DEPLOYMENT_OVERVIEW=${AWS_CODE_DEPLOY_DEPLOYMENT_OVERVIEW:-true}
385-
386405
h1 "Step 10: Creating Deployment"
387406
DEPLOYMENT_CMD="aws deploy create-deployment --application-name $APPLICATION_NAME --deployment-config-name $DEPLOYMENT_CONFIG_NAME --deployment-group-name $DEPLOYMENT_GROUP --s3-location $S3_LOCATION"
388407

@@ -405,6 +424,7 @@ note "You can follow your deployment at: https://console.aws.amazon.com/codedepl
405424
# ----- Monitor Deployment -----
406425
# see documentation http://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html
407426
# ----------------------
427+
DEPLOYMENT_OVERVIEW=${AWS_CODE_DEPLOY_DEPLOYMENT_OVERVIEW:-true}
408428
if [ "true" = "$DEPLOYMENT_OVERVIEW" ]; then
409429
h1 "Deployment Overview"
410430

@@ -515,10 +535,8 @@ if [ "true" = "$DEPLOYMENT_OVERVIEW" ]; then
515535
continue
516536
fi
517537

518-
# Attempt to get error message
519-
ERROR_CODE=$(echo $line | sed -r 's/DIAGNOSTICS//g' | sed -r 's/LifecycleEvent\s-\s[a-zA-Z]+//g')
520-
printf " ${red} Error Code: %s${reset}\n" $ERROR_CODE
521-
printf " ${red} Error Log:${reset}\n"
538+
# Just pipe off the DIAGNOSTICS
539+
printf "${red}%s${reset}\n" "$(echo $line | sed -r 's/^DIAGNOSTICS\s*//g')"
522540
;;
523541

524542
*)

0 commit comments

Comments
 (0)