feat: final template.yaml
This commit is contained in:
+54
-72
@@ -1,99 +1,81 @@
|
|||||||
AWSTemplateFormatVersion: '2010-09-09'
|
AWSTemplateFormatVersion: '2010-09-09'
|
||||||
Description: Deploy EC2 instance using a specific AMI, configure a security group with ingress rules for SSH and port 3001, and create VPC and subnet.
|
Description: 'Create an EC2 instance with port 3001 open and auto-generate network resources'
|
||||||
|
|
||||||
Parameters:
|
|
||||||
AMI:
|
|
||||||
Type: String
|
|
||||||
Default: ami-021141a79f4c8fc02 # Default to your AMI ID if needed
|
|
||||||
InstanceType:
|
|
||||||
Type: String
|
|
||||||
Default: t3.large # Default to t3.large
|
|
||||||
VpcCidrBlock:
|
|
||||||
Type: String
|
|
||||||
Default: 10.0.0.0/16 # Default to a private network range
|
|
||||||
SubnetCidrBlock:
|
|
||||||
Type: String
|
|
||||||
Default: 10.0.1.0/24 # Default to a smaller subnet range
|
|
||||||
SecurityGroupName:
|
|
||||||
Type: String
|
|
||||||
Default: ShuffleSG
|
|
||||||
|
|
||||||
Resources:
|
Resources:
|
||||||
# Create the VPC
|
|
||||||
VPC:
|
VPC:
|
||||||
Type: AWS::EC2::VPC
|
Type: AWS::EC2::VPC
|
||||||
Properties:
|
Properties:
|
||||||
CidrBlock: !Ref VpcCidrBlock
|
CidrBlock: 10.0.0.0/16
|
||||||
EnableDnsSupport: "true"
|
EnableDnsHostnames: true
|
||||||
EnableDnsHostnames: "true"
|
EnableDnsSupport: true
|
||||||
Tags:
|
|
||||||
- Key: Name
|
|
||||||
Value: ShuffleVPC
|
|
||||||
|
|
||||||
# Create the Subnet within the VPC
|
PublicSubnet:
|
||||||
Subnet:
|
|
||||||
Type: AWS::EC2::Subnet
|
Type: AWS::EC2::Subnet
|
||||||
Properties:
|
Properties:
|
||||||
CidrBlock: !Ref SubnetCidrBlock
|
|
||||||
VpcId: !Ref VPC
|
VpcId: !Ref VPC
|
||||||
AvailabilityZone: !Select [ 0, !GetAZs '' ]
|
AvailabilityZone: !Select
|
||||||
MapPublicIpOnLaunch: "true"
|
- 0
|
||||||
Tags:
|
- !GetAZs
|
||||||
- Key: Name
|
Ref: 'AWS::Region'
|
||||||
Value: ShuffleSubnet
|
CidrBlock: 10.0.1.0/24
|
||||||
|
MapPublicIpOnLaunch: true
|
||||||
|
|
||||||
|
InternetGateway:
|
||||||
|
Type: AWS::EC2::InternetGateway
|
||||||
|
|
||||||
|
AttachGateway:
|
||||||
|
Type: AWS::EC2::VPCGatewayAttachment
|
||||||
|
Properties:
|
||||||
|
VpcId: !Ref VPC
|
||||||
|
InternetGatewayId: !Ref InternetGateway
|
||||||
|
|
||||||
|
PublicRouteTable:
|
||||||
|
Type: AWS::EC2::RouteTable
|
||||||
|
Properties:
|
||||||
|
VpcId: !Ref VPC
|
||||||
|
|
||||||
|
PublicRoute:
|
||||||
|
Type: AWS::EC2::Route
|
||||||
|
DependsOn: AttachGateway
|
||||||
|
Properties:
|
||||||
|
RouteTableId: !Ref PublicRouteTable
|
||||||
|
DestinationCidrBlock: 0.0.0.0/0
|
||||||
|
GatewayId: !Ref InternetGateway
|
||||||
|
|
||||||
|
SubnetRouteTableAssociation:
|
||||||
|
Type: AWS::EC2::SubnetRouteTableAssociation
|
||||||
|
Properties:
|
||||||
|
SubnetId: !Ref PublicSubnet
|
||||||
|
RouteTableId: !Ref PublicRouteTable
|
||||||
|
|
||||||
# Create the Security Group for the EC2 instance
|
|
||||||
SecurityGroup:
|
SecurityGroup:
|
||||||
Type: AWS::EC2::SecurityGroup
|
Type: AWS::EC2::SecurityGroup
|
||||||
Properties:
|
Properties:
|
||||||
GroupName: !Ref SecurityGroupName
|
GroupDescription: Allow port 3001 access
|
||||||
VpcId: !Ref VPC
|
VpcId: !Ref VPC
|
||||||
SecurityGroupIngress:
|
SecurityGroupIngress:
|
||||||
- IpProtocol: tcp
|
|
||||||
FromPort: 22
|
|
||||||
ToPort: 22
|
|
||||||
CidrIp: 0.0.0.0/0 # Allow SSH from anywhere
|
|
||||||
- IpProtocol: tcp
|
- IpProtocol: tcp
|
||||||
FromPort: 3001
|
FromPort: 3001
|
||||||
ToPort: 3001
|
ToPort: 3001
|
||||||
CidrIp: 0.0.0.0/0 # Allow traffic on port 3001 from anywhere
|
CidrIp: 0.0.0.0/0
|
||||||
|
- IpProtocol: tcp
|
||||||
|
FromPort: 22
|
||||||
|
ToPort: 22
|
||||||
|
CidrIp: 0.0.0.0/0
|
||||||
|
|
||||||
# Create an EC2 instance
|
|
||||||
EC2Instance:
|
EC2Instance:
|
||||||
Type: AWS::EC2::Instance
|
Type: AWS::EC2::Instance
|
||||||
Properties:
|
Properties:
|
||||||
ImageId: !Ref AMI
|
InstanceType: t3.large
|
||||||
InstanceType: !Ref InstanceType
|
SecurityGroupIds:
|
||||||
NetworkInterfaces:
|
- !Ref SecurityGroup
|
||||||
- AssociatePublicIpAddress: true
|
SubnetId: !Ref PublicSubnet
|
||||||
DeviceIndex: 0
|
ImageId: ami-04996ef73316c465c
|
||||||
GroupSet:
|
|
||||||
- !Ref SecurityGroup
|
|
||||||
SubnetId: !Ref Subnet
|
|
||||||
Tags:
|
|
||||||
- Key: Name
|
|
||||||
Value: Shuffle AMI Test Instance
|
|
||||||
CpuOptions:
|
|
||||||
CoreCount: 1
|
|
||||||
ThreadsPerCore: 1
|
|
||||||
PrivateDnsNameOptions:
|
|
||||||
HostnameType: "ip-name"
|
|
||||||
EnableResourceNameDnsARecord: true
|
|
||||||
EnableResourceNameDnsAAAARecord: false
|
|
||||||
|
|
||||||
Outputs:
|
Outputs:
|
||||||
InstanceId:
|
InstanceId:
|
||||||
Description: "Instance ID of the created EC2 instance"
|
Description: InstanceId of the newly created EC2 instance
|
||||||
Value: !Ref EC2Instance
|
Value: !Ref EC2Instance
|
||||||
PublicIP:
|
PublicDNS:
|
||||||
Description: "Public IP address of the EC2 instance"
|
Description: Public DNSName of the newly created EC2 instance
|
||||||
Value: !GetAtt EC2Instance.PublicIp
|
Value: !GetAtt EC2Instance.PublicDnsName
|
||||||
VPCId:
|
|
||||||
Description: "VPC ID"
|
|
||||||
Value: !Ref VPC
|
|
||||||
SubnetId:
|
|
||||||
Description: "Subnet ID"
|
|
||||||
Value: !Ref Subnet
|
|
||||||
SecurityGroupId:
|
|
||||||
Description: "Security Group ID"
|
|
||||||
Value: !Ref SecurityGroup
|
|
||||||
Reference in New Issue
Block a user