|
| 1 | +# Setup a static website bucket for the sole purpose of |
| 2 | +# redirecting all request to another website. |
| 3 | +AWSTemplateFormatVersion: 2010-09-09 |
| 4 | +Description: >- |
| 5 | + Provision a S3 website with redirect rules |
| 6 | +Parameters: |
| 7 | + RedirectFrom: |
| 8 | + Description: Domain name of the old website (redirected from) |
| 9 | + Type: String |
| 10 | + AllowedPattern: (?!-)[a-zA-Z0-9-.]{1,63}(?<!-) |
| 11 | + ConstraintDescription: must be a valid DNS zone name. |
| 12 | + RedirectTo: |
| 13 | + Description: Domain name of the new website (redirected to) |
| 14 | + Type: String |
| 15 | + AllowedPattern: (?!-)[a-zA-Z0-9-.]{1,63}(?<!-) |
| 16 | + ConstraintDescription: must be a valid DNS zone name. |
| 17 | +Resources: |
| 18 | + WebsiteBucket: |
| 19 | + Type: AWS::S3::Bucket |
| 20 | + Metadata: |
| 21 | + cfn-lint: |
| 22 | + config: |
| 23 | + ignore_checks: [W3045] |
| 24 | + Properties: |
| 25 | + PublicAccessBlockConfiguration: |
| 26 | + BlockPublicAcls: false |
| 27 | + BlockPublicPolicy: false |
| 28 | + IgnorePublicAcls: false |
| 29 | + RestrictPublicBuckets: false |
| 30 | + BucketName: !Ref RedirectFrom |
| 31 | + WebsiteConfiguration: |
| 32 | + RedirectAllRequestsTo: |
| 33 | + HostName: !Ref RedirectTo |
| 34 | + Protocol: https |
| 35 | + WebsiteBucketPolicy: |
| 36 | + Type: 'AWS::S3::BucketPolicy' |
| 37 | + Properties: |
| 38 | + Bucket: !Ref WebsiteBucket |
| 39 | + PolicyDocument: |
| 40 | + Version: '2012-10-17' |
| 41 | + Statement: |
| 42 | + - Effect: Allow |
| 43 | + Principal: '*' |
| 44 | + Action: 's3:GetObject' |
| 45 | + Resource: !Sub '${WebsiteBucket.Arn}/*' |
| 46 | +Outputs: |
| 47 | + BucketWebsiteUrl: |
| 48 | + Value: !GetAtt WebsiteBucket.WebsiteURL |
| 49 | + Description: URL for website redirector |
| 50 | + Export: |
| 51 | + Name: !Sub '${AWS::StackName}-BucketWebsiteUrl' |
| 52 | + WebsiteBucket: |
| 53 | + Value: !Ref WebsiteBucket |
| 54 | + Description: The bucket containing the website redirect rules |
| 55 | + Export: |
| 56 | + Name: !Sub '${AWS::StackName}-WebsiteBucket' |
0 commit comments