aws lambda waiter to uploadcode

Viewed 193

I am trying to implement lambda waiter to upload my my lambda code. Here is the piece of code that uses waiter:

def update_function_code(config, publish = True):
    print('Updating function code')
    code_config = {**config['Code'],**{'FunctionName': config['function']['FunctionName'], 'Publish': publish}}
    boolean = wait_lambda_active()
    print(boolean)
    if boolean == True:
        response = lambda_client.update_function_code(**code_config)
        print('Failure waiting for lambda')
        return

    response = lambda_client.update_function_code(**code_config)

    return True

def wait_lambda_active():
    try:
        print('Getting waiter for lambda')
        print(config['function']['FunctionName'])
        waiter = lambda_client.get_waiter('function_active')
        waiter.wait(FunctionName =config['function']['FunctionName'],
                WaiterConfig={'Delay':delay, 'MaxAttempts':max_attempts})
    except Exception as e:
        print('Lambda is not in desired state')
        print(e)
        return False
    else:
        return True

I still get the error: botocore.errorfactory.ResourceConflictException: An error occurred (ResourceConflictException) when calling the UpdateFunctionCode operation: The operation cannot be performed at this time. An update is in progress for resource: arn:aws:lambda:us-east-1:xxxxxxxxx:function:xxxxxxxxxx

TIA

1 Answers

The reason you're seeing this error is that a previous function code update hasn't been completed yet and a new update is called.

To properly wait for the function code update, I used function_updated instead of function_active as the function code is being updated.

Here is the code:

    try:
        print('Getting waiter for lambda')
        waiter = lambdaClient.get_waiter('function_updated')
        waiter.wait(FunctionName=projectName)
        response = lambdaClient.get_function(
            FunctionName=projectName
        )
        print(response['Configuration']['LastUpdateStatus'])
    except Exception as e:
        print('Lambda is not in desired state')
        print(e)
Related