Provisioned Concurency is not smart enough to act based on input values
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

Expected result:
It should be smart enough to act based on the values.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Ubuntu
- If using SAM CLI,
sam --version: SAM CLI, version 0.51.0 - AWS region: all
Add --debug flag to any SAM CLI commands you are running
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 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)
I believe it's on the Config that you want it, not the number value.
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
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]