From 62fd40269f5ab9830e375fe13695e3727384ba26 Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Wed, 6 Nov 2024 15:45:59 -0600 Subject: [PATCH 1/3] Minor updates to fill in vpc id and stage Signed-off-by: Tanner Lewis --- .../migration-assistant-solution/initBootstrap.sh | 8 ++++++++ .../lib/solutions-stack.ts | 13 +++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/deployment/migration-assistant-solution/initBootstrap.sh b/deployment/migration-assistant-solution/initBootstrap.sh index 5355bca93..0b5cf6993 100644 --- a/deployment/migration-assistant-solution/initBootstrap.sh +++ b/deployment/migration-assistant-solution/initBootstrap.sh @@ -50,6 +50,14 @@ else fi cd deployment/cdk/opensearch-service-migration || exit + +if [[ -n "$VPC_ID" ]]; then + sed -i "s||$VPC_ID|g" /opensearch-migrations/deployment/cdk/opensearch-service-migration/cdk.context.json +fi +if [[ -n "$STAGE" ]]; then + sed -i "s||$STAGE|g" /opensearch-migrations/deployment/cdk/opensearch-service-migration/cdk.context.json +fi + npm install -g aws-cdk 2>&1 npm install 2>&1 ./buildDockerImages.sh \ No newline at end of file diff --git a/deployment/migration-assistant-solution/lib/solutions-stack.ts b/deployment/migration-assistant-solution/lib/solutions-stack.ts index c727a562a..d893b69df 100644 --- a/deployment/migration-assistant-solution/lib/solutions-stack.ts +++ b/deployment/migration-assistant-solution/lib/solutions-stack.ts @@ -144,12 +144,6 @@ export class SolutionsInfrastructureStack extends Stack { }) const solutionsUserAgent = `AwsSolution/${props.solutionId}/${props.solutionVersion}` - const cfnInitConfig: InitElement[] = [ - InitCommand.shellCommand(`echo "export MIGRATIONS_APP_REGISTRY_ARN=${appRegistryAppARN}; export MIGRATIONS_USER_AGENT=${solutionsUserAgent}" > /etc/profile.d/solutionsEnv.sh`), - InitFile.fromFileInline("/opensearch-migrations/initBootstrap.sh", './initBootstrap.sh', { - mode: "000744" - }), - ] const bootstrapRole = new Role(this, 'BootstrapRole', { assumedBy: new ServicePrincipal('ec2.amazonaws.com'), @@ -188,6 +182,13 @@ export class SolutionsInfrastructureStack extends Stack { vpc = importVPC(this, vpcIdParameter, availabilityZonesParameter, privateSubnetIdsParameter); } + const cfnInitConfig: InitElement[] = [ + InitCommand.shellCommand(`echo "export MIGRATIONS_APP_REGISTRY_ARN=${appRegistryAppARN}; export MIGRATIONS_USER_AGENT=${solutionsUserAgent}; export VPC_ID=${vpc.vpcId}; export STAGE=${stageParameter.valueAsString}" > /etc/profile.d/solutionsEnv.sh`), + InitFile.fromFileInline("/opensearch-migrations/initBootstrap.sh", './initBootstrap.sh', { + mode: "000744" + }), + ] + new Instance(this, 'BootstrapEC2Instance', { vpc: vpc, vpcSubnets: { From 1e0be25743e305dfb6b0ccbe813e05b2035f9e8e Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Thu, 7 Nov 2024 10:40:21 -0600 Subject: [PATCH 2/3] Update export string generation Signed-off-by: Tanner Lewis --- .../lib/solutions-stack.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/deployment/migration-assistant-solution/lib/solutions-stack.ts b/deployment/migration-assistant-solution/lib/solutions-stack.ts index d893b69df..46dc427aa 100644 --- a/deployment/migration-assistant-solution/lib/solutions-stack.ts +++ b/deployment/migration-assistant-solution/lib/solutions-stack.ts @@ -89,6 +89,12 @@ function importVPC(stack: Stack, vpdIdParameter: CfnParameter, availabilityZones }); } +function generateExportString(exports: { [key: string]: string }): string { + return Object.entries(exports) + .map(([key, value]) => `export ${key}=${value}`) + .join("; "); +} + export class SolutionsInfrastructureStack extends Stack { constructor(scope: Construct, id: string, props: SolutionsInfrastructureStackProps) { @@ -182,8 +188,14 @@ export class SolutionsInfrastructureStack extends Stack { vpc = importVPC(this, vpcIdParameter, availabilityZonesParameter, privateSubnetIdsParameter); } + const exportString = generateExportString({ + "MIGRATIONS_APP_REGISTRY_ARN": appRegistryAppARN, + "MIGRATIONS_USER_AGENT": solutionsUserAgent, + "VPC_ID": vpc.vpcId, + "STAGE": stageParameter.valueAsString, + }) const cfnInitConfig: InitElement[] = [ - InitCommand.shellCommand(`echo "export MIGRATIONS_APP_REGISTRY_ARN=${appRegistryAppARN}; export MIGRATIONS_USER_AGENT=${solutionsUserAgent}; export VPC_ID=${vpc.vpcId}; export STAGE=${stageParameter.valueAsString}" > /etc/profile.d/solutionsEnv.sh`), + InitCommand.shellCommand(`echo "${exportString}" > /etc/profile.d/solutionsEnv.sh`), InitFile.fromFileInline("/opensearch-migrations/initBootstrap.sh", './initBootstrap.sh', { mode: "000744" }), From 5e2f69f55db3637d055f8dc2790159b6a51e5edf Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Thu, 7 Nov 2024 11:24:28 -0600 Subject: [PATCH 3/3] Update parameter type Signed-off-by: Tanner Lewis --- deployment/migration-assistant-solution/lib/solutions-stack.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/migration-assistant-solution/lib/solutions-stack.ts b/deployment/migration-assistant-solution/lib/solutions-stack.ts index 46dc427aa..5ef3ed83d 100644 --- a/deployment/migration-assistant-solution/lib/solutions-stack.ts +++ b/deployment/migration-assistant-solution/lib/solutions-stack.ts @@ -89,7 +89,7 @@ function importVPC(stack: Stack, vpdIdParameter: CfnParameter, availabilityZones }); } -function generateExportString(exports: { [key: string]: string }): string { +function generateExportString(exports: Record): string { return Object.entries(exports) .map(([key, value]) => `export ${key}=${value}`) .join("; ");