Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feat/target group #3

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.idea

# Make
!environments/example.mvars
environments/*.mvars

# SAM Specific files
Expand Down
31 changes: 21 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ NC = \033[0m

default:help;

appName=continuous-dev-environment
env?=dev

include environments/$(env).mvars

region=us-east-1
stack_name=$(appName)
profile=$(appName)
baseDomain=example.com
bucket=example-template-bucket
role=arn:aws:iam::ACCOUNTID:role/cloudformation-role
certificateArn=arn:aws:acm:us-east-1:ACCOUNTID:certificate/CERTIFICATEID
user=prenom.nom@continuous.team
roleSSO=continuous-team-sso-Role-ABCDEFG
appName=continuous-dev-environment
stack_name?=$(appName)

EC2InstanceId=$(shell aws ec2 describe-instances --profile $(profile) --region $(region) --filters "Name=instance-type,Values=m5.large" --query "Reservations[*].Instances[*].{Instance:InstanceId}" --output text)
WebappTargetGroup=$(shell aws cloudformation describe-stacks --profile $(profile) --stack-name $(appName) --region $(region) --query "Stacks[0].Outputs[?OutputKey=='WebappTargetGroup'].OutputValue" --output text)
ApiTargetGroup=$(shell aws cloudformation describe-stacks --profile $(profile) --stack-name $(appName) --region $(region) --query "Stacks[0].Outputs[?OutputKey=='ApiTargetGroup'].OutputValue" --output text)

## Display this help dialog
help:
Expand Down Expand Up @@ -55,6 +53,7 @@ deploy:
--parameter-overrides BaseDomain=$(baseDomain) CertificateArn=$(certificateArn) \
User=$(user) RoleSSO=$(roleSSO)


## Describe Cloud Formation stack outputs
describe:
@aws --profile $(profile) \
Expand All @@ -69,3 +68,15 @@ delete:
--region $(region) \
cloudformation delete-stack \
--stack-name $(stack_name)

target-group:
@aws elbv2 register-targets \
--target-group-arn $(WebappTargetGroup) \
--targets Id=$(EC2InstanceId) \
--region $(region) \
--profile $(profile) && echo "Instance is registered in webapp target group"
@aws elbv2 register-targets \
--target-group-arn $(ApiTargetGroup) \
--targets Id=$(EC2InstanceId) \
--region $(region) \
--profile $(profile) && echo "Instance is registered in Api target group"
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ make package
make deploy
```

### after stack created

Add your instance to a new target group.
The `target-group` Makefile rule may not work correctly if multiple m5.large instances are present in the targeted region (another m5.large instance may be picked up). Execute this BEFORE the final step.
```bash
make target-group
```

### finalize

Manually change your cloud9 EC2 instance type to r5a.large.
To finalize the configuration connect to AWS console.
Go to EC2/LoadBlancing/targetGroup and add your instance to a new target group.

### Launch

Expand Down
8 changes: 8 additions & 0 deletions environments/dev.mvars.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bucket=example-template-bucket
role=arn:aws:iam::ACCOUNTID:role/administrative-cloudformation-role
certificateArn=arn:aws:acm:eu-west-1:ACCOUNTID:certificate/CERTIFICATEID
baseDomain=example.com
user=john@example.com
roleSSO=continuous-team-sso-Role-ABCDEFG
profile?=default
region?=us-east-1
9 changes: 9 additions & 0 deletions library/load-balancer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,12 @@ Outputs:
DNSName:
Description: ALB Hostname
Value: !GetAtt Alb.DNSName
Alb:
Description: Alb
Value: !Ref Alb
ApiTargetGroup:
Description: ApiTargetGroup
Value: !Ref ApiTargetGroup
WebappTargetGroup:
Description: WebappTargetGroup
Value: !Ref WebappTargetGroup
9 changes: 9 additions & 0 deletions template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,12 @@ Resources:
Name: !Ref AWS::StackName
SubnetId: !GetAtt VpcStack.Outputs.Subnet1
OwnerArn: !Sub 'arn:aws:sts::${AWS::AccountId}:assumed-role/${RoleSSO}/${User}'


Outputs:
WebappTargetGroup:
Description: WebappTargetGroup
Value: !GetAtt LoadBalancerStack.Outputs.WebappTargetGroup
ApiTargetGroup:
Description: ApiTargetGroup
Value: !GetAtt LoadBalancerStack.Outputs.ApiTargetGroup