Skip to content

Commit

Permalink
added aws cli profile
Browse files Browse the repository at this point in the history
  • Loading branch information
MFProduction committed Mar 1, 2017
1 parent dbd6e9f commit 075732c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
29 changes: 24 additions & 5 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ fi

if [ $# -lt 1 ]
then
echo "usage: $0 <CHANNEL> <WEBHOOK>"
echo "usage: $0 <CHANNEL> <WEBHOOK> <AWS_PROFILE>"
exit 1
fi

CHANNEL=$1
WEBHOOK=$2
PROFILE=$3

if [ -z $CHANNEL ];
then
Expand All @@ -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}
Expand All @@ -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"


Expand All @@ -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
Expand All @@ -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'
--parameters ParameterKey=Bucket,ParameterValue=$BUCKET ParameterKey=Channel,ParameterValue=$CHANNEL_NAME \
--profile $PROFILE

if [[ $? != 0 ]];
then
exit 1
else
echo 'Stack created'
fi

0 comments on commit 075732c

Please sign in to comment.