AWS/CloudFormation
From r00tedvw.com wiki
(Difference between revisions)
| Line 7: | Line 7: | ||
*Bucket Policy allowing access to all resources. | *Bucket Policy allowing access to all resources. | ||
*Export the S3 bucket name, Secure URL, and Website URL for usage in other templates. | *Export the S3 bucket name, Secure URL, and Website URL for usage in other templates. | ||
| + | <div class="toccolours mw-collapsible mw-collapsed"> | ||
| + | AWS Template: | ||
| + | <div class="mw-collapsible-content"> | ||
<nowiki>AWSTemplateFormatVersion: 2010-09-09 | <nowiki>AWSTemplateFormatVersion: 2010-09-09 | ||
| Line 65: | Line 68: | ||
Export: | Export: | ||
Name: !Sub "${AWS::StackName}-S3WebsiteURL"</nowiki> | Name: !Sub "${AWS::StackName}-S3WebsiteURL"</nowiki> | ||
| + | </div> | ||
| + | </div> | ||
Revision as of 17:27, 4 December 2019
Quick Reference | AWS CLI | CloudFormation
Template Examples
S3 Bucket
Here is a CloudFormation Template (in yaml) that I used to create a S3 bucket with the following requirements:
- Public Read
- 7 day retention policy
- Bucket Policy allowing access to all resources.
- Export the S3 bucket name, Secure URL, and Website URL for usage in other templates.
AWS Template:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
BranchName:
Description: Branch Name
Type: String
Resources:
S3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
LifecycleConfiguration:
Rules:
- Status: Enabled
ExpirationInDays: 7
WebsiteConfiguration:
IndexDocument: index.html
S3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: S3Bucket
PolicyDocument:
Statement:
- Sid: AddPerm
Effect: 'Allow'
Principal: '*'
Action:
- 's3:GetObject'
Resource:
Fn::Join:
- ''
- - 'arn:aws:s3:::'
- Ref: 'S3Bucket'
- '/**'
Outputs:
S3BucketName:
Value:
Ref: S3Bucket
Description: The S3 bucket name
Export:
Name:
Fn::Sub: ${AWS::StackName}-S3BucketName
S3BucketSecureURL:
Value:
Fn::Join: ['', ['http://', !GetAtt [S3Bucket, DomainName]]]
Description: Name of S3 bucket to hold Tenant Management website content
S3WebsiteURL:
Description: Website URL of the S3 Bucket
Value: !Select [1, !Split ["//", !GetAtt S3Bucket.WebsiteURL]]
Export:
Name: !Sub "${AWS::StackName}-S3WebsiteURL"