Skip to content

Commit f012204

Browse files
committed
stg use role_arn too
1 parent c614744 commit f012204

File tree

5 files changed

+15
-24
lines changed

5 files changed

+15
-24
lines changed

.envrc.example

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#!/usr/bin/env bash
22

3-
export AWS_ACCESS_KEY_ID=
4-
export AWS_SECRET_ACCESS_KEY=
5-
export AWS_DEFAULT_REGION=
6-
export AWS_REGION=
7-
8-
export PROD_ROLE_ARN=
3+
export ROLE_ARN_stg=
4+
export ROLE_ARN_prod=
95

106
export SLACK_WEBHOOK_URL=
11-
12-
unset AWS_SESSION_TOKEN

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ before_deploy:
2929
- npm prune --production
3030
deploy:
3131
- provider: script
32-
script: ./scripts/deploy.sh ${ENV}
32+
script: ./scripts/deploy.sh
3333
skip_cleanup: true
3434
on:
3535
branch: deploy/*

scripts/deploy.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
set -u
44

5-
ENV=$1
6-
7-
if [ "${ENV}" = "prod" ]; then
8-
source scripts/switch-production-role.sh
5+
if [ ! -v AWS_SESSION_TOKEN ]; then
6+
source ./scripts/switch-role.sh
97
fi
108

119
# account number to mask

scripts/switch-production-role.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

scripts/switch-role.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# Parse variable such as ROLE_ARN_stg, ROLE_ARN_prod and etc.
4+
ROLE_ARN=$(eval echo '$ROLE_ARN_'${ENV})
5+
6+
CREDENTIALS=$(aws sts assume-role --role-arn ${ROLE_ARN} --role-session-name travisci)
7+
8+
export AWS_ACCESS_KEY_ID=$(echo ${CREDENTIALS} | jq --raw-output .Credentials.AccessKeyId)
9+
export AWS_SECRET_ACCESS_KEY=$(echo ${CREDENTIALS} | jq --raw-output .Credentials.SecretAccessKey)
10+
export AWS_SESSION_TOKEN=$(echo ${CREDENTIALS} | jq --raw-output .Credentials.SessionToken)

0 commit comments

Comments
 (0)