Skip to content

Commit

Permalink
[ETL-658] Bucket for hosting static HTML files for GX reports (#120)
Browse files Browse the repository at this point in the history
* Create templates to create another s3 bucket where GX reports/artifacts can be hosted from
  • Loading branch information
BryanFauble authored Jun 28, 2024
1 parent 1deebfc commit 22391b0
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/develop/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ raw_bucket_name: recover-dev-raw-data
template_bucket_name: recover-dev-cloudformation
intermediate_bucket_name: recover-dev-intermediate-data
processed_data_bucket_name: recover-dev-processed-data
shareable_artifacts_vpn_bucket_name: recover-dev-shareable-artifacts-vpn
9 changes: 9 additions & 0 deletions config/develop/s3-shareable-artifacts-vpn-bucket.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
template:
type: file
path: s3-bucket-html-hosting.yaml
stack_name: recover-dev-shareable-artifacts-vpn-bucket
parameters:
BucketName: {{ stack_group_config.shareable_artifacts_vpn_bucket_name }}
EnableVpnAccess: "true"
stack_tags:
{{ stack_group_config.default_stack_tags }}
1 change: 1 addition & 0 deletions config/prod/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ raw_bucket_name: recover-raw-data
template_bucket_name: recover-cloudformation
intermediate_bucket_name: recover-intermediate-data
processed_data_bucket_name: recover-processed-data
shareable_artifacts_vpn_bucket_name: recover-shareable-artifacts-vpn
9 changes: 9 additions & 0 deletions config/prod/s3-shareable-artifacts-vpn-bucket.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
template:
type: file
path: s3-bucket-html-hosting.yaml
stack_name: recover-shareable-artifacts-vpn-bucket
parameters:
BucketName: {{ stack_group_config.shareable_artifacts_vpn_bucket_name }}
EnableVpnAccess: "true"
stack_tags:
{{ stack_group_config.default_stack_tags }}
90 changes: 90 additions & 0 deletions templates/s3-bucket-html-hosting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
AWSTemplateFormatVersion: 2010-09-09

Description: >-
This S3 bucket will be used for development and production,
and for storing GX reports to be viewable from the Sage AWS VPN.
Parameters:

BucketName:
Type: String
Description: Name of the bucket.
Default: ''

EnableVpnAccess:
Type: String
Description: Whether to grant the Sage VPN read permissions on the bucket.
AllowedValues:
- "true"
- "false"
Default: "true"

Conditions:
HasBucketName: !Not [!Equals [!Ref BucketName, ""]]
EnableVpnAccess:
!Equals [!Ref EnableVpnAccess, "true"]

Resources:
Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
BucketName: !If [HasBucketName, !Ref BucketName, !Ref 'AWS::NoValue']
AccessControl: Private
OwnershipControls:
Rules:
- ObjectOwnership: BucketOwnerEnforced
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
PublicAccessBlockConfiguration:
BlockPublicAcls : true
BlockPublicPolicy : true
IgnorePublicAcls : true
RestrictPublicBuckets : true

BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref Bucket
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AccountRead
Effect: Allow
Principal:
AWS:
- !Sub '${AWS::AccountId}'
Action:
- 's3:Get*'
- 's3:List*'
Resource:
- !Sub 'arn:aws:s3:::${Bucket}'
- !Sub 'arn:aws:s3:::${Bucket}/*'
- !If
- EnableVpnAccess
- Sid: Allow based on source IP
Effect: Allow
Principal: '*'
Action:
- 's3:GetObject'
Resource:
- !Sub 'arn:aws:s3:::${Bucket}'
- !Sub 'arn:aws:s3:::${Bucket}/*'
Condition:
IpAddress:
aws:SourceIp: '52.44.61.21'
- !Ref AWS::NoValue

Outputs:

BucketName:
Value: !Ref Bucket
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-BucketName'

BucketArn:
Value: !GetAtt Bucket.Arn
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-BucketArn'

0 comments on commit 22391b0

Please sign in to comment.