Delete an old version of lambda(with provisioned concurrency) after new version is created

0

We have lambda one-box aliases with provisioning concurrency setup on these aliases. I'd like to delete old version of one-box alias after new one-box version creation. For this, we are trying to use

await lambda.waitFor('functionUpdatedV2', { FunctionName: `${FunctionName}:${ONEBOX_ALIAS_NAME}` }).promise();

to wait until newer version is setup. But, this returns DELETE-FAILED operations in Cfn stacks with ResourceConflictException and after roughly 3 minutes, the delete function operation retries itself and succeeds. So,

  1. does this mean lambda.waitFor() doesn't wait until Provisioning concurrency is setup on newer version of lambda?
  2. We have used static waits(i.e. calling getProvisionedConcurrencyConfig() periodically) and based on the Status property being READY, we performed delete operation. This succeeds. But can we omit the static waits and use some lambda-waiters or lambda-functionality to delete the old alias version after new alias is created?

Thanks.

AWS
asked a month ago109 views
1 Answer
2

Hi It seems like you're encountering an issue with the lambda.waitFor() method not behaving as expected when waiting for the provisioning concurrency to be set up on a newer version of a Lambda function before deleting the old version.

lambda.waitFor() should indeed wait until the specified event occurs, but it's possible that it might not be the most suitable method for waiting on the provisioning concurrency setup.

One alternative approach you mentioned is periodically checking the status of the provisioning concurrency using getProvisionedConcurrencyConfig() until it's in the "READY" state before proceeding with the deletion of the old alias. This approach seems reasonable and practical.

Here's how you can implement it:

  • After creating the new version of the Lambda function, periodically check the status of the provisioning concurrency for that version.
  • Once the provisioning concurrency is in the "READY" state, proceed with deleting the old version of the alias. Here's a rough outline of how you can achieve this:

javascript

async function waitForProvisionedConcurrency(functionName, aliasName, version) {
    const params = {
        FunctionName: functionName,
        Qualifier: `${version}:${aliasName}`
    };

    let provisionedConcurrencyConfig;
    do {
        // Get the provisioned concurrency configuration
        provisionedConcurrencyConfig = await lambda.getProvisionedConcurrencyConfig(params).promise();

        // Check if the status is "READY"
        if (provisionedConcurrencyConfig.Status === 'READY') {
            return;
        }

        // Wait for a certain period before checking again
        await new Promise(resolve => setTimeout(resolve, 5000)); // Wait for 5 seconds
    } while (true);
}

// Example usage after creating the new version
const functionName = 'your-function-name';
const aliasName = 'your-alias-name';
const newVersion = 'new-version';

// Wait for provisioning concurrency to be ready
await waitForProvisionedConcurrency(functionName, aliasName, newVersion);

// Now, proceed with deleting the old version of the alias
// You can use whatever method you were using previously to delete the old alias

This approach should ensure that you wait until the provisioning concurrency is set up on the new version before deleting the old version of the alias. It eliminates the need for static waits and provides a more dynamic and efficient solution.

answered a month ago
  • Thanks Pandu Ranga Swamy for the answer. Yes, I tried the same. But I just wanted to explore any other ways of doing this, if possible involving lambda in-build methods/functionalities. Would appreciate if I get some help on this.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions