Problem
I have Lambda function for which i want to add provisioned concurrency.I can access the Lambda only as a lower level CfnFunction resource or a FunctionProxy imported via ARN. I do not have access to the higher level Function construct in the cdk stack directly which would give me access to the needed attributes and methods to add prov. concurrency as usual.
Details
My cdk stack setup consists of
- an
APIGateway REST APIrunning aLambdafunction as request handler - the
Lambdarequest handler has noAliasorVersion(uses default$LATEST) - the
APIGateway REST APIand theLambdafunction are created viacdk-chaliceand not defined in my stack directly. - this means they come from a pre-generated Cloudfomation template that gets then included into my main
cdkstack template. - so i have no higher level construct access to the
APIGatewayorLambdafunction - I only have lower level construct access (
CfnFunction) from importing theChalicegenerated template back in the cdk stack or imported theLambdafunction vialambda.from_function_arn()
Question
- Is there a way to add provisioned concurrency
- via manipulating the pre-generated Cloudformation template from
cdk-chalice? - by importing the lambda through
lambda.from_function_arn()then adding aVersionandScalableTarget? - via some tricks adding a
Versionfrom the lower level constructCfnFunction? - or maybe via some
AwsSdkCalls to generate aVersionfor the lambda and add PC wrapped in aAwsCustomResource?
- via manipulating the pre-generated Cloudformation template from
What I have tried so far
Importing the Lambda
# Pseudocode
handler = lambda.from_function_arn("arn-from-cdk-chalice-function")
# approach a - cdk deploy error: No current_version attribute on BaseFunctionImportProxy_
handler_version = handler.current_version
# approach b - cdk deploy error: Application Autoscaling cannot work with $LATEST
handler_version = handler.latest_version
target = appscaling.ScalableTarget(self, "ScalableTarget",
service_namespace=appscaling.ServiceNamespace.LAMBDA,
max_capacity=100,
min_capacity=10,
resource_id=f"function:{handler.functionName}:{handler_version.version}",
scalable_dimension="lambda:function:ProvisionedConcurrency"
)