From 075732c57e3a3cc65ce5a3c85bf35554e4cbb21a Mon Sep 17 00:00:00 2001 From: mferenc Date: Wed, 1 Mar 2017 14:01:57 +0100 Subject: [PATCH] added aws cli profile --- README.md | 3 ++- deploy.sh | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fc1b540..5df6b5c 100644 --- a/README.md +++ b/README.md @@ -35,12 +35,13 @@ You can create an incoming webhook [here](https://my.slack.com/services/new/inco This is done using the script [deploy.sh](./deploy.sh). ```sh -./deploy.sh $CHANNEL $WEBHOOK +./deploy.sh $CHANNEL $WEBHOOK $AWS_PROFILE ``` Where: - CHANNEL is the Slack channel or user to send messages to. It will be used in the naming of the Lambda artifact file stored in S3. - WEBHOOK is the Web Hook URL of an Incoming Web Hook (see https://api.slack.com/incoming-webhooks). + - AWS_PROFILE is the aws cli profile you want to use for deploy. Default profile is "default" `deploy.sh` will create a zip file and upload it to S3 and also create a cloud formation stack using the [template](./cf-notify.json). diff --git a/deploy.sh b/deploy.sh index caf287b..4440aa1 100755 --- a/deploy.sh +++ b/deploy.sh @@ -8,12 +8,13 @@ fi if [ $# -lt 1 ] then - echo "usage: $0 " + echo "usage: $0 " exit 1 fi CHANNEL=$1 WEBHOOK=$2 +PROFILE=$3 if [ -z $CHANNEL ]; then @@ -27,6 +28,17 @@ then exit 1 fi +if [ -z $PROFILE ]; +then + PROFILE="default" +fi + +if [[ $(aws configure --profile $PROFILE list) && $? -ne 0 ]]; +then + exit 1 +fi + + if [ ${CHANNEL:0:1} != '#' ] && [ ${CHANNEL:0:1} != '@' ]; then echo ${CHANNEL:0:1} @@ -39,7 +51,7 @@ CHANNEL_NAME=`echo ${CHANNEL:1} | tr '[:upper:]' '[:lower:]'` echo 'Creating bucket' BUCKET="cf-notify-$CHANNEL_NAME-`pwgen -1 --no-capitalize 5`" echo $BUCKET -aws s3 mb "s3://$BUCKET" +aws s3 mb "s3://$BUCKET" --profile $PROFILE echo "Bucket $BUCKET created" @@ -54,7 +66,7 @@ echo 'Lambda artifact created' echo 'Moving lambda artifact to S3' -aws s3 cp cf-notify.zip s3://$BUCKET/cf-notify-$CHANNEL_NAME.zip +aws s3 cp cf-notify.zip s3://$BUCKET/cf-notify-$CHANNEL_NAME.zip --profile $PROFILE rm slack.py rm cf-notify.zip @@ -65,5 +77,12 @@ aws cloudformation create-stack \ --template-body file://cf-notify.json \ --stack-name cf-notify-$CHANNEL_NAME \ --capabilities CAPABILITY_IAM \ - --parameters ParameterKey=Bucket,ParameterValue=$BUCKET ParameterKey=Channel,ParameterValue=$CHANNEL_NAME -echo 'Stack created' \ No newline at end of file + --parameters ParameterKey=Bucket,ParameterValue=$BUCKET ParameterKey=Channel,ParameterValue=$CHANNEL_NAME \ + --profile $PROFILE + +if [[ $? != 0 ]]; +then + exit 1 +else + echo 'Stack created' +fi