Skip to content

Commit 10d4f55

Browse files
authored
Merge branch 'main' into chore-iotevents-action-bind
2 parents c67b82c + 48178ac commit 10d4f55

23 files changed

Lines changed: 808 additions & 258 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"devDependencies": {
1919
"@types/prettier": "2.6.0",
2020
"@yarnpkg/lockfile": "^1.1.0",
21-
"cdk-generate-synthetic-examples": "^0.1.12",
21+
"cdk-generate-synthetic-examples": "^0.1.14",
2222
"conventional-changelog-cli": "^2.2.2",
2323
"fs-extra": "^9.1.0",
2424
"graceful-fs": "^4.2.10",

packages/@aws-cdk/aws-eks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"@types/sinon": "^9.0.11",
9191
"@types/yaml": "1.9.6",
9292
"aws-sdk": "^2.848.0",
93-
"cdk8s": "^2.3.72",
93+
"cdk8s": "^2.3.74",
9494
"cdk8s-plus-21": "^2.0.0-beta.12",
9595
"jest": "^27.5.1",
9696
"sinon": "^9.2.4"

packages/@aws-cdk/aws-lambda-nodejs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"@aws-cdk/pkglint": "0.0.0",
8080
"@types/jest": "^27.5.2",
8181
"delay": "5.0.0",
82-
"esbuild": "^0.14.51"
82+
"esbuild": "^0.14.53"
8383
},
8484
"dependencies": {
8585
"@aws-cdk/aws-lambda": "0.0.0",

packages/@aws-cdk/aws-lambda/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ new lambda.DockerImageFunction(this, 'ECRFunction', {
8181
The props for these docker image resources allow overriding the image's `CMD`, `ENTRYPOINT`, and `WORKDIR`
8282
configurations as well as choosing a specific tag or digest. See their docs for more information.
8383

84+
To deploy a `DockerImageFunction` on Lambda `arm64` architecture, specify `Architecture.ARM_64` in `architecture`.
85+
This will bundle docker image assets for `arm64` architecture with `--platform linux/arm64` even if build within an `x86_64` host.
86+
87+
```ts
88+
new DockerImageFunction(this, 'AssetFunction', {
89+
code: DockerImageCode.fromImageAsset(path.join(__dirname, 'docker-arm64-handler')),
90+
architecture: Architecture.ARM_64,
91+
});
92+
```
93+
8494
## Execution Role
8595

8696
Lambda functions assume an IAM role during execution. In CDK by default, Lambda

packages/@aws-cdk/aws-lambda/lib/image-function.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as ecr from '@aws-cdk/aws-ecr';
2+
import { Platform } from '@aws-cdk/aws-ecr-assets';
23
import { Construct } from 'constructs';
4+
import { Architecture } from './architecture';
35
import { AssetImageCode, AssetImageCodeProps, EcrImageCode, EcrImageCodeProps, Code } from './code';
46
import { Function, FunctionOptions } from './function';
57
import { Handler } from './handler';
@@ -41,8 +43,12 @@ export abstract class DockerImageCode {
4143
*/
4244
public static fromImageAsset(directory: string, props: AssetImageCodeProps = {}): DockerImageCode {
4345
return {
44-
_bind() {
45-
return new AssetImageCode(directory, props);
46+
_bind(architecture?: Architecture) {
47+
return new AssetImageCode(directory, {
48+
// determine the platform from `architecture`.
49+
...architecture?.dockerPlatform ? { platform: Platform.custom(architecture.dockerPlatform) } : {},
50+
...props,
51+
});
4652
},
4753
};
4854
}
@@ -51,7 +57,7 @@ export abstract class DockerImageCode {
5157
* Produce a `Code` instance from this `DockerImageCode`.
5258
* @internal
5359
*/
54-
public abstract _bind(): Code;
60+
public abstract _bind(architecture?: Architecture): Code;
5561
}
5662

5763
/**
@@ -63,7 +69,7 @@ export class DockerImageFunction extends Function {
6369
...props,
6470
handler: Handler.FROM_IMAGE,
6571
runtime: Runtime.FROM_IMAGE,
66-
code: props.code._bind(),
72+
code: props.code._bind(props.architecture),
6773
});
6874
}
6975
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM public.ecr.aws/lambda/python:latest
2+
3+
ARG FUNCTION_DIR="/var/task"
4+
COPY index.py ${FUNCTION_DIR}
5+
6+
CMD [ "index.handler" ]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import json, platform
2+
def handler(event, context):
3+
return {
4+
'statusCode': 200,
5+
'body': json.dumps( f'Hello CDK from Lambda({platform.platform()})!')
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as path from 'path';
2+
import { App, Stack } from '@aws-cdk/core';
3+
import * as integ from '@aws-cdk/integ-tests';
4+
import { Architecture, DockerImageCode, DockerImageFunction } from '../lib';
5+
6+
const app = new App();
7+
8+
const stack = new Stack(app, 'lambda-ecr-docker-arm64');
9+
10+
new DockerImageFunction(stack, 'MyLambda', {
11+
code: DockerImageCode.fromImageAsset(path.join(__dirname, 'docker-arm64-handler')),
12+
architecture: Architecture.ARM_64,
13+
});
14+
15+
new integ.IntegTest(app, 'lambda-docker-arm64', {
16+
testCases: [stack],
17+
});
18+
19+
app.synth();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as path from 'path';
2+
import { Template } from '@aws-cdk/assertions';
3+
import * as cdk from '@aws-cdk/core';
4+
import { Architecture, DockerImageCode, DockerImageFunction } from '../lib';
5+
6+
describe('lambda platform', () => {
7+
test('can choose lambda architecture arm64', () => {
8+
// GIVEN
9+
const app = new cdk.App();
10+
const stack = new cdk.Stack(app, 'stack');
11+
12+
// WHEN
13+
new DockerImageFunction(stack, 'Lambda', {
14+
code: DockerImageCode.fromImageAsset(path.join(__dirname, 'docker-arm64-handler')),
15+
architecture: Architecture.ARM_64,
16+
});
17+
18+
// THEN
19+
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
20+
Architectures: [
21+
'arm64',
22+
],
23+
});
24+
});
25+
26+
test('can choose lambda architecture x86_64', () => {
27+
// GIVEN
28+
const app = new cdk.App();
29+
const stack = new cdk.Stack(app, 'stack');
30+
31+
// WHEN
32+
new DockerImageFunction(stack, 'Lambda', {
33+
code: DockerImageCode.fromImageAsset(path.join(__dirname, 'docker-arm64-handler')),
34+
architecture: Architecture.X86_64,
35+
});
36+
37+
// THEN
38+
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
39+
Architectures: [
40+
'x86_64',
41+
],
42+
});
43+
});
44+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"20.0.0"}

0 commit comments

Comments
 (0)