0
0
AWScloud~5 mins

Resources section in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you create cloud infrastructure with AWS CloudFormation, you need to tell it what resources to make. The Resources section is where you list all the things like servers, databases, or networks you want AWS to set up for you.
When you want to create a virtual server (EC2 instance) automatically.
When you need to set up a database (RDS) as part of your app environment.
When you want to create a storage bucket (S3) to hold files.
When you want to define a network setup like a Virtual Private Cloud (VPC).
When you want to manage all your cloud resources in one file for easy updates.
Config File - template.yaml
template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: Simple EC2 instance setup
Resources:
  MyEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-0c55b159cbfafe1f0
      InstanceType: t2.micro
      Tags:
        - Key: Name
          Value: MyTestInstance

The AWSTemplateFormatVersion defines the template version.

The Description explains what this template does.

The Resources section lists all AWS resources to create. Here, MyEC2Instance is a virtual server.

Type tells AWS what kind of resource it is.

Properties set details like the server image and size.

Commands
This command tells AWS CloudFormation to create a new stack named 'my-test-stack' using the template file. It starts building the resources defined in the Resources section.
Terminal
aws cloudformation create-stack --stack-name my-test-stack --template-body file://template.yaml
Expected OutputExpected
An error occurred (ValidationError) when calling the CreateStack operation: Stack with id my-test-stack already exists
--stack-name - Names the stack for easy identification.
--template-body - Specifies the local template file to use.
This command checks the status and details of the stack named 'my-test-stack' to see if the resources were created successfully.
Terminal
aws cloudformation describe-stacks --stack-name my-test-stack
Expected OutputExpected
{ "Stacks": [ { "StackName": "my-test-stack", "StackStatus": "CREATE_COMPLETE", "CreationTime": "2024-06-01T12:00:00.000Z" } ] }
--stack-name - Specifies which stack to describe.
Key Concept

If you remember nothing else from this pattern, remember: the Resources section is where you list every AWS resource you want CloudFormation to create and manage.

Common Mistakes
Leaving out the Resources section or misspelling resource names.
CloudFormation won't know what to create and will give an error or create nothing.
Always include a properly named Resources section with valid resource definitions.
Using incorrect resource Types or invalid property names.
CloudFormation will fail to create the stack due to validation errors.
Check AWS documentation for correct resource Types and property names before writing the template.
Summary
The Resources section in a CloudFormation template lists all AWS resources to create.
Each resource needs a unique name, a Type, and Properties to define it.
Use AWS CLI commands to create the stack and check its status after deployment.