Skip to content
This repository has been archived by the owner on Nov 27, 2021. It is now read-only.

Added aws cli profile #3

Merged
merged 1 commit into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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