Laracasts mascots - robot, elephant, monster, computer.

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!

8

Infrastructure as Code

Episode
06
Published
Mar 6th, 2023
Run Time
12m 59s
Topic
AWS
themsaid's avatar
Your Instructor
robertocannella's avatar
robertocannella
3 years ago

{ "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" } ] } } } }

CreativeCoder's avatar
CreativeCoder
2 years ago

hello

clem's avatar
clem
2 years ago

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.

laracasts2020's avatar
laracasts2020
2 years ago

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)
laracasts2020's avatar
laracasts2020
2 years ago

Here is the JSON File

zunnurs01's avatar
zunnurs01
2 years ago

@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.

EBonocore's avatar
EBonocore
1 year ago

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?

Your avatar

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

Subscribe to unlock full access.