The lambda function is created using serverless(2.22) and is deployed using codebuild (standard5.0). I want to conditionally set the provisioned concurrency only for UAT and Prod env and not for dev and test env.
These are the things I tried:
serverless.yml:
...
alarms:
- functionErrors
Conditions:
isProdOrUAT: {"Fn::Or": [{"${opt:stage}": "prod"}, {"${opt:stage}": "uat"}]}
functions:
TestApi:
handler: test.api.StreamLambdaHandler::handleRequest
description: Lambda function for the Test API
timeout: 20
custom: !If [isProdOrUAT, "${file(./provisionedconcurrency.yml)}", !Ref "AWS::NoValue"]
provisionedconcurrency.yml
provisionedConcurrency: "${ssm:/${opt:stage}/TestsServiceProvisionedConcurrency}"
In this case what happens is, it imports the file successfully, build also passes. But there is no provisioned concurrency attached in the lambda configuration for UAT and Prod.
serverless.yml
...
alarms:
- functionErrors
Conditions:
isProdOrUAT: {"Fn::Or": [{"${opt:stage}": "prod"}, {"${opt:stage}": "uat"}]}
functions:
TestApi:
handler: test.api.StreamLambdaHandler::handleRequest
description: Lambda function for the Test API
timeout: 20
provisionedConcurrency: !If [isProdOrUAT, "${ssm:/${opt:stage}/TestsServiceProvisionedConcurrency}", !Ref "AWS::NoValue"]
In this case getting the following error
Error --------------------------------------------------
Error: The CloudFormation template is invalid: [/Resources/TestApiProvConcLambdaAlias/Type/ProvisionedConcurrencyConfig/ProvisionedConcurrentExecutions] 'null' values are not allowed in templates
Checked the serverless-state.json, found this to be there.
"Name": "provisioned",
"ProvisionedConcurrencyConfig": {
"ProvisionedConcurrentExecutions": null
}