Skip to content

Instantly share code, notes, and snippets.

@saidach
Created December 26, 2017 18:17
Show Gist options
  • Save saidach/34e0c4ddd6408e45cbcc8f4ffd362f86 to your computer and use it in GitHub Desktop.
Save saidach/34e0c4ddd6408e45cbcc8f4ffd362f86 to your computer and use it in GitHub Desktop.
files:
"/home/ec2-user/sourceenvname.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
export AWS_DEFAULT_REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -e 's/[a-z]$//')
instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
ebenvname=$(aws --output text ec2 describe-tags --filters "Name=resource-id,Values=${instance_id}" "Name=key,Values=elasticbeanstalk:environment-name" | awk '{print $5}')
export ENV_NAME=$ebenvname
"/home/ec2-user/dev.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
echo "this is Dev" > /tmp/test.tx
commands:
00-source-env:
command: "/home/ec2-user/sourceenvname.sh"
01-run-dev:
command: "/home/ec2-user/dev.sh"
test: '. /home/ec2-user/sourceenvname.sh && [[ $ENV_NAME == *"test-ebx"* ]]'
02-run-prod:
command: "/home/ec2-user/prod.sh"
test: '. /home/ec2-user/sourceenvname.sh && [[ $ENV_NAME == *"prod-ebx"* ]]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment