Skip to content

feat(lambda): timeout property to lambda function construct - #17000

Closed
ben-eb wants to merge 1 commit into
aws:masterfrom
university-of-york:gh16047-add-function-timeout
Closed

ben-eb wants to merge 1 commit into
aws:masterfrom
university-of-york:gh16047-add-function-timeout

Conversation

@ben-eb

@ben-eb ben-eb commented Oct 15, 2021

Copy link
Copy Markdown
Contributor

Hello 👋

We would like to keep the timeout in sync between CloudWatch and Lambda, to avoid false positives. Currently, we are writing code like the following:

const myLambdaTimeout = cdk.Duration.seconds(30);

const myLambda = new Lambda.Function(this, 'my-lambda', {
  // ... rest of props
  timeout: myLambdaTimeout
});

// ... later in the stack
new CloudWatch.Alarm(this, 'my-alarm', {
  // ... rest of props
  threshold: myLambdaTimeout.toMilliseconds()
});

It would be really nice to be able to do myLambda.timeout.toMilliseconds() instead, as we can't currently validate that the timeout being passed in is from that particular lambda function.

This fixes #16047.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io

gitpod-io Bot commented Oct 15, 2021

Copy link
Copy Markdown

@peterwoodworth peterwoodworth changed the title feat(lambda): add timeout property to lambda function construct feat(lambda): add timeout property to lambda function construct Oct 21, 2021
@github-actions github-actions Bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Oct 21, 2021
@ben-eb

ben-eb commented Oct 22, 2021

Copy link
Copy Markdown
Contributor Author

Hello again,

I've updated this pull request to add an example use case in the readme in order for this to pass the validate-pr step. I'm happy to make any further amendments if needed.

Thanks! 👍

@ben-eb

ben-eb commented Nov 5, 2021

Copy link
Copy Markdown
Contributor Author

Hello,

I've updated the branch a few times due to it being out of date with the master branch. Is there anything else I can do to get this reviewed/merged?

Thanks. 🙂

@aws-cdk-automation

Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 2c6375d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@nija-at

nija-at commented Nov 5, 2021

Copy link
Copy Markdown
Contributor

Hi @ben-eb,

You do not need to update the branch regularly, unless you need the new updates on master. Our automation will take care of doing so once approved.

/**
* The timeout configured for this lambda.
*/
public readonly timeout?: Duration;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think about returning the default value here instead of undefined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For our needs, an optional value is OK because we could throw an exception if the timeout was not defined.

A non-optional value would be a better API but this value is not guaranteed to be in the CloudFormation template. As such, if the default were changed in the future it might lead to CDK reporting a timeout value different to the one deployed to Lambda.

However, I'm happy to make that change if you're OK with this caveat. 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, fair enough. Let's leave it as is.

@nija-at nija-at changed the title feat(lambda): add timeout property to lambda function construct feat(lambda): timeout property to lambda function construct Nov 5, 2021
@mergify

mergify Bot commented Nov 5, 2021

Copy link
Copy Markdown
Contributor

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@ben-eb

ben-eb commented Nov 19, 2021

Copy link
Copy Markdown
Contributor Author

Hey @nija-at,

I've created a new pull request with the "allow edits from maintainers" option checked, as it is currently unsupported for organisation accounts: #17594

Thanks for your patience! 👍

@ben-eb ben-eb closed this Nov 19, 2021
@ben-eb
ben-eb deleted the gh16047-add-function-timeout branch November 26, 2021 14:40
mergify Bot pushed a commit that referenced this pull request Nov 26, 2021
Supersedes #17000.

I didn't realise that the "allow edits by maintainers" was not supported under organisation accounts, so I've forked under my account instead. Otherwise, these changes are the same as the linked PR.

Thanks! 👍 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
beezly pushed a commit to beezly/aws-cdk that referenced this pull request Nov 29, 2021
Supersedes aws#17000.

I didn't realise that the "allow edits by maintainers" was not supported under organisation accounts, so I've forked under my account instead. Otherwise, these changes are the same as the linked PR.

Thanks! 👍 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
pedrosola pushed a commit to pedrosola/aws-cdk that referenced this pull request Dec 1, 2021
Supersedes aws#17000.

I didn't realise that the "allow edits by maintainers" was not supported under organisation accounts, so I've forked under my account instead. Otherwise, these changes are the same as the linked PR.

Thanks! 👍 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
Supersedes aws#17000.

I didn't realise that the "allow edits by maintainers" was not supported under organisation accounts, so I've forked under my account instead. Otherwise, these changes are the same as the linked PR.

Thanks! 👍 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
ali-n4i pushed a commit to ali-n4i/aws-cdk that referenced this pull request Jul 29, 2026
Supersedes aws#17000.

I didn't realise that the "allow edits by maintainers" was not supported under organisation accounts, so I've forked under my account instead. Otherwise, these changes are the same as the linked PR.

Thanks! 👍 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@aws-cdk/aws-lambda Related to AWS Lambda

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws-lambda): add timeout property to Function

3 participants