From 650e77e7754265645fdcea67ef4ad4f17a575ac3 Mon Sep 17 00:00:00 2001 From: Amir Szekely Date: Tue, 17 Oct 2023 15:42:44 -0400 Subject: [PATCH 1/2] fix: Java bundling stopped working --- src/base.ts | 4 ++-- src/java.ts | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/base.ts b/src/base.ts index d7d5c56..9966683 100644 --- a/src/base.ts +++ b/src/base.ts @@ -164,7 +164,7 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable, subnetSelection: internalProps.props?.subnetSelection, environment: { buildImage: this.architecture == lambda.Architecture.X86_64 ? - codebuild.LinuxBuildImage.AMAZON_LINUX_2_5 : codebuild.LinuxArmBuildImage.AMAZON_LINUX_2_STANDARD_2_0, + codebuild.LinuxBuildImage.AMAZON_LINUX_2_5 : codebuild.LinuxArmBuildImage.AMAZON_LINUX_2_STANDARD_3_0, }, logging: { cloudWatch: { @@ -197,7 +197,7 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable, ], logRetention: RetentionDays.ONE_MONTH, }); - this.provider.node.addDependency(this.project); + this.provider.node.addDependency(this.project); this.packagesBucket.grantDelete(this.provider); } else if (this.type == DependencyPackagerType.LAMBDA) { const lambdaProps = { diff --git a/src/java.ts b/src/java.ts index a623912..dbc8737 100644 --- a/src/java.ts +++ b/src/java.ts @@ -8,7 +8,7 @@ import { BaseDependencyPackager, DependencyPackagerProps, LayerProps } from './b * Packager for creating Lambda layers for Java dependencies in AWS. Nothing is done locally so this doesn't require Docker and doesn't upload huge files to S3. */ export class JavaDependencyPackager extends BaseDependencyPackager { - private static runtimePackage(props?: DependencyPackagerProps) { + private static basePackage(props?: DependencyPackagerProps) { switch (props?.runtime ?? lambda.Runtime.JAVA_11) { case lambda.Runtime.JAVA_8: case lambda.Runtime.JAVA_8_CORRETTO: @@ -20,16 +20,27 @@ export class JavaDependencyPackager extends BaseDependencyPackager { } } + private static packageArch(props?: DependencyPackagerProps) { + switch (props?.architecture ?? lambda.Architecture.X86_64) { + case lambda.Architecture.X86_64: + return 'x86_64'; + case lambda.Architecture.ARM_64: + return 'aarch64'; + default: + throw new Error(`We do not support ${props?.architecture?.name} yet`); + } + } + constructor(scope: Construct, id: string, props?: DependencyPackagerProps) { super(scope, id, { props, runtimeFamily: lambda.RuntimeFamily.JAVA, defaultRuntime: lambda.Runtime.JAVA_11, codeBuildRuntimeInstallCommands: [ - `echo Installing ${JavaDependencyPackager.runtimePackage(props)}`, - `yum install -y ${JavaDependencyPackager.runtimePackage(props)}`, - `alternatives --set java /usr/lib/jvm/${JavaDependencyPackager.runtimePackage(props)}.*/bin/java`, - `alternatives --set javac /usr/lib/jvm/${JavaDependencyPackager.runtimePackage(props)}.*/bin/javac`, + `echo Installing ${JavaDependencyPackager.basePackage(props)}`, + `yum install -y ${JavaDependencyPackager.basePackage(props)}-devel.${JavaDependencyPackager.packageArch(props)} ${JavaDependencyPackager.basePackage(props)}-headless.${JavaDependencyPackager.packageArch(props)}`, + `alternatives --set java $(rpm -ql ${JavaDependencyPackager.basePackage(props)}-headless.${JavaDependencyPackager.packageArch(props)} | grep bin/java$ | head -n 1)`, + `alternatives --set javac $(rpm -ql ${JavaDependencyPackager.basePackage(props)}-devel.${JavaDependencyPackager.packageArch(props)} | grep bin/javac$ | head -n 1)`, ], targetDirectory: 'java', }); From d1700359c8fb43ce8d3f232aa978b162eece8e08 Mon Sep 17 00:00:00 2001 From: Amir Szekely Date: Tue, 17 Oct 2023 15:44:51 -0400 Subject: [PATCH 2/2] Update snapshot --- test/default.integ.snapshot/Turbo-Layer-Test.assets.json | 4 ++-- test/default.integ.snapshot/Turbo-Layer-Test.template.json | 6 +++--- test/default.integ.snapshot/manifest.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/default.integ.snapshot/Turbo-Layer-Test.assets.json b/test/default.integ.snapshot/Turbo-Layer-Test.assets.json index 3a1a30b..3a2260b 100644 --- a/test/default.integ.snapshot/Turbo-Layer-Test.assets.json +++ b/test/default.integ.snapshot/Turbo-Layer-Test.assets.json @@ -235,7 +235,7 @@ } } }, - "3a503d4db4e69346c332bfe77fce8ce0c794379d3af40b21131b92e270d6c489": { + "ca58bd87cb799fc28d4ab0ad7e68f27535125e8e95625d6a331bc473d09c7ae8": { "source": { "path": "Turbo-Layer-Test.template.json", "packaging": "file" @@ -243,7 +243,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "3a503d4db4e69346c332bfe77fce8ce0c794379d3af40b21131b92e270d6c489.json", + "objectKey": "ca58bd87cb799fc28d4ab0ad7e68f27535125e8e95625d6a331bc473d09c7ae8.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/test/default.integ.snapshot/Turbo-Layer-Test.template.json b/test/default.integ.snapshot/Turbo-Layer-Test.template.json index 2e0ca04..c5bb0aa 100644 --- a/test/default.integ.snapshot/Turbo-Layer-Test.template.json +++ b/test/default.integ.snapshot/Turbo-Layer-Test.template.json @@ -7919,9 +7919,9 @@ }, "CodeBuildInstallCommands": [ "echo Installing java-11-amazon-corretto", - "yum install -y java-11-amazon-corretto", - "alternatives --set java /usr/lib/jvm/java-11-amazon-corretto.*/bin/java", - "alternatives --set javac /usr/lib/jvm/java-11-amazon-corretto.*/bin/javac" + "yum install -y java-11-amazon-corretto-devel.x86_64 java-11-amazon-corretto-headless.x86_64", + "alternatives --set java $(rpm -ql java-11-amazon-corretto-headless.x86_64 | grep bin/java$ | head -n 1)", + "alternatives --set javac $(rpm -ql java-11-amazon-corretto-devel.x86_64 | grep bin/javac$ | head -n 1)" ], "PreinstallCommands": [], "Commands": [ diff --git a/test/default.integ.snapshot/manifest.json b/test/default.integ.snapshot/manifest.json index 38cc8d3..199fa2d 100644 --- a/test/default.integ.snapshot/manifest.json +++ b/test/default.integ.snapshot/manifest.json @@ -17,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/3a503d4db4e69346c332bfe77fce8ce0c794379d3af40b21131b92e270d6c489.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/ca58bd87cb799fc28d4ab0ad7e68f27535125e8e95625d6a331bc473d09c7ae8.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [