Skip to content

Commit 1b06a29

Browse files
authored
fix(upgrade): enable organization cloudtrail in config converter. For… (#1263)
* fix(upgrade): enable organization cloudtrail in config converter. For CT environment create s3 events trail. Add option to delete cloudtrail in post migration * update resource handler table for vpc endpoints.
1 parent 8bc0506 commit 1b06a29

File tree

4 files changed

+81
-18
lines changed

4 files changed

+81
-18
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* eslint-disable */
2+
/**
3+
* Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
6+
* with the License. A copy of the License is located at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
11+
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
import { CloudTrailClient, DeleteTrailCommand } from '@aws-sdk/client-cloudtrail';
15+
import { Credentials } from '@aws-sdk/client-sts';
16+
import { throttlingBackOff } from './backoff';
17+
18+
export class Cloudtrail {
19+
private readonly serviceClient: CloudTrailClient;
20+
21+
constructor(credentials?: Credentials, region?: string) {
22+
if (credentials) {
23+
this.serviceClient = new CloudTrailClient({ credentials: {
24+
accessKeyId: credentials.AccessKeyId!,
25+
secretAccessKey: credentials.SecretAccessKey!,
26+
sessionToken: credentials.SessionToken! },
27+
region });
28+
} else {
29+
this.serviceClient = new CloudTrailClient({});
30+
}
31+
}
32+
33+
async deleteOrganizationTrail(acceleratorPrefix: string): Promise<void> {
34+
try {
35+
await throttlingBackOff(() => this.serviceClient.send(new DeleteTrailCommand({ Name: `${acceleratorPrefix}Org-Trail` })));
36+
} catch (error) {
37+
console.log(`Unable to delete Organization CloudTrail ${acceleratorPrefix}Org-Trail`);
38+
}
39+
}
40+
}

reference-artifacts/Custom-Scripts/lza-upgrade/src/convert-config.ts

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,39 @@ export class ConvertAseaConfig {
741741
ousForS3EncryptionDeploymentTargetsWithoutNestedOus,
742742
);
743743

744+
let cloudtrailConfig = undefined;
745+
if (globalOptions['ct-baseline'] === true) {
746+
cloudtrailConfig = {
747+
enable: true,
748+
organizationTrail: true,
749+
organizationTrailSettings: {
750+
multiRegionTrail: true,
751+
globalServiceEvents: false,
752+
managementEvents: false,
753+
s3DataEvents: true,
754+
lambdaDataEvents: false,
755+
sendToCloudWatchLogs: true,
756+
apiErrorRateInsight: false,
757+
apiCallRateInsight: false,
758+
}
759+
}
760+
} else {
761+
cloudtrailConfig = {
762+
enable: true,
763+
organizationTrail: true,
764+
organizationTrailSettings: {
765+
multiRegionTrail: true,
766+
globalServiceEvents: true,
767+
managementEvents: true,
768+
s3DataEvents: true,
769+
lambdaDataEvents: false,
770+
sendToCloudWatchLogs: true,
771+
apiErrorRateInsight: false,
772+
apiCallRateInsight: true,
773+
}
774+
}
775+
}
776+
744777
const globalConfigAttributes: { [key: string]: unknown } = {
745778
externalLandingZoneResources: {
746779
importExternalLandingZoneResources: true,
@@ -779,23 +812,7 @@ export class ConvertAseaConfig {
779812
logging: {
780813
account: this.getAccountKeyforLza(globalOptions, centralizeLogging.account),
781814
centralizedLoggingRegion: centralizeLogging.region,
782-
cloudtrail: {
783-
enable: false,
784-
organizationTrail: false,
785-
// TODO: Confirm defaults
786-
organizationTrailSettings: {
787-
multiRegionTrail: true,
788-
globalServiceEvents: true,
789-
managementEvents: true,
790-
s3DataEvents: true,
791-
lambdaDataEvents: false,
792-
sendToCloudWatchLogs: true,
793-
apiErrorRateInsight: false,
794-
apiCallRateInsight: true,
795-
},
796-
// TODO: Confirm Account trails, ASEA seems like doesn't have any account specific trail config
797-
// TODO: Confirm about lifecycleRules. Not present in ASEA and not used in LZA
798-
},
815+
cloudtrail: cloudtrailConfig,
799816
sessionManager: {
800817
sendToS3: centralizeLogging['ssm-to-s3'],
801818
sendToCloudWatchLogs: centralizeLogging['ssm-to-cwl'],

reference-artifacts/Custom-Scripts/lza-upgrade/src/post-migration.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { AcceleratorConfig, ImportCertificateConfig, ImportCertificateConfigType
1616
import { loadAseaConfig } from './asea-config/load';
1717
import { DynamoDB } from './common/aws/dynamodb';
1818
import { ConfigService } from './common/aws/config-service';
19+
import { Cloudtrail } from './common/aws/cloudtrail';
1920
import { S3 } from './common/aws/s3';
2021
import { Account, getAccountId } from './common/outputs/accounts';
2122
import { StackOutput, findValuesFromOutputs, loadOutputs } from './common/outputs/load-outputs';
@@ -32,6 +33,7 @@ export class PostMigration {
3233
private readonly s3: S3;
3334
private readonly dynamoDb: DynamoDB;
3435
private readonly configService: ConfigService;
36+
private readonly cloudtrail = new Cloudtrail();
3537
private outputs: StackOutput[] = [];
3638
private accounts: Account[] = [];
3739
private centralBucket: string | undefined;
@@ -51,6 +53,7 @@ export class PostMigration {
5153
this.s3 = new S3(undefined, this.region);
5254
this.dynamoDb = new DynamoDB(undefined, this.region);
5355
this.configService = new ConfigService(undefined, this.region);
56+
this.cloudtrail = new Cloudtrail(undefined, this.region);
5457
this.args = args;
5558
this.outputsDirectory = './outputs';
5659
this.writeConfig = {
@@ -151,6 +154,9 @@ export class PostMigration {
151154
break;
152155
case 'remove-logging':
153156
await this.removeLogging(mappingConfig);
157+
break;
158+
case 'remove-org-cloudtrail':
159+
await this.cloudtrail.deleteOrganizationTrail(this.aseaPrefix);
154160
}
155161
}
156162

src/mkdocs/docs/lza-upgrade/asea-resource-handlers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ In order to accomplish upgrading from ASEA to LZA, the solution relies on a conc
3535
|Transit Gateways |FALSE |TRUE |Amazon Side ASN </br> Auto Accept Shared Attachments </br> Default Route Table Associations </br> Default Route Table Propagations </br> DNS Support </br> VPN ECMP Support | |
3636
|Virtual Private Gateway |FALSE |TRUE |Amazon Side ASN | |
3737
|VPC |FALSE |TRUE |CIDR Blocks </br> Enable DNS Host Names </br> Enable DNS Support </br> Instance Tenancy | |
38-
|VPC Endpoint |FALSE |FALSE | | |
38+
|VPC Endpoint |TRUE |FALSE |None, Including associated security group. Must re-create endpoint | |
3939
|VPC Endpoint (Gateway) |FALSE |TRUE |Route Table Ids | |
4040
|VPC Peering Connection |FALSE |FALSE | | |

0 commit comments

Comments
 (0)