-
Notifications
You must be signed in to change notification settings - Fork 823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provisioned Concurrency for Lambda Functions #4865
Comments
We don't provide this out of the box. |
Also looking for a solution using Amplify |
@dseeker thats exactly what I did :) Until this is officially implemented in amplify-cli, I was able to modify my cloudformation template to include a version and alias that allows me to use provisioned concurrency like this:
|
@jadenv did you connect your lambda to API gateway at all? I'm having trouble here as API gateway doesn't integrate with the alias that has provisioned concurrency, it connects to "latest", not sure what changes i need to make here |
@tomhirschfeld yep, you will have to add Ex:
|
@jadenv where in the standard amplify stack does this live? I see the cloudformation-template.json for api/graphql is auto-generated under the /build directory, I expect this gets overridden in each publish? |
Actually if one is looking to map into the alias from a graphql function I think you can simply pass the alias in the function name. |
Hi @jadenv I tried a set up in cloudformation as you suggested for both the Function and API templates. The new resources were created correctly (alias, version and concurrency configurations). But API calls are not invoking the new version. Concurrency still doesn't work. Besides the edit in the API and Function CloudFormation templates you suggested is there anything else I should do? |
Worth making it clear if anyone else stumbles on this, the proposed solution doesn't fully work. This will publish a single LambdaVersion and Alias once, and will not update with subsequent changes. |
However...there is a potential workaround(not battle-tested and not for the faint of heart). Here is a rough sketch of a solution that seems to work for me Step1
Step 2Alter the cf template of the function to export s3Key(CF template Output). (this changes if the contents of the lambda changes, i.e. you want to publish a new version)
Step 3Create a new custom resource (https://docs.amplify.aws/cli/usage/customcf/) name it what you want, but ensure that it depends on the function you want to have provisioned concurrency (Name and your newly exported s3Key) Step 4Make the cf template include these two sections;
Step 5Create new lambda (amplify add function) lambdaversioner with contents that look like, exports.handler = (event, context) => {
console.log('Request received:', JSON.stringify(event)); // Print params so you can manually recover
const cf = require('cfn-response');
if (event.RequestType == 'Delete') {
return cf.send(event, context, "SUCCESS");
}
const AWS = require('aws-sdk');
const lambda = new AWS.Lambda();
const res = lambda
.publishVersion({FunctionName: event.ResourceProperties.FunctionName})
.promise()
.then(data => {
return cf.send(
event,
context,
"SUCCESS",
{Version: data.Version},
data.FunctionArn,
);
})
.catch(e => {
return cf.send(event, context, "FAILED", e);
});
}; Step 6Don't forget to 'amplify env pull' because backend-config.json changed Obviously any feedback anyone has, on the pitfalls of this approach, would be greatly appreciated. |
I am looking to add concurrency to my amplify app. Has there been any updates on this? Now I need publish a new version and assign the alias to it when I push to production. How can I achieve this? |
Is there any update on this feature-request? |
Seeing as this issue has been open for almost 4 years now, it seems this might be a bit too advanced of a use case for Amplify. I would recommend using AWS CDK as an alternative to configure Lambda autoscaling: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda-readme.html#autoscaling |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Which Category is your question related to?
Functions
Amplify CLI Version
4.24.2
What AWS Services are you utilizing?
API + Functions
Provide additional details e.g. code snippets
Is there a way to configure Provisioned Concurrency for Lambda Functions within the amplify-cli as documented here?
https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/
The biggest issue seems to be that you can't allocate provisioned concurrency on an alias that points to the unpublished version ($LATEST), so not sure how that would work in the cloudformation template as I don't believe you can reference a published version, but maybe I'm wrong about that.
Either way, does anybody have an example of how to do this? Cheers 🍻
The text was updated successfully, but these errors were encountered: