Skip to content

Commit a88ca90

Browse files
Merge branch 'main' into update-resource-handler-table
2 parents d7f799f + 3827c6b commit a88ca90

File tree

27 files changed

+366
-130
lines changed

27 files changed

+366
-130
lines changed

reference-artifacts/Custom-Scripts/lza-upgrade/src/assets/cloudformation/AlbIpForwardingStack.template.json

Lines changed: 84 additions & 13 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ export class ConvertAseaConfig {
748748
organizationTrail: true,
749749
organizationTrailSettings: {
750750
multiRegionTrail: true,
751-
globalServiceEvents: false,
751+
globalServiceEvents: true,
752752
managementEvents: false,
753753
s3DataEvents: true,
754754
lambdaDataEvents: false,
@@ -2049,7 +2049,7 @@ export class ConvertAseaConfig {
20492049
});
20502050
}
20512051
const policyJson = JSON.parse(policyData);
2052-
if (scpName.includes('Guardrails-Part-1') || scpName.includes('Guardrails-Part-0')) {
2052+
if (scpName.includes('Part-1') || scpName.includes('Part-0')) {
20532053
const newStatements = policyJson.Statement.map((stmt: any) => {
20542054
if (stmt.Sid === 'SSM' || stmt.Sid === 'S3' || (stmt.Condition && stmt.Condition['ForAnyValue:StringLike'])) {
20552055
console.log('Adding Org admin role to scp');
@@ -2804,7 +2804,7 @@ export class ConvertAseaConfig {
28042804
};
28052805
} else if (route['target-vpn']) {
28062806
return {
2807-
vpnConnectionName: route['target-vpn'],
2807+
vpnConnectionName: route['target-vpn']['name'],
28082808
};
28092809
} else if (route['target-tgw']) {
28102810
if (tgwConfig['tgw-attach'] && tgwConfig['tgw-attach']['associate-to-tgw'] === route['target-tgw']) {

reference-artifacts/Custom-Scripts/lza-upgrade/src/snapshot.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class Snapshot {
2525
private readonly aseaConfigRepositoryName: string;
2626
private readonly localConfigFilePath: string | undefined;
2727
private readonly preMigrationSnapshot: boolean;
28+
private readonly parametersTableName: string;
2829

2930
constructor(config: Config) {
3031
this.aseaPrefix = config.aseaPrefix ?? 'ASEA-';
@@ -34,6 +35,7 @@ export class Snapshot {
3435
this.aseaConfigRepositoryName = config.repositoryName;
3536
this.localConfigFilePath = config.localConfigFilePath;
3637
this.preMigrationSnapshot = false;
38+
this.parametersTableName = config.parametersTableName;
3739
}
3840

3941
async pre() {
@@ -50,6 +52,7 @@ export class Snapshot {
5052
this.aseaPrefix,
5153
true,
5254
aseaConfig,
55+
this.parametersTableName
5356
);
5457
}
5558

@@ -67,6 +70,7 @@ export class Snapshot {
6770
this.aseaPrefix,
6871
this.preMigrationSnapshot,
6972
aseaConfig,
73+
this.parametersTableName
7074
);
7175
}
7276

reference-artifacts/Custom-Scripts/lza-upgrade/src/snapshot/snapshotConfiguration.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
* and limitations under the License.
1212
*/
1313

14-
import { Account, OrganizationsClient, paginateListAccounts } from '@aws-sdk/client-organizations';
14+
import { Account, AccountStatus, OrganizationsClient, paginateListAccounts } from '@aws-sdk/client-organizations';
1515
import { AssumeRoleCommand, AssumeRoleCommandOutput, GetCallerIdentityCommand, STSClient } from '@aws-sdk/client-sts';
1616
import { AwsCredentialIdentity } from '@aws-sdk/types';
1717

1818
import { TableOperations } from './common/dynamodb';
1919
import { snapshotAccountResources } from './snapshotAccountResources';
2020
import { snapshotGlobalResources } from './snapshotGlobalResources';
21+
import { DynamoDB } from '../common/aws/dynamodb';
22+
import { loadAccounts } from '../common/utils/accounts';
2123
import { snapshotRegionResources } from './snapshotRegionalResources';
2224
import { AcceleratorConfig } from '../asea-config';
2325

@@ -31,6 +33,7 @@ export async function snapshotConfiguration(
3133
prefix: string,
3234
preMigration: boolean,
3335
aseaConfig: AcceleratorConfig,
36+
aseaParametersTableName: string
3437
) {
3538
stsClient = new STSClient({ maxAttempts: 10 });
3639

@@ -44,7 +47,8 @@ export async function snapshotConfiguration(
4447
// process global services
4548
await snapshotGlobalResources(tableName, homeRegion, currentAccountId!, preMigration, undefined);
4649

47-
const accounts = await getAccountList();
50+
const accounts = await getAccountList(homeRegion, aseaParametersTableName);
51+
console.log(`Running snapshot for ${accounts.length} accounts`)
4852
const regions = aseaConfig['global-options']['supported-regions'];
4953
// process account services
5054
const accountPromises = [];
@@ -112,7 +116,40 @@ export async function getCredentials(accountId: string, roleName: string): Promi
112116
}
113117
}
114118

115-
export async function getAccountList(): Promise<Account[]> {
119+
export async function getAccountList(homeRegion: string, parametersTableName: string): Promise<Account[]> {
120+
// Get accounts from DynamoDB (ASEA managed accounts)
121+
const dynamodb = new DynamoDB(undefined, homeRegion);
122+
const aseaAccounts = await loadAccounts(parametersTableName, dynamodb);
123+
124+
if (aseaAccounts.length === 0) {
125+
console.warn(`No accounts found in DynamoDB table ${parametersTableName}.`);
126+
return [];
127+
}
128+
129+
console.log(`Retrieved ${aseaAccounts.length} accounts from DynamoDB table ${parametersTableName}`);
130+
131+
// Get all accounts from Organizations to get their current status
132+
const orgAccounts = await getAccountListFromOrganizations();
133+
console.log(`Retrieved ${orgAccounts.length} accounts from AWS Organizations`);
134+
135+
// Create a map of account IDs to their Organization status
136+
const accountStatusMap = new Map<string, AccountStatus>();
137+
for (const orgAccount of orgAccounts) {
138+
if (orgAccount.Id) {
139+
accountStatusMap.set(orgAccount.Id, orgAccount.Status || AccountStatus.SUSPENDED);
140+
}
141+
}
142+
143+
// Return only accounts from DynamoDB but with status from Organizations
144+
return aseaAccounts.map(account => ({
145+
Id: account.id,
146+
Name: account.key,
147+
Email: account.email || '',
148+
Status: accountStatusMap.get(account.id) || AccountStatus.SUSPENDED // Default to SUSPENDED if not found in Organizations
149+
}));
150+
}
151+
152+
async function getAccountListFromOrganizations(): Promise<Account[]> {
116153
const organizationsClient = new OrganizationsClient({ region: 'us-east-1', maxAttempts: 10 });
117154

118155
const accounts: Account[] = [];

reference-artifacts/Custom-Scripts/lza-upgrade/tools/network-drift-detection/lza-upgrade-check.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -627,13 +627,11 @@ def compare_route_table(crt, drt):
627627
{"Route": cr['destination'], "Reason": "Not matched to firewall instance"})
628628
else:
629629
logger.error(f"Route target {cr['target']} is not supported!")
630-
drift.append({"Route": cr['destination'], "Reason": f"Route target {
631-
cr['target']} is not supported!"})
630+
drift.append({"Route": cr['destination'], "Reason": f"Route target {cr['target']} is not supported!"}) # nopep8
632631
else:
633632
# this should not be possible!
634633
logger.error(f"More than one route with destination {cr['destination']} is deployed!") # nopep8
635-
drift.append({"Route": cr['destination'], "Reason": f"More than one route with destination {
636-
cr['destination']} found"})
634+
drift.append({"Route": cr['destination'], "Reason": f"More than one route with destination {cr['destination']} found"}) # nopep8
637635

638636
# check if there are route entries deployed that are not in the config
639637
for dr in dRoutes:
@@ -642,8 +640,7 @@ def compare_route_table(crt, drt):
642640
f"Route {dr['DestinationCidrBlock']} is a VPC peering route. Skipping check")
643641
continue
644642

645-
cr = [r for r in cRoutes if r['destination']
646-
== dr['DestinationCidrBlock']]
643+
cr = [r for r in cRoutes if r['destination'] == dr['DestinationCidrBlock']]
647644
if len(cr) == 0:
648645
logger.warning(f"Route {dr['DestinationCidrBlock']} exists in deployed route table but not found in config") # nopep8
649646
drift.append(
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
boto3==1.35.40
2-
botocore==1.35.40
1+
boto3==1.38.1
2+
botocore==1.38.2
33
jmespath==1.0.1
44
python-dateutil==2.9.0.post0
5-
s3transfer==0.10.3
6-
six==1.16.0
7-
urllib3==2.2.3
5+
s3transfer==0.12.0
6+
six==1.17.0
7+
urllib3==2.4.0

reference-artifacts/ssm-documents/attach-iam-role-policy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mainSteps:
1616
- name: attachPolicy
1717
action: 'aws:executeScript'
1818
inputs:
19-
Runtime: python3.7
19+
Runtime: python3.11
2020
Handler: script_handler
2121
Script: |-
2222
import boto3

reference-artifacts/ssm-documents/ssm-patching-role-tagging.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mainSteps:
1616
- name: LookupRole
1717
action: 'aws:executeScript'
1818
inputs:
19-
Runtime: python3.8
19+
Runtime: python3.11
2020
Handler: getRoleName
2121
InputPayload:
2222
roleId: '{{RoleId}}'

src/core/cdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aws-accelerator/accelerator",
3-
"version": "1.6.2",
3+
"version": "1.6.3",
44
"scripts": {
55
"bootstrap": "pnpx cdk bootstrap",
66
"deploy": "pnpx cdk deploy",

src/deployments/cdk/src/deployments/iam/log-group-role.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,12 @@ async function createRole(stack: AccountStack) {
5151
resources: ['*'],
5252
}),
5353
);
54+
55+
role.addToPrincipalPolicy(
56+
new iam.PolicyStatement({
57+
actions: ['kms:Encrypt', 'kms:Decrypt', 'kms:GenerateDataKey'],
58+
resources: ['*'],
59+
}),
60+
);
5461
return role;
5562
}

0 commit comments

Comments
 (0)