From 16042a75fb55ae85de0e2a0649c209122d1b2715 Mon Sep 17 00:00:00 2001 From: Kikuo Emoto Date: Tue, 20 Sep 2022 15:31:56 +0900 Subject: [PATCH] feat(cdk-ops): resolve access logs bucket - `resolveCodemongerResourceNames` resolves the name of the S3 bucket for access logs of the development stage. - `CodemongerResources` binds the S3 bucket for access logs of the development stage. issue codemonger-io/codemonger#30 --- cdk-ops/lib/codemonger-resources.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cdk-ops/lib/codemonger-resources.ts b/cdk-ops/lib/codemonger-resources.ts index ff0b32d..b0a9667 100644 --- a/cdk-ops/lib/codemonger-resources.ts +++ b/cdk-ops/lib/codemonger-resources.ts @@ -21,6 +21,8 @@ export type CodemongerResourceNames = { developmentDistributionDomainName: string; /** Name of the S3 bucket for production contents. */ productionContentsBucketName: string; + /** Name of the S3 bucket of CloudFront access logs for development. */ + developmentContentsAccessLogsBucketName: string; }; /** @@ -50,10 +52,16 @@ export async function resolveCodemongerResourceNames(): if (productionContentsBucketName == null) { throw new Error('contents bucket for production is not available'); } + const developmentContentsAccessLogsBucketName = + developmentOutputs.get('ContentsAccessLogsBucketName'); + if (developmentContentsAccessLogsBucketName == null) { + throw new Error('access logs bucket for development is not available'); + } return { developmentContentsBucketName, developmentDistributionDomainName, productionContentsBucketName, + developmentContentsAccessLogsBucketName, }; } @@ -104,6 +112,8 @@ export class CodemongerResources extends Construct { readonly productionContentsBucket: s3.IBucket; /** Domain name for production. */ readonly productionDomainName = CODEMONGER_DOMAIN_NAME; + /** S3 bucket of CloudFront access logs for development. */ + readonly developmentContentsAccessLogsBucket: s3.IBucket; constructor( scope: Construct, @@ -113,6 +123,7 @@ export class CodemongerResources extends Construct { super(scope, id); const { + developmentContentsAccessLogsBucketName, developmentContentsBucketName, developmentDistributionDomainName, productionContentsBucketName, @@ -129,5 +140,10 @@ export class CodemongerResources extends Construct { 'ProductionContentsBucket', productionContentsBucketName, ); + this.developmentContentsAccessLogsBucket = s3.Bucket.fromBucketName( + this, + 'DevelopmentContentsAccessLogsBucket', + developmentContentsAccessLogsBucketName, + ); } }