There are pre-defined templates available in AWS which you can use and customize according to your requirement.
AWS CloudFormation Template usually written in YAML or JSON format
Its syntax includes
AWSTemplateFormatVersion [usually 2010-09-09 as latest]
Description [basic idea about your template]
Metadata [label your parameters]
Parameters [data about parameters]
Mappings
Resources [define all your required aws resources here]
Condtions
Output [can be your end result]
A sample json resource for S3 may look like
{
"Resources": {
"democf": {
"Type": "AWS::S3::Bucket",
"Properties": {}
}
}
}
the moment you create a stack, it will store your stack into S3 generating a URL for it
ex:
https://s3.ap-south-1.amazonaws.com/cf-templates-194b45c-ap-south-1/202118-demox5dr
The best sample template to start with cloudFormation is the LAMP stack (Linux Apache Mysql Php)
Navigate to: services > cloudFormation > Create Stack > use a sample template > LAMP stack
at this stage, you do have an option to customize your stack, choose View in Designer to customize it and edit the json/yaml as per requirement and create a stack by clicking a small button
a glimpse from designer |
once you create the task it will show the status in events
Verification
- You should be able to see all the four resources in aws-gui
- navigate to EC2 dashboard you will see a new instance created using the above stack
- hit public IP of EC2-Linux instance you will be able to see a PHP page hosted by Apache
- connect to EC2 and test your Mysql by running the below command.
$ mysql -h localhost -P 3306 -u dbuser -p dbpass
// if all goes well you should be able to connect to your sql db
and that's it. This is how you can start with your first cloudFormation template in AWS.
No comments:
Post a Comment