{
"Resources":{
"VPC":{
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsSupport": true,
"EnableDnsHostnames":true
}
},
"InternetGateway":{
"Type": "AWS::EC2::InternetGateway",
"Properties": {
}
},
"InternetGatewayAttachment":{
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"InternetGatewayId":{
"Ref": "InternetGateway"
},
"VpcId": {
"Ref": "VPC"
}
}
},
"PublicSubnet": {
"Type":"AWS::EC2::Subnet",
"Properties": {
"VpcId":{
"Ref": "VPC"
},
"AvailabilityZone": "us-east-1a",
"CidrBlock": "10.0.1.0/24",
"MapPublicIpOnLaunch": true
}
},
"PublicRouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "VPC"
}
}
},
"DefaultPublicRoute":{
"Type": "AWS::EC2::Route",
"DependsOn": "InternetGatewayAttachment",
"Properties":{
"RouteTableId": {
"Ref": "PublicRouteTable"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "InternetGateway"
}
}
},
"PublicSubnetRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId":{
"Ref": "PublicRouteTable"
},
"SubnetId": {
"Ref": "PublicSubnet"
}
}
},
"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties":{
"GroupDescription": "Allow SSH Access",
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": "0.0.0.0/0"
}
],
"VpcId":{
"Ref": "VPC"
}
}
},
"EC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-00874d747dde814fa",
"InstanceType": "t2.micro",
"KeyName": "laracastsec2",
"SubnetId": {
"Ref": "PublicSubnet"
},
"SecurityGroupIds": [
{
"Ref": "SecurityGroup"
}
]
}
}
}
}
This episode is for
subscribers only.
For the cost of a pizza, you'll gain access to this and hundreds of hours worth of content from top developers in the Laravel space!
Laracasts taught me more in a month than I've learnt at university in two years. Absolutely indispensable.
Robb Lewis
@robertocannella Thanks for sharing
hello
I like the idea of managing the server infrastructure with code. Especially when working with a team to know which services are running. However this config is overly complicated so I'd rather do it from the interface.
Hi, I am trying to create an AWS CLOUD FORMATION stack but getting an error of imageId in this series you did not show how to create AMIs and get the ImageId for AWS::EC2::Instance the id that you are using is for your AWS console not in our JSON file can you please explain how to do it?
The following resource(s) failed to create: [InternetGatewayAttachment, EC2Instance, PublicRouteTable]. Rollback requested by user.
Root Cause:
The image id '[ami-00874d747dde814fa]' does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidAMIID.NotFound; Request ID: 6f8401b3-1bc1-4db4-bd21-c8300a60417b; Proxy: null)
Here is the JSON File
{
"Resources": {
"VPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsSupport": true,
"EnableDnsHostnames": true
}
},
"InternetGateway": {
"Type": "AWS::EC2::InternetGateway",
"Properties": {}
},
"InternetGatewayAttachment": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties":{
"InternetGatewayId": {
"Ref": "InternetGateway"
},
"VpcId": {
"Ref": "VPC"
}
}
},
"PublicSubnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"AvailabilityZone": "us-east-2a",
"CidrBlock": "10.0.1.0/24",
"MapPublicIpOnLaunch": true
}
},
"PublicRouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": { "Ref": "VPC" }
}
},
"DefaultPublicRoute": {
"Type": "AWS::EC2::Route",
"DependsOn": "InternetGatewayAttachment",
"Properties": {
"RouteTableId": {
"Ref": "PublicRouteTable"
},
"DestinationCidrBlock": "0.0.0.0",
"GatewayId": {
"Ref": "InternetGateway"
}
}
},
"PublicSubnetRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "PublicRouteTable"
},
"SubnetId": {
"Ref": "PublicSubnet"
}
}
},
"SecurityGroup":{
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Allow SSH Access",
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": "0.0.0.0/0"
}
],
"VpcId":{
"Ref": "VPC"
}
}
},
"EC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-00874d747dde814fa",
"InstanceType": "t2.micro",
"KeyName": "tapinns",
"SubnetId":{
"Ref": "PublicSubnet"
},
"SecurityGroupIds": [
{
"Ref": "SecurityGroup"
}
]
}
}
}
}
@laracasts2020 I have same problem with you but I found the solution.
Just make sure your KeyName created and exist before you added in the EC2Instance Properties.
Does anyone have any thoughts on using Terraform instead of CloudFormation?
Just curious... I'm new to DevOps and had not heard of CloudFormation until I saw this video. I'm aware of Terraform as an IAC tool that integrates with AWS. It seems that both Terraform and CloudFormation do the same thing, with the benefit that if you're using CloudFormation you don't even need to worry about integrating with your AWS account. What's the point of using Terraform then? Is it better than CloudFormation?
You get a window into a seasoned developer's mind and workflow for the price of an Uber. I can't overstate the value of a Laracasts subscription.
Caleb Porzio — Creator of Livewire
