serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

Provisioned Concurency is not smart enough to act based on input values

Open Karthi96 opened this issue 5 years ago • 5 comments

Description:

I'm using the SAM framework for deployment across all environments. we do have dev, stage, prod envs, but only for prod, i need to make provisioned concurrency as 1 for lower env it should be zero. so I decided to go with runtime parameter value and lambda fails on creating when provisioned concurrency parameter is 0

Screenshot from 2021-02-05 11-05-32

Expected result:

It should be smart enough to act based on the values.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Ubuntu
  2. If using SAM CLI, sam --version: SAM CLI, version 0.51.0
  3. AWS region: all

Add --debug flag to any SAM CLI commands you are running

Karthi96 avatar Feb 05 '21 05:02 Karthi96

This is a difficult one.

So, this isn't a SAM or a CloudFormation problem but a Lambda problem.

0 and non existent are 2 distinct states that we opted to support only 1. The reason for this, is that provisioned concurrency "does different things under the hood" and these things are visible to the customer.

One visible example: Metrics. You get more of those for PC. Does 0 mean that you have PC and that all of it is spillover or that you don't want it enabled? The obvious answer is "just don't emit on a 0 value"! At the time of release we didn't have those answers fully formed, but after a year of operation, it's worth investigating.

In the meantime, you can use conditions of 0 as an input to conditionally return nil in cfn, which though it does give you a way to fix it, it does look ugly in code :/

iph avatar Feb 11 '21 06:02 iph

@iph would you provide an example on how the condition may look like? something like:

  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      AutoPublishAlias: a1
      ProvisionedConcurrencyConfig:
        ProvisionedConcurrentExecutions: AWS::NoValue

fails as nil is not allowed for ProvisionedConcurrentExecutions (Resource creation cancelled Encountered non numeric value for property ProvisionedConcurrentExecutions)

elbayaaa avatar Feb 11 '21 16:02 elbayaaa

I believe it's on the Config that you want it, not the number value.

iph avatar Feb 11 '21 16:02 iph

I see your point. So in this case, we can conditionally(on prod env) create a AWS::Lambda::Version with the required provisioned concurrency.

@Karthi96 I am going to close the issue as it is by design. Meanwhile, please see if this workaround solves your problem:

Conditions:

  ProdEnv: ...

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      ...
  MyFunctionVersion:
    Type: AWS::Lambda::Version
    Condition: ProdEnv
    Properties:
      FunctionName: !Ref MyFunction
      ProvisionedConcurrencyConfig:
        ProvisionedConcurrentExecutions: 1

elbayaaa avatar Feb 11 '21 16:02 elbayaaa

If you want to use AutoPublishAlias and still use conditions this will work:

Conditions:
  ProdDeployment...

MyFunction:
      Type: AWS::Serverless::Function
      Properties:
        AutoPublishAlias: Live
        ProvisionedConcurrencyConfig:
          !If [ProdDeployment, ProvisionedConcurrentExecutions: 1, !Ref AWS::NoValue]

ahurlburt avatar Feb 23 '22 01:02 ahurlburt