Introduction
AWS CloudFormation lets you describe your infrastructure as code. Instead of clicking in the console, you define resources in a YAML or JSON file. This makes your deployments reproducible, versionable, and secure. In 2026, this IaC approach is essential for any serious AWS project. This tutorial walks you through creating a simple stack containing an S3 bucket, from writing the template to deploying it via CLI.
Prerequisites
- AWS account with sufficient IAM permissions
- AWS CLI installed and configured (aws configure)
- Basic knowledge of YAML
- Node.js not required for this beginner tutorial
Basic CloudFormation Template
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Bucket S3 simple pour débutants'
Resources:
MonBucketS3:
Type: AWS::S3::Bucket
Properties:
BucketName: mon-bucket-tutoriel-2026
AccessControl: Private
Tags:
- Key: Environment
Value: TutorialThis minimal template creates a private S3 bucket. The name must be globally unique. Tags help with identification and billing.
Adding Parameters
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Bucket S3 avec paramètres'
Parameters:
BucketNameParam:
Type: String
Default: mon-bucket-tutoriel-2026
Description: Nom unique du bucket S3
Resources:
MonBucketS3:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref BucketNameParam
AccessControl: PrivateParameters make the template reusable. !Ref references the value provided at deployment time.
Template Validation
aws cloudformation validate-template --template-body file://s3-bucket-params.yamlThis command checks syntax and common errors before deployment. It prevents costly failures.
Deploying the Stack
aws cloudformation create-stack \
--stack-name TutorielS3 \
--template-body file://s3-bucket-params.yaml \
--parameters ParameterKey=BucketNameParam,ParameterValue=mon-bucket-unique-2026create-stack starts resource creation. The stack name must be unique within the region.
Update and Delete
aws cloudformation update-stack --stack-name TutorielS3 --template-body file://s3-bucket-params.yaml --parameters ParameterKey=BucketNameParam,ParameterValue=mon-bucket-unique-2026
aws cloudformation delete-stack --stack-name TutorielS3update-stack applies changes. delete-stack removes all resources created by the stack.
Best Practices
- Always use parameters for variable values
- Add tags systematically for cost tracking
- Version your templates in Git
- Test with validate-template before every deployment
- Prefer small, focused stacks over monolithic ones
Common Errors to Avoid
- Non-unique bucket name (409 error)
- Forgetting to configure the AWS CLI region
- Not using --capabilities for IAM resources
- Manually deleting resources managed by CloudFormation
Going Further
Discover our advanced AWS and IaC courses: https://learni-group.com/formations