Skip to content

muses-code-js/IntroCloudformationworkshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CloudFormation Tutorial

This is a step by step guide on how to build and provision your own s3 bucket to host your own static website

Installation

To use CloudFormation you must has a text editor and a AWS account Cloudformation is a template language you can either use YAML or JSON.

It will be great if you're familiar with some of the services as we will be using the CloudFormation service and S3 Service.

Code step by step

Please set up a file it can be test.yaml or mybucket.yaml something that is relevant to the task

  1. Adding the template heading
AWSTemplateFormatVersion: 2010-09-09
Description: "Creating an s3 bucket to host static content"

You will need to add this at the top of the file

  1. Adding the parameter
  S3BucketName: 
    Type: String
    Description: "Name of S3Bucket"

Note: Parameter is a field you can add in when uploading the template in the Cloudformation Service

  1. Adding the resource
  S3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      AccessControl: PublicRead
      WebsiteConfiguration:
        IndexDocument: index.html
        ErrorDocument: error.html
  1. Adding the bucket policy
    Type: AWS::S3::BucketPolicy
    Properties:
      PolicyDocument:
        Id: MyPolicy
        Version: 2012-10-17
        Statement:
          - Sid: PublicReadForGetBucketObjects
            Effect: Allow
            Principal: '*'
            Action: 's3:GetObject'
            Resource: !Join 
              - ''
              - - 'arn:aws:s3:::'
                - !Ref S3Bucket
                - /*
      Bucket: !Ref S3Bucket
  1. The final block of code will look like this:
AWSTemplateFormatVersion: 2010-09-09
Description: "Creating an s3 bucket to host static content"

Parameters:
  S3BucketName: 
    Type: String
    Description: "Name of S3Bucket"
    
Resources:
  S3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      AccessControl: PublicRead
      WebsiteConfiguration:
        IndexDocument: index.html
        ErrorDocument: error.html
        
  BucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
      PolicyDocument:
        Id: MyPolicy
        Version: 2012-10-17
        Statement:
          - Sid: PublicReadForGetBucketObjects
            Effect: Allow
            Principal: '*'
            Action: 's3:GetObject'
            Resource: !Join 
              - ''
              - - 'arn:aws:s3:::'
                - !Ref S3Bucket
                - /*
      Bucket: !Ref S3Bucket
  1. To upload the file ensure you save the file and go to the cloudformation service within the aws console and follow the prompts to upload template. Once stack is GREEN and has passed you can check to validate to see if your bucket is in the console, if validated, you can add your index.html file and hit the endpoint to access your webpage.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages