정적 페이지를 만들기 위한 CloudFormation 템플릿(사용자 지정 도메인 없음)

11390 단어 CloudFormationAWS
S3을 오리진으로 정적 페이지를 만들고 싶은 경우 CloudFormation 템플릿입니다.

맞춤 도메인은 설정하지 않으므로 xxxxx.cloudfront.net 와 같은 URL 액세스만 가능합니다.
프로덕션 이용은 상정하고 있지 않기 때문에 일시적으로 동작 확인하고 싶을 때라든지 사용하기 위한 것입니다.

S3의 버킷 정책은 CloudFront를 통한 액세스를 허용하기 위한 설정입니다.

S3 버킷 이름과 CloudFront TTL은 필요에 따라 변경하고 싶기 때문에 매개 변수화합니다.AWS::WAF::IPSet 에 관해서는 허가하고 싶은 IP가 매번 다르기 때문에 베타 쓰기.

주의점



이 사이트에 쓰여졌지만 제작 후 기장에 1 시간 정도 기다려야하는 데스
  • h tp // 미야 사쿠라. 하테나 bぉg. 코m/엔트리/2016/12/28/200000
  • ht tp // 마사루-테 ch. 는 bぉ. jp/엔트리/2018/03/27/111327

  • 템플릿


    AWSTemplateFormatVersion: 2010-09-09
    Description: Web Site Hosting Stack
    
    Parameters:
      BucketName:
        Type: String
      CloudFrontTTL:
        Type: Number
        Default: 0
    
    Resources:
      S3Bucket:
        Type: AWS::S3::Bucket
        Properties:
          AccessControl: Private
          BucketName: !Ref BucketName
          WebsiteConfiguration:
            IndexDocument: index.html
            ErrorDocument: error.html
    
      S3BucketPolicy:
        Type: AWS::S3::BucketPolicy
        DependsOn:
          - S3Bucket
          - CloudFrontOriginAccessIdentity
        Properties:
          Bucket: !Ref S3Bucket
          PolicyDocument:
            Version: 2008-10-17
            Statement:
              - Action:
                  - s3:GetObject
                Effect: Allow
                Resource: !Join ["/", [!GetAtt S3Bucket.Arn, "*"]]
                Principal:
                  AWS: !Sub "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ${CloudFrontOriginAccessIdentity}"
    
      CloudFrontOriginAccessIdentity:
        Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
        Properties:
          CloudFrontOriginAccessIdentityConfig:
            Comment: !Sub "${BucketName} access identity"
    
      CloudFrontDistribution:
        Type: AWS::CloudFront::Distribution
        DependsOn:
          - S3Bucket
          - CloudFrontOriginAccessIdentity
          - WebACL
        Properties:
          DistributionConfig:
            Enabled: true
            DefaultCacheBehavior:
              AllowedMethods:
                - HEAD
                - GET
              CachedMethods:
                - HEAD
                - GET
              DefaultTTL: !Ref CloudFrontTTL
              MaxTTL: !Ref CloudFrontTTL
              MinTTL: !Ref CloudFrontTTL
              TargetOriginId: !Sub "${BucketName}-Origin"
              ViewerProtocolPolicy: redirect-to-https
              ForwardedValues:
                QueryString: false
            IPV6Enabled: true
            HttpVersion: http2
            DefaultRootObject: index.html
            WebACLId: !Ref WebACL
            Origins:
              - Id: !Sub "${BucketName}-Origin"
                DomainName: !Sub "${BucketName}.s3.amazonaws.com"
                S3OriginConfig:
                  OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}"
    
      WebACL:
        Type: AWS::WAF::WebACL
        DependsOn:
          - IPSetRule
        Properties:
          DefaultAction:
            Type: BLOCK
          MetricName: WebACLMetric
          Name: !Sub "${BucketName} WebACL"
          Rules:
            - Action:
                Type: ALLOW
              Priority: 0
              RuleId: !Ref IPSetRule
    
      IPSetRule:
        Type: AWS::WAF::Rule
        Properties:
          Name: !Sub "${BucketName} IPSetRule"
          MetricName: IPSetRuleMetric
          Predicates:
            - DataId: !Ref IPSet
              Negated: false
              Type: IPMatch
    
      IPSet:
        Type: AWS::WAF::IPSet
        Properties:
          IPSetDescriptors:
            - Type: IPV4
              # ここは書き換える
              Value: aaa.bbb.ccc.ddd/32
          Name: !Sub "${BucketName} IPSet"
    

    좋은 웹페이지 즐겨찾기