Skip to content

Commit

Permalink
feat(cdk-ops): resolve access logs bucket
Browse files Browse the repository at this point in the history
- `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#30
  • Loading branch information
kikuomax committed Sep 24, 2022
1 parent ae2887c commit 16042a7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cdk-ops/lib/codemonger-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down Expand Up @@ -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,
};
}

Expand Down Expand Up @@ -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,
Expand All @@ -113,6 +123,7 @@ export class CodemongerResources extends Construct {
super(scope, id);

const {
developmentContentsAccessLogsBucketName,
developmentContentsBucketName,
developmentDistributionDomainName,
productionContentsBucketName,
Expand All @@ -129,5 +140,10 @@ export class CodemongerResources extends Construct {
'ProductionContentsBucket',
productionContentsBucketName,
);
this.developmentContentsAccessLogsBucket = s3.Bucket.fromBucketName(
this,
'DevelopmentContentsAccessLogsBucket',
developmentContentsAccessLogsBucketName,
);
}
}

0 comments on commit 16042a7

Please sign in to comment.