Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lambda): add support for ephemeral storage #19552

Merged
merged 31 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3a70f66
feat(lambda): add support for ephemeral storage
robertd Mar 25, 2022
5a5ea1b
add missing semicolon
robertd Mar 25, 2022
986f671
throw on out of bound ephemeral storage size
robertd Mar 25, 2022
2b8e85a
update readme
robertd Mar 25, 2022
69a00ee
add tests
robertd Mar 25, 2022
447ad15
minor change
robertd Mar 25, 2022
ce255fd
Update packages/@aws-cdk/aws-lambda/lib/function.ts
robertd Mar 25, 2022
3f58ab3
Update packages/@aws-cdk/aws-lambda/lib/function.ts
robertd Mar 25, 2022
ef22c8f
Update packages/@aws-cdk/aws-lambda/test/function.test.ts
robertd Mar 25, 2022
5227a3a
Update packages/@aws-cdk/aws-lambda/README.md
robertd Mar 25, 2022
39ed82d
Update packages/@aws-cdk/aws-lambda/lib/function.ts
robertd Mar 25, 2022
f14691b
fix few minor suggestions
robertd Mar 25, 2022
e25f2d8
minor
robertd Mar 25, 2022
617a4fe
lint
robertd Mar 25, 2022
eec7cf2
Update packages/@aws-cdk/aws-lambda/README.md
robertd Mar 30, 2022
8340dbf
add tests using Size
robertd Mar 30, 2022
5be64bc
Merge branch 'lambda-ephemeral-storage' of github.com:robertd/aws-cdk…
robertd Mar 30, 2022
ed15836
Merge branch 'master' into lambda-ephemeral-storage
robertd Mar 30, 2022
f2cf8af
fix readme
robertd Mar 30, 2022
cd9bc2d
update readme
robertd Mar 30, 2022
9d51de0
fix rosetta
robertd Mar 30, 2022
b4172fb
Merge branch 'master' into lambda-ephemeral-storage
robertd Mar 31, 2022
3cc1850
Update packages/@aws-cdk/aws-lambda/lib/function.ts
robertd Mar 31, 2022
be67334
Update packages/@aws-cdk/aws-lambda/lib/function.ts
robertd Mar 31, 2022
ced6336
Merge branch 'master' into lambda-ephemeral-storage
robertd Mar 31, 2022
ffefc69
Merge branch 'master' into lambda-ephemeral-storage
robertd Mar 31, 2022
3168256
Merge branch 'master' into lambda-ephemeral-storage
robertd Mar 31, 2022
bdc6814
Merge branch 'master' into lambda-ephemeral-storage
robertd Mar 31, 2022
3f1fd81
add test for token value
robertd Apr 1, 2022
f0c5dd8
Merge branch 'master' into lambda-ephemeral-storage
robertd Apr 1, 2022
0a4bde8
Merge branch 'master' into lambda-ephemeral-storage
mergify[bot] Apr 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,18 @@ const fn = new lambda.Function(this, 'MyLambda', {
});
```

## Ephemeral Storage

You can configure ephemeral storage (/tmp) between 512 MB and 10,240 MB, and you can now control the amount of ephemeral storage a function gets for reading or writing data, allowing you to use AWS Lambda for ETL jobs, ML inference, or other data-intensive workloads.
robertd marked this conversation as resolved.
Show resolved Hide resolved

```ts
const fn = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_12_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
ephemeralStorageSize: 1024,
});
```

robertd marked this conversation as resolved.
Show resolved Hide resolved
## Singleton Function

Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-lambda/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ export interface FunctionOptions extends EventInvokeConfigOptions {
*/
readonly memorySize?: number;

/**
* The size of the function’s /tmp directory in MB.
*
* @default 512
robertd marked this conversation as resolved.
Show resolved Hide resolved
*/
readonly ephemeralStorageSize?: number;
robertd marked this conversation as resolved.
Show resolved Hide resolved

/**
* Initial policy statements to add to the created Lambda Role.
*
Expand Down Expand Up @@ -743,6 +750,10 @@ export class Function extends FunctionBase {
}
this._architecture = props.architecture ?? (props.architectures && props.architectures[0]);

if (props.ephemeralStorageSize && (props.ephemeralStorageSize < 512 || props.ephemeralStorageSize > 10240)) {
robertd marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Ephemeral storage size must be between 512 and 10240 MB.');
robertd marked this conversation as resolved.
Show resolved Hide resolved
}

const resource: CfnFunction = new CfnFunction(this, 'Resource', {
functionName: this.physicalName,
description: props.description,
Expand All @@ -763,6 +774,7 @@ export class Function extends FunctionBase {
// Token, actually *modifies* the 'environment' map.
environment: Lazy.uncachedAny({ produce: () => this.renderEnvironment() }),
memorySize: props.memorySize,
ephemeralStorage: this.buildEphemeralStorage(props),
robertd marked this conversation as resolved.
Show resolved Hide resolved
vpcConfig: this.configureVpc(props),
deadLetterConfig: this.buildDeadLetterConfig(dlqTopicOrQueue),
tracingConfig: this.buildTracingConfig(props),
Expand Down Expand Up @@ -1128,6 +1140,16 @@ Environment variables can be marked for removal when used in Lambda@Edge by sett
}
}

private buildEphemeralStorage(props: FunctionProps) {
robertd marked this conversation as resolved.
Show resolved Hide resolved
if (props.ephemeralStorageSize === undefined) {
return undefined;
}

return {
size: props.ephemeralStorageSize,
};
}

private buildTracingConfig(props: FunctionProps) {
if (props.tracing === undefined || props.tracing === Tracing.DISABLED) {
return undefined;
Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-lambda/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2487,6 +2487,16 @@ describe('function', () => {
});
});

test('throws if ephemeral storage size is out of bound', () => {
robertd marked this conversation as resolved.
Show resolved Hide resolved
const stack = new cdk.Stack();
expect(() => new lambda.Function(stack, 'MyLambda', {
code: new lambda.InlineCode('foo'),
handler: 'bar',
robertd marked this conversation as resolved.
Show resolved Hide resolved
runtime: lambda.Runtime.NODEJS_14_X,
ephemeralStorageSize: 511,
})).toThrow(/Ephemeral storage size must be between 512 and 10240 MB./);
});

function newTestLambda(scope: constructs.Construct) {
return new lambda.Function(scope, 'MyLambda', {
code: new lambda.InlineCode('foo'),
Expand Down