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

Provide sensible defaults for GuLambda memorySize and timeout #188

Merged
merged 3 commits into from
Jan 21, 2021

Conversation

jacobwinch
Copy link
Contributor

What does this change?

Whilst testing #186, I noticed that memorySize and timeout are optional parameters for a GuLambda. If these values are omitted, CloudFormation defaults to 128MB and 3 seconds, respectively.

I don't think that these default values are particularly helpful for many of the Guardian use-cases that I've seen (they are especially unhelpful for Scala lambdas!), so I've tried to suggest something more appropriate.

Does this change require changes to existing projects or CDK CLI?

There are no required changes, but some projects may automatically increase the memory or timeout values for lambda functions. This change would show up in a snapshot diff though, so people could set these low values again manually if they felt strongly about keeping them.

How to test

I think this is adequately covered by unit tests added in this PR.

How can we measure success?

When setting projects up from scratch developers should save time, as they are less likely to encounter timeouts or OOM errors immediately after deploying for the first time.

Have we considered potential risks?

I suppose there is a small risk that this could incur unnecessary costs (due to the way that lambda pricing works).

There is also a risk that we will over or under provision lambdas due to my assumptions about what 'sensible' defaults are. An alternative approach would be to make these properties mandatory for a GuLambda. This would force developers to make these choices up-front, but at least it would avoid the annoying case where you end up with the super-low CloudFormation defaults!

@jacobwinch jacobwinch requested a review from a team January 21, 2021 13:04
} else {
switch (runtime.family) {
case RuntimeFamily.JAVA:
return 1024;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case RuntimeFamily.JAVA:
return 1024;
default:
return 512;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export class GuLambdaFunction extends Function {
constructor(scope: GuStack, id: string, props: GuFunctionProps) {
const bucket = Bucket.fromBucketName(scope, `${id}-bucket`, props.code.bucket);
const code = Code.fromBucket(bucket, props.code.key);
const { memorySize, timeout, ...rest } = props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these still need to be extracted from props or would it be easier just to use props.memorySize on line 45?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes thanks, I didn't realise this simpler version would work (but now I've read the docs and re-tested I can see that my version was needlessly complicated 😀).

...props,
...rest,
memorySize: defaultMemorySize(props.runtime, memorySize),
timeout: props.timeout ? props.timeout : Duration.seconds(30),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor but the following should achieve the same result with marginally less code

Suggested change
timeout: props.timeout ? props.timeout : Duration.seconds(30),
timeout: props.timeout ?? Duration.seconds(30),

Comment on lines +29 to +34
switch (runtime.family) {
case RuntimeFamily.JAVA:
return 1024;
default:
return 512;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@jacobwinch jacobwinch merged commit 9f929ef into main Jan 21, 2021
@jacobwinch jacobwinch deleted the jw-provide-sensible-defaults branch January 21, 2021 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants