Skip to main content
Welcome — in this lesson we’ll create a minimal CloudFormation template (YAML) that provisions an Amazon S3 bucket. The workflow is simple and focused: create a project folder, add a YAML template file, and author the minimal CloudFormation content that instructs AWS to create the S3 bucket. Steps (high level)
  1. Create a project folder
  2. Open the folder in an editor
  3. Create the YAML template file
  4. Add the minimal Resources section
  5. Optionally set BucketName and additional properties
  6. Save the file and (optionally) validate/deploy
  7. Create a project folder
  • On your Desktop create a new folder (for example: cf-project).
  1. Open that folder in Visual Studio Code
  • File → Open Folder → select your cf-project folder.
  1. Create a new file for the template
  • Click the new file icon and name it with a .yaml extension. Example:
    • s3-bucket.yaml
  • Important: do not end filenames with a trailing dot (e.g., s3-bucket. is invalid). Use .yaml or .yml so CloudFormation recognizes the format.
YAML is generally preferred for CloudFormation because it’s more concise and easier to scan than JSON. Use .yaml or .yml as the file extension.
  1. Add the minimal template content
A CloudFormation template needs at least a top-level Resources section. In Resources you declare a logical ID (a template-local name) and the Type that tells CloudFormation which AWS resource to create. Example minimal template:
Resources:
  MyS3Bucket:
    Type: AWS::S3::Bucket
Explanation:
  • Resources: — required top-level section where every resource to be created is listed.
  • MyS3Bucket — the logical ID (template-local identifier). Choose any valid name; it becomes a reference key inside the template.
  • Type: AWS::S3::Bucket — instructs CloudFormation to create an S3 bucket.
  1. (Optional) Specify a bucket name and other properties
To provision a bucket with a specific name, include a Properties block with BucketName. Remember bucket names must be globally unique across all AWS and must follow S3 naming rules. Example with a specified bucket name:
Resources:
  MyS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-unique-bucket-name-12345
BucketName must be globally unique and conform to S3 naming rules. If the name is already taken or invalid, stack creation will fail. Prefer letting CloudFormation generate a name, or ensure uniqueness by adding a random suffix.
  1. Save the file
  • Save s3-bucket.yaml in your project folder.
Optional — validate and deploy the template
  • Validate the template locally with the AWS CLI:
aws cloudformation validate-template --template-body file://s3-bucket.yaml
  • Create or deploy the stack (example using aws cloudformation deploy):
aws cloudformation deploy \
  --template-file s3-bucket.yaml \
  --stack-name my-s3-stack \
  --region us-east-1
Notes:
  • Ensure your AWS credentials and region are configured (aws configure) and that your IAM principal has permission to create S3 buckets and CloudFormation stacks.
  • For simple S3 bucket templates, you typically don’t need extra capabilities flags. If your template uses IAM resources, add --capabilities CAPABILITY_NAMED_IAM.
Quick reference — Commands table
ActionCommand exampleNotes
Validate templateaws cloudformation validate-template --template-body file://s3-bucket.yamlChecks template syntax and basic structure
Deploy stackaws cloudformation deploy --template-file s3-bucket.yaml --stack-name my-s3-stackCreates or updates the stack
View stack eventsaws cloudformation describe-stack-events --stack-name my-s3-stackUseful for troubleshooting
Summary
  • Create a folder and a .yaml file.
  • Add a required Resources section with a logical ID and Type AWS::S3::Bucket.
  • Optionally add Properties (for example, BucketName) but ensure global uniqueness.
  • Validate locally and deploy via AWS CLI, Console, or your CI/CD pipeline.
Links and references Well done — you now have a base CloudFormation YAML template that creates an S3 bucket.

Watch Video