8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CloudFormationでS3を作成する

8
Last updated at Posted at 2019-10-27

CloudFormationでS3のバケットを作成。

Log保管用のバケットとコンテンツデータ(アップロード・添付ファイルなど)の保管用の二つのバケットを作ってみました。

方針

Logファイル

  • バージョニング(世代管理)はなし
  • 180日後にGlacierに移行
  • 移行後365日で原稿世代のデータは削除

Contentsファイル

アップロードされたファイルや、静的ファイルの保管先に利用

  • バージョニング(世代管理)あり
  • バージョニングされたデータ(過去のデータ)は180日後にGlacierに移行
  • 移行後365日でバージョニングされたデータ(過去のデータ)は削除
s3-sample.yml
AWSTemplateFormatVersion: 2010-09-09
Description: Create S3 for LifeCycle
Parameters:
  BucketNameLog:
    Type: String
    Default: xxxxxxxx
    Description: A name for the log bucket.
  BucketNameContents:
    Type: String
    Default: xxxxxxxx
    Description: A name for the contents bucket.
    
Resources:
  S3Log:
    Type: "AWS::S3::Bucket"
    Properties:
      BucketName: !Ref BucketNameLog
      BucketEncryption:
        ServerSideEncryptionConfiguration:
          - ServerSideEncryptionByDefault:
              SSEAlgorithm: AES256
      LifecycleConfiguration:
        Rules:
          - Id: !Join ['-', [!Ref 'BucketNameLog', 'log-LifeCycle']]
            Status: Enabled
            Prefix: log/
            # 365日経過したら削除
            ExpirationInDays: 365
            # 180日経過したらS3 clacierに移行する
            Transitions:
              - StorageClass: GLACIER
                TransitionInDays: 180
  S3Contents:
    Type: 'AWS::S3::Bucket'
    Properties:
      BucketName: !Ref BucketNameContents
      VersioningConfiguration:
        Status: Enabled
      BucketEncryption:
        ServerSideEncryptionConfiguration:
          - ServerSideEncryptionByDefault:
              SSEAlgorithm: AES256  
      LifecycleConfiguration:
        Rules:
          - Id: !Join ['-', [!Ref 'BucketNameContents', 'Contents-LifeCycle']]
            Status: Enabled
            # バージョニングされているデータは180日経過したらS3 clacierに移行する
            NoncurrentVersionTransition:
                StorageClass: GLACIER
                TransitionInDays: 180
            # バージョニングされているデータは365日経過したら削除する
            NoncurrentVersionExpirationInDays: 365
            
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?