Skip to content

Commit

Permalink
Add support for aws cli profile
Browse files Browse the repository at this point in the history
  • Loading branch information
gsoyka committed Nov 18, 2019
1 parent a87a86f commit c46ef08
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ endif
ifdef AWS_REGION
regionArg= --region $(AWS_REGION)
endif
ifdef AWS_PROFILE
awsProfile= --profile $(AWS_PROFILE)
endif
ifndef LAMBDA_NAME
ifndef STACK_ID
usesLambdaName := create-stack load-lambda-name
Expand Down Expand Up @@ -49,16 +52,16 @@ package:
.PHONY: create-stack-raw
create-stack-raw:
# Create CloudFormation Stack
aws cloudformation create-stack --stack-name "$(STACK_NAME)" --template-body file://cloudformation.yaml \
aws $(awsProfile) cloudformation create-stack --stack-name "$(STACK_NAME)" --template-body file://cloudformation.yaml \
$(regionArg) --capabilities CAPABILITY_IAM --parameters $(STACK_PARAMS)
aws cloudformation wait stack-create-complete --stack-name "$(STACK_NAME)" $(regionArg)
aws $(awsProfile) cloudformation wait stack-create-complete --stack-name "$(STACK_NAME)" $(regionArg)


# Create the stack, print output, and save to TARGET file
# (must be separate from create-stack-raw because uses $(shell ...)
.PHONY: create-stack
create-stack: create-stack-raw
$(eval STACK_ID := $(shell aws cloudformation describe-stacks --stack-name "$(STACK_NAME)" \
$(eval STACK_ID := $(shell aws $(awsProfile) cloudformation describe-stacks --stack-name "$(STACK_NAME)" \
$(regionArg) --output text --query 'Stacks[0].StackId' ))
@echo "Add to your .env file: STACK_ID=$(STACK_ID)"
@ [ -z "$(TARGET)" ] || { echo "# Makefile on `date`" >> "$(TARGET)"; echo "STACK_ID=$(STACK_ID)" >> "$(TARGET)"; }
Expand All @@ -67,7 +70,7 @@ create-stack: create-stack-raw
# Update CloudFormation stack
.PHONY: update-stack
update-stack:
aws cloudformation update-stack --stack-name "$(STACK_NAME)" --template-body file://cloudformation.yaml \
aws $(awsProfile) cloudformation update-stack --stack-name "$(STACK_NAME)" --template-body file://cloudformation.yaml \
$(regionArg) --capabilities CAPABILITY_IAM --parameters $(STACK_PARAMS)


Expand All @@ -76,7 +79,7 @@ update-stack:
load-lambda-name:
# Load Lambda name from CloudFormation
@if [ -z "$(STACK_NAME)" ]; then echo "Var STACK_NAME must be defined"; exit 1; fi;
$(eval LAMBDA_NAME := $(shell aws cloudformation describe-stacks --stack-name "$(STACK_NAME)" \
$(eval LAMBDA_NAME := $(shell aws $(awsProfile) cloudformation describe-stacks --stack-name "$(STACK_NAME)" \
$(regionArg) --output text --query 'Stacks[0].Outputs[?OutputKey==`LambdaFunction`].OutputValue'))
@echo "Add to your .env file: LAMBDA_NAME=$(LAMBDA_NAME)"
@ [ -z "$(TARGET)" ] || { echo "# Makefile on `date`" >> "$(TARGET)"; echo "LAMBDA_NAME=$(LAMBDA_NAME)" >> "$(TARGET)"; }
Expand All @@ -86,7 +89,7 @@ load-lambda-name:
.PHONY: deploy
deploy: $(usesReleaseZip) $(usesLambdaName)
# Update Lambda function code
aws lambda update-function-code --function-name "$(LAMBDA_NAME)" \
aws $(awsProfile) lambda update-function-code --function-name "$(LAMBDA_NAME)" \
$(regionArg) --zip-file "fileb://$(RELEASE_ZIP)" --publish


Expand All @@ -100,5 +103,5 @@ REGIONS ?= \
.PHONY: publish
publish: $(usesReleaseZip) $(REGIONS)
$(REGIONS):
aws s3 cp "./cloudformation.yaml" "s3://aws-to-slack-$@" --acl public-read
aws s3 cp "$(RELEASE_ZIP)" "s3://aws-to-slack-$@" --acl public-read
aws $(awsProfile) s3 cp "./cloudformation.yaml" "s3://aws-to-slack-$@" --acl public-read
aws $(awsProfile) s3 cp "$(RELEASE_ZIP)" "s3://aws-to-slack-$@" --acl public-read
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ Ready to try the latest version for yourself? Installation into your own AWS env
AWS_REGION="<your_lambda_region>" LAMBDA_NAME="<your_lambda_name>" make deploy
```

If you use AWS CLI profiles, simply add `AWS_PROFILE` to the make command like so:
```
AWS_PROFILE="my-profile" AWS_REGION="<your_lambda_region>" LAMBDA_NAME="<your_lambda_name>" make deploy
```

### Option 3: Use deploy target

See [Managing Multiple Deployments](#managing-multiple-deployments) for a `.env` file approach to creating or managing multiple stacks.
Expand Down

0 comments on commit c46ef08

Please sign in to comment.