- Create a project folder
- Open the folder in an editor
- Create the YAML template file
- Add the minimal Resources section
- Optionally set BucketName and additional properties
- Save the file and (optionally) validate/deploy
- Create a project folder
- On your Desktop create a new folder (for example:
cf-project).
- Open that folder in Visual Studio Code
- File → Open Folder → select your
cf-projectfolder.
- Create a new file for the template
- Click the new file icon and name it with a
.yamlextension. Example:s3-bucket.yaml
- Important: do not end filenames with a trailing dot (e.g.,
s3-bucket.is invalid). Use.yamlor.ymlso 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.- Add the minimal template content
- 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.
- (Optional) Specify a bucket name and other properties
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.
- Save the file
- Save
s3-bucket.yamlin your project folder.
- Validate the template locally with the AWS CLI:
- Create or deploy the stack (example using aws cloudformation deploy):
- 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.
| Action | Command example | Notes |
|---|---|---|
| Validate template | aws cloudformation validate-template --template-body file://s3-bucket.yaml | Checks template syntax and basic structure |
| Deploy stack | aws cloudformation deploy --template-file s3-bucket.yaml --stack-name my-s3-stack | Creates or updates the stack |
| View stack events | aws cloudformation describe-stack-events --stack-name my-s3-stack | Useful for troubleshooting |
- Create a folder and a
.yamlfile. - 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.