-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Push S3 | ||
description: Upload built static frontend data to s3 | ||
inputs: | ||
source-dir: | ||
description: Source directory to upload | ||
required: true | ||
aws-region: | ||
description: AWS region | ||
required: true | ||
aws-s3-bucket: | ||
description: AWS S3 bucket | ||
required: true | ||
aws-access-key-id: | ||
description: AWS access key id | ||
required: true | ||
aws-secret-access-key: | ||
description: AWS access key secret | ||
required: true | ||
|
||
runs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- uses: jakejarvis/s3-sync-action@master | ||
with: | ||
args: --follow-symlinks --delete --exclude '.git*/*' | ||
env: | ||
SOURCE_DIR: ${{ input.source-dir }} | ||
AWS_REGION: ${{ input.aws-region }} | ||
AWS_S3_BUCKET: ${{ input.aws-s3-bucket }} | ||
AWS_ACCESS_KEY_ID: ${{ input.aws-access-key-id }} | ||
AWS_SECRET_ACCESS_KEY: ${{ input.aws-secret-access-key }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,46 @@ | ||
import { Stack, StackProps } from 'aws-cdk-lib'; | ||
import { Construct } from 'constructs'; | ||
import * as cdk from 'aws-cdk-lib/core' | ||
import * as s3 from 'aws-cdk-lib/aws-s3'; | ||
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'; | ||
import * as origins from 'aws-cdk-lib/aws-cloudfront-origins'; | ||
import { Stack, StackProps } from 'aws-cdk-lib'; | ||
import { Construct } from 'constructs'; | ||
import { BucketAccessControl, ObjectOwnership } from 'aws-cdk-lib/aws-s3' | ||
import { RemovalPolicy } from 'aws-cdk-lib/core' | ||
|
||
|
||
interface FrontendBucketStackProps extends StackProps { | ||
// domain: string | ||
environment: string, | ||
cloudFrontDistribution: cloudfront.Distribution, | ||
} | ||
|
||
environment: string, | ||
cloudFrontDistribution: cloudfront.Distribution, | ||
} | ||
|
||
export class FrontendBucketStack extends Stack { | ||
readonly bucket: s3.Bucket; | ||
constructor(scope: Construct, id: string, props: FrontendBucketStackProps) { | ||
super(scope, id, props); | ||
super(scope, id, props); | ||
|
||
// FrontEnd S3 bucket - OAI does not support KMS - encryption | ||
this.bucket = new s3.Bucket(this, 'FrontEndBucket', { | ||
bucketName: `aoe-static-content-${props.environment}`, | ||
enforceSSL: true, | ||
accessControl: BucketAccessControl.PRIVATE, | ||
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, | ||
versioned: true, // Required for taking backups | ||
objectOwnership: ObjectOwnership.BUCKET_OWNER_PREFERRED, // Required for restoring backups | ||
lifecycleRules: [ | ||
{ | ||
id: 'ExpireOldVersions', | ||
noncurrentVersionExpiration: cdk.Duration.days(30), // Retain old versions for 30 days | ||
} | ||
], | ||
removalPolicy: RemovalPolicy.RETAIN | ||
}); | ||
|
||
// FrontEnd S3 bucket - OAI does not support KMS - encryption | ||
this.bucket = new s3.Bucket(this, 'FrontEndBucket', { | ||
bucketName: `aoe-static-content-${props.environment}`, | ||
enforceSSL: true, | ||
// encryption: s3.BucketEncryption.KMS, | ||
// encryptionKey: props.s3KmsKey, | ||
}); | ||
// CloudFront OAI, Origin & behaviour | ||
const s3oai = new cloudfront.OriginAccessIdentity(this, 'OAI'); | ||
const s3origin = new origins.S3Origin(this.bucket, { originAccessIdentity: s3oai }); | ||
|
||
// CloudFront OAI, Origin & behaviour | ||
const s3oai = new cloudfront.OriginAccessIdentity(this, 'OAI'); | ||
const s3origin = new origins.S3Origin(this.bucket, { originAccessIdentity: s3oai }); | ||
|
||
props.cloudFrontDistribution.addBehavior('/static/*', s3origin, { | ||
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS | ||
}); | ||
props.cloudFrontDistribution.addBehavior('/static/*', s3origin, { | ||
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters