From 29acdd9a3c068a467f549426ac53a6db8a1fbc94 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Tue, 5 Dec 2023 07:33:02 -0500 Subject: [PATCH] new file: template.yaml modified: templates/chat.html --- template.yaml | 96 +++++++++++++++++++++++++++++++++++++++++++++ templates/chat.html | 5 ++- 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 template.yaml diff --git a/template.yaml b/template.yaml new file mode 100644 index 0000000..7b2344f --- /dev/null +++ b/template.yaml @@ -0,0 +1,96 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: > + Example arch to deploy application in AWS. + + Assumes us-east-1 AMI. + + SAM template to create an EC2 instance, an ALB with a target group on port 5001, + and a security group to allow access over port 5001. + + you will need to allow access to the ALB to certain ips in the security group. + + Don't run this application publicly unless you a generous with your API bill. + +Parameters: + CertificateArn: + Type: String + Description: The ARN of the certificate to attach to the ALB listener. + VPCId: + Type: AWS::EC2::VPC::Id + Description: The VPC ID where the resources will be deployed. + SubnetIds: + Type: List + Description: The list of Subnet IDs for the ALB. + KeyPairName: + Type: AWS::EC2::KeyPair::KeyName + Description: The name of the EC2 KeyPair to allow SSH access to the instance. + +Resources: + EC2InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Security Group for EC2 instance + VpcId: !Ref VPCId + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 5001 + ToPort: 5001 + SourceSecurityGroupId: !Ref ALBSecurityGroup + - IpProtocol: '-1' # Allows all traffic + CidrIp: 172.31.0.0/16 + + EC2Instance: + Type: AWS::EC2::Instance + Properties: + ImageId: ami-0fc5d935ebf8bc3bc + InstanceType: t3.small + KeyName: !Ref KeyPairName + SecurityGroupIds: + - !Ref EC2InstanceSecurityGroup + SubnetId: !Select [0, !Ref SubnetIds] + + ALBSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Security Group for ALB + VpcId: !Ref VPCId + SecurityGroupIngress: + - IpProtocol: '-1' # Allows all traffic + CidrIp: 172.31.0.0/16 + + LoadBalancer: + Type: AWS::ElasticLoadBalancingV2::LoadBalancer + Properties: + Subnets: !Ref SubnetIds + Scheme: internal + SecurityGroups: + - !Ref ALBSecurityGroup + + Listener: + Type: AWS::ElasticLoadBalancingV2::Listener + Properties: + DefaultActions: + - Type: forward + TargetGroupArn: !Ref TargetGroup + LoadBalancerArn: !Ref LoadBalancer + Port: 443 + Protocol: HTTPS + Certificates: + - CertificateArn: !Ref CertificateArn + + TargetGroup: + Type: AWS::ElasticLoadBalancingV2::TargetGroup + Properties: + Port: 5001 + Protocol: HTTP + VpcId: !Ref VPCId + HealthCheckProtocol: HTTP + HealthCheckPort: '5001' + HealthCheckPath: '/' + +Outputs: + + LoadBalancerDNSName: + Description: The DNS name of the ALB + Value: !GetAtt LoadBalancer.DNSName diff --git a/templates/chat.html b/templates/chat.html index 04c9115..3eec2e7 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -182,8 +182,9 @@