CloudFormationでS3バケットを作成してバケットポリシーを設定してみたメモ。
手順
- CreateS3Bucket.yml をローカルに作成する。
AWSTemplateFormatVersion: '2010-09-09' Description: This CloudFormation template to create S3 Bucket Parameters: S3BucketName: Description: Type of this BacketName. Type: String Resources: S3Bucket: Type: AWS::S3::Bucket Properties: BucketName: !Sub ${S3BucketName} AccessControl: Private PublicAccessBlockConfiguration: BlockPublicAcls: True BlockPublicPolicy: True IgnorePublicAcls: True RestrictPublicBuckets: True S3BucketPolicy: Type: AWS::S3::BucketPolicy Properties: Bucket: Ref: "S3Bucket" PolicyDocument: Version: "2012-10-17" Statement: - Action: - "s3:GetObject" Effect: "Allow" Resource: Fn::Join: - "" - - "arn:aws:s3:::" - Ref: "S3Bucket" - "/*" Principal: AWS: Fn::Join: - "" - - "arn:aws:iam::" - Ref: "AWS::AccountId" - ":root" Outputs: S3BucketName: Value: !Ref S3Bucket
- AWSマネジメントコンソール-[CloudFormation]-[スタックの作成]をクリック