diff --git a/README.md b/README.md index 164a9fb..afcf8cd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # aws-snippets -Sample CloudFormation/CLI/boto3 templates for CS4740. +Sample CloudFormation/CLI/boto3 templates for SDS. diff --git a/ec2/cloudformation/README.md b/ec2/cloudformation/README.md index ae96e43..6bcc81c 100644 --- a/ec2/cloudformation/README.md +++ b/ec2/cloudformation/README.md @@ -1,3 +1,5 @@ # CloudFormation Stacks -[![EC2 Instance with S3 IAM Profile](../../images/launch-stack.png)](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/quickcreate?stackName=ds2002-base-instance&templateURL=https://sds-cloud-snippets.s3.amazonaws.com/ec2/cloudformation/ec2-with-s3.yaml) - Ubuntu 22.04LTS instance second hard drive attached. (Default user `ubuntu`) [Template](ec2-with-s3.yaml) +[![EC2 Instance for FastAPI](../../images/launch-stack.png)](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/quickcreate?stackName=ds2002-fastapi-instance&templateURL=https://sds-cloud-snippets.s3.amazonaws.com/ec2/cloudformation/ec2-ds2002-base.yaml) - Ubuntu 22.04LTS instance for FastAPI. (Default user `ubuntu`) [Template](ec2-ds2002-base.yaml) +[![EC2 Instance](../../images/launch-stack.png)](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/quickcreate?stackName=ds2002-base-instance&templateURL=https://sds-cloud-snippets.s3.amazonaws.com/ec2/cloudformation/ec2-with-s3.yaml) - Ubuntu 22.04LTS instance second hard drive attached. (Default user `ubuntu`) [Template](ec2-with-s3.yaml) + diff --git a/ec2/cloudformation/ec2-ds2002-base.yaml b/ec2/cloudformation/ec2-ds2002-base.yaml new file mode 100644 index 0000000..d2eaadb --- /dev/null +++ b/ec2/cloudformation/ec2-ds2002-base.yaml @@ -0,0 +1,71 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: >- + AWS CloudFormation template: This template builds an EC2 instance attached to + an elastic IP address. Bootstrapping for basic next steps. +Parameters: + InstanceType: + Description: EC2 instance type + Type: String + Default: t2.micro + AllowedValues: + - t1.micro + - t2.nano + - t2.micro + - t2.small + - t2.medium + ConstraintDescription: must be a valid EC2 instance type. + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instances + Type: 'AWS::EC2::KeyPair::KeyName' + ConstraintDescription: must be the name of an existing EC2 KeyPair. + +Resources: + + EC2Instance: + Type: 'AWS::EC2::Instance' + Properties: + InstanceType: !Ref InstanceType + SecurityGroups: + - !Ref InstanceSecurityGroup + KeyName: !Ref KeyName + ImageId: ami-0c7217cdde317cfec + Tags: + - Key: Name + Value: ds2002-ec2-instance + UserData: + Fn::Base64: + !Sub | + #!/bin/bash -xe + apt update && apt install git python3-pip -y + python3 -m pip install boto3 awscli + + InstanceSecurityGroup: + Type: 'AWS::EC2::SecurityGroup' + Properties: + GroupDescription: Enable SSH access + 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' + + IPAddress: + Type: 'AWS::EC2::EIP' + + IPAssoc: + Type: 'AWS::EC2::EIPAssociation' + Properties: + InstanceId: !Ref EC2Instance + EIP: !Ref IPAddress + +Outputs: + InstanceId: + Description: InstanceId of the new EC2 instance + Value: !Ref EC2Instance + InstanceIPAddress: + Description: IP address of the new EC2 instance + Value: !Ref IPAddress