@@ -2,6 +2,7 @@ import * as cdk from '@aws-cdk/core';
22import * as iam from '@aws-cdk/aws-iam' ;
33import * as kms from '@aws-cdk/aws-kms' ;
44import * as s3 from '@aws-cdk/aws-s3' ;
5+ import { RegionInfo } from '@aws-cdk/region-info' ;
56import { EbsDefaultEncryption } from '@aws-accelerator/custom-resource-ec2-ebs-default-encryption' ;
67import { S3CopyFiles } from '@aws-accelerator/custom-resource-s3-copy-files' ;
78import { S3PublicAccessBlock } from '@aws-accelerator/custom-resource-s3-public-access-block' ;
@@ -30,7 +31,7 @@ export interface DefaultsStep1Props {
3031export interface DefaultsStep1Result {
3132 centralBucketCopy : s3 . Bucket ;
3233 centralLogBucket : s3 . Bucket ;
33- aesLogBucket : s3 . Bucket ;
34+ aesLogBucket ? : s3 . Bucket ;
3435 accountEbsEncryptionKeys : AccountRegionEbsEncryptionKeys ;
3536}
3637
@@ -293,6 +294,13 @@ function createAesLogBucket(props: DefaultsStep1Props) {
293294 const logAccountConfig = config [ 'global-options' ] [ 'central-log-services' ] ;
294295 const logAccountStack = accountStacks . getOrCreateAccountStack ( logAccountConfig . account ) ;
295296
297+ const regionInfo = RegionInfo . get ( logAccountStack . region ) ;
298+ const elbv2Account = regionInfo ?. elbv2Account ;
299+ if ( ! elbv2Account ) {
300+ console . warn ( `Cannot enable access logging; don't know ELBv2 account for region ${ logAccountConfig . region } ` ) ;
301+ return ;
302+ }
303+
296304 const logBucket = new s3 . Bucket ( logAccountStack , 'AesBucket' , {
297305 versioned : true ,
298306 blockPublicAccess : s3 . BlockPublicAccess . BLOCK_ALL ,
@@ -306,10 +314,9 @@ function createAesLogBucket(props: DefaultsStep1Props) {
306314
307315 accounts . map ( a => logBucket . grantRead ( new iam . AccountPrincipal ( a . id ) ) ) ;
308316
309- // TODO remove hard coded ELB ca-central-1 region account id
310317 logBucket . addToResourcePolicy (
311318 new iam . PolicyStatement ( {
312- principals : [ new iam . AccountPrincipal ( '985666609251' ) ] ,
319+ principals : [ new iam . AccountPrincipal ( elbv2Account ) ] ,
313320 actions : [ 's3:PutObject' ] ,
314321 resources : [ `${ logBucket . bucketArn } /*` ] ,
315322 } ) ,
0 commit comments