pulumi / pulumi-aws

An Amazon Web Services (AWS) Pulumi resource package, providing multi-language access to AWS
Apache License 2.0
449 stars 155 forks source link

ProvisionedConcurrencyConfig for API Gateway not staying warm #1474

Closed njbmartin closed 3 years ago

njbmartin commented 3 years ago

Creating ProvisionedConcurrencyConfig for API Gateway does not work as expected. Followed this blog: https://www.pulumi.com/blog/aws-lambda-provisioned-concurrency-no-cold-starts/

Granted, it's for pure lamba functions, but would expect this to work the same?

const fetchSurveyLambda = new aws.lambda.CallbackFunction(
  `${appName}-fetchSurveyLambda`,
  {
    callback: fetchSurvey,
    publish: true,
  }
)
new aws.lambda.ProvisionedConcurrencyConfig(
  `${appName}-fetchSurveyLambda-warmer`,
  {
    functionName: fetchSurveyLambda.name,
    qualifier: fetchSurveyLambda.version,
    provisionedConcurrentExecutions: 2,
  }
)

After 5 minutes of inactivity on the endpoint, it takes at least 5s to warm up, once warm, requests take milliseconds as expected. It never stays warm though.

Expected behavior

The endpoint should always be warm and take ms to respond.

Current behavior

After a period of inactivity on the endpoint, the endpoint takes 5s+ to warm up again.

Steps to reproduce

  1. See example above

Context (Environment)

Affected feature

njbmartin commented 3 years ago

This might be an upstream issue, so I'm raising with AWS Support

njbmartin commented 3 years ago

Spent a good hour speaking with AWS Support who walked me through some debugging and potential causes for the slow "cold start". It had nothing to do with the lambda instance, but the code. Will create another issue for this as it doesn't seem right that it takes a few seconds to initialise aws.sdk.DynamoDB.DocumentClient();