aws cloudformation hello world

Cloudformation is quite cool and this is an example of how to do a simple s3 bucket creations.

AWSTemplateFormatVersion: '2010-09-09'
Description: Simple Lambda Hello World example
 
Resources:
  MyS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub "jeremywootestbucketstore123"

The resources followed by MyS3Bucket (this can be any meaningful name). Type is mandatory and it has to be pre-defined and we're creating a s3 bucket. As for the properties, it has to be references from the documentation. 

And then we have outputs - where we can see what the ARN and websiteURL for our s3 bucket. Notice that this doesn't allow you to shared with other resources.

Outputs:
  BucketName:
    Description: The name of the S3 bucket.
    Value: !Ref MyS3Bucket
    Export:
      Name: MyS3Bucket

  BucketArn:
    Description: The ARN of the S3 bucket.
    Value: !GetAtt MyS3Bucket.Arn

  BucketWebsiteURL:
    Description: The URL for the S3 bucket if configured for website hosting.
    Value: !GetAtt MyS3Bucket.WebsiteURL


To make it shareable to other resources, we simply add Export, as seen here:- 


Outputs:
  BucketName:
    Description: The name of the S3 bucket.
    Value: !Ref MyS3Bucket
    Export:
      Name: MyS3Bucket

  BucketArn:
    Description: The ARN of the S3 bucket.
    Value: !GetAtt MyS3Bucket.Arn
    Export:
      Name: !Sub "${AWS::StackName}-BucketArn"

  BucketWebsiteURL:
    Description: The URL for the S3 bucket if configured for website hosting.
    Value: !GetAtt MyS3Bucket.WebsiteURL
    Export:
      Name: !Sub "${AWS::StackName}-BucketWebsiteURL"

To create this stack, simply run

aws cloudformation create-stack   --stack-name lambda-store   --template-body file://store.yaml   --capabilities CAPABILITY_NAMED_IAM   --region ap-southeast-2

And then once you've created it, you can see we have the outputs and exports. 




Repository link here:-

https://github.com/kepungnzai/cloudformation-helloworld





Comments

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type