AWSTemplateFormatVersion: '2010-09-09' Parameters: LatestAmiId: Type: 'AWS::SSM::Parameter::Value' Default: '/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id' Resources: BankIP: Type: AWS::EC2::EIP BankEC2Instance: Description: Ec2 instance with running latest bank-go app. Type: AWS::EC2::Instance Properties: InstanceType: 'm4.large' Monitoring: true SecurityGroups: [!Ref 'InstanceSecurityGroup'] KeyName: 'hendry' ImageId: !Ref LatestAmiId UserData: Fn::Base64: !Sub | #!/bin/bash -xe yum -y update yum -y install git vim git clone https://github.com/nikitsenka/bank-java.git docker build --no-cache -t bank-java -f bank-java/docker/app.dockerfile bank-java docker run --name bank-java -p 80:8080 -e POSTGRES_HOST=13.228.149.43 -d bank-java Tags: - Key: Name Value: bank-app PostgresEC2Instance: Description: Postgres database. Type: AWS::EC2::Instance Properties: InstanceType: 'm4.large' Monitoring: true SecurityGroups: [!Ref 'InstanceSecurityGroup'] KeyName: 'hendry' ImageId: !Ref LatestAmiId UserData: Fn::Base64: !Sub | #!/bin/bash -xe yum -y update yum -y install git vim git clone https://github.com/nikitsenka/bank-go.git docker build --no-cache -t bank-db -f bank-go/docker/db.dockerfile bank-go docker run --name bank-db -p 5432:5432 -e POSTGRES_PASSWORD=test1234 -d bank-db Tags: - Key: Name Value: bank-db InstanceSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Enable SSH access via port 22 SecurityGroupIngress: - IpProtocol: tcp FromPort: 22 ToPort: 22 CidrIp: '0.0.0.0/0' - IpProtocol: tcp FromPort: 80 ToPort: 80 CidrIp: '0.0.0.0/0' - IpProtocol: tcp FromPort: 5432 ToPort: 5432 CidrIp: '0.0.0.0/0' BankIPAssoc: Type: AWS::EC2::EIPAssociation Properties: InstanceId: !Ref 'BankEC2Instance' EIP: !Ref BankIP PostgresIPAssoc: Type: AWS::EC2::EIPAssociation Properties: InstanceId: !Ref 'PostgresEC2Instance' EIP: '13.228.149.43' Outputs: InstanceId: Description: InstanceId of the newly created EC2 instance Value: !Ref 'BankEC2Instance' AZ: Description: Availability Zone of the newly created EC2 instance Value: !GetAtt [BankEC2Instance, AvailabilityZone] PublicDNS: Description: Public DNSName of the newly created EC2 instance Value: !GetAtt [BankEC2Instance, PublicDnsName] PublicIP: Description: Public IP address of the newly created EC2 instance Value: !GetAtt [BankEC2Instance, PublicIp]