amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Removing dependency on layer for lambda function fails to push

Open ymentha14 opened this issue 2 years ago • 8 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

npm install -g @aws-amplify/cli

If applicable, what version of Node.js are you using?

v18.12.0

Amplify CLI Version

10.5.1

What operating system are you using?

Arch linux

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Amplify Categories

function

Amplify Commands

add, push, update

Describe the bug

After removing the dependency of a lambda function on a lambda layer (both created with amplify cli) and trying to push, the following error is thrown:

Reason: Resource handler returned message: "1 validation error detected: Value '[functionfoofooBarArn]' at 'layers' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 140, Member must have length greater than or equal to 1, Member must satisfy regular expression pattern: (arn:[a-zA-Z0-9-]+:lambda:[a-zA-Z0-9-]+:\d{12}:layer:[a-zA-Z0-9-_]+:[0-9]+)|(arn:[a-zA-Z0-9-]+:lambda:::awslayer:[a-zA-Z0-9-_]+), Member must not be null] (Service: Lambda, Status Code: 400, Request ID: #############)" (RequestToken: #############, HandlerErrorCode: InvalidRequest) URL: ####

Expected behavior

The push should complete and the function should be updated with no dependency on the lambda layer in the cloud backend.

Reproduction steps

  1. amplify init

? Enter a name for the project bar The following configuration will be applied:

Project information | Name: bar | Environment: dev | Default editor: Visual Studio Code | App type: javascript | Javascript framework: none | Source Directory Path: src | Distribution Directory Path: dist | Build Command: npm run-script build | Start Command: npm run-script start

? Initialize the project with the above configuration? Yes Using default provider awscloudformation ? Select the authentication method you want to use: AWS profile

? Please choose the profile you want to use default

  1. amplify add function

? Select which capability you want to add: Lambda function (serverless function) ? Provide an AWS Lambda function name: foo ? Choose the runtime that you want to use: Python Only one template found - using Hello World by default.

? Do you want to configure advanced settings? No ? Do you want to edit the local lambda function now? No Successfully added resource foo locally.

  1. amplify add function ? Select which capability you want to add: Lambda layer (shared code & resource used across functions) ? Provide a name for your Lambda layer: bar ? Choose the runtime that you want to use: Python ? The current AWS account will always have access to this layer. Optionally, configure who else can access this layer. (Hit <Enter> to skip) ✅ Lambda layer folders & files created: amplify/backend/function/barbar

  2. amplify push --yes

  3. amplify update function

? Select which capability you want to update: Lambda function (serverless function) ? Select the Lambda function you want to update foo General information

  • Name: foo
  • Runtime: python

Resource access permission

  • Not configured

Scheduled recurring invocation

  • Not configured

Lambda layers

  • Not configured

Environment variables:

  • Not configured

Secrets configuration

  • Not configured

? Which setting do you want to update? Lambda layers configuration ? Do you want to enable Lambda layers for this function? Yes ? Provide existing layers or select layers in this project to access from this function (pick up to 5): barbar ? Select a version for barbar: Always choose latest version ? Do you want to edit the local lambda function now? No

  1. amplify push --yes
  2. amplify update function ? Select which capability you want to update: Lambda function (serv erless function) ? Select the Lambda function you want to update foo General information
  • Name: foo
  • Runtime: python

Resource access permission

  • Not configured

Scheduled recurring invocation

  • Not configured

Lambda layers

  • barbar

Environment variables:

  • Not configured

Secrets configuration

  • Not configured

? Which setting do you want to update? Lambda layers configuration ? Do you want to enable Lambda layers for this function? No ? Do you want to edit the local lambda function now? No

  1. amplify push --yes (see below for error log)

GraphQL schema(s)

# Put schemas below this line


Project Identifier

No response

Log output

# Put your logs below this line
✔ Successfully pulled backend environment dev from the cloud.

    Current Environment: dev

┌──────────┬───────────────┬───────────┬───────────────────┐
│ Category │ Resource name │ Operation │ Provider plugin   │
├──────────┼───────────────┼───────────┼───────────────────┤
│ Function │ foo           │ Update    │ awscloudformation │
├──────────┼───────────────┼───────────┼───────────────────┤
│ Function │ barbar        │ No Change │ awscloudformation │
└──────────┴───────────────┴───────────┴───────────────────┘
Installing dependencies from Pipfile.lock (e02f68)...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

Deploying resources into dev environment. This will take a few minutes. ⠏
Deploying root stack bar [ =============--------------------------- ] 1/3
        amplify-bar-dev-94213          AWS::CloudFormation::Stack     UPDATE_IN_PROGRESS             Fri Nov 25 2022 09:58:17…
        functionfoo                    AWS::CloudFormation::Stack     UPDATE_IN_PROGRESS             Fri Nov 25 2022 09:58:21…
Deploying resources into dev environment. This will take a few minutes. ⠸
Deploying root stack bar [ ===========================------------- ] 2/3
        amplify-bar-dev-94213          AWS::CloudFormation::Stack     UPDATE_ROLLBACK_COMPLETE       Fri Nov 25 2022 09:59:34…
        functionfoo                    AWS::CloudFormation::Stack     UPDATE_FAILED                  Fri Nov 25 2022 09:58:32…
Deployment failed.
Deploying root stack bar [ ===========================---
        amplify-bar-dev-94213          AWS::CloudFormation::Stac
        functionfoo                    AWS::CloudFormation::Stac
        functionbarbar                 AWS::CloudFormation::Stac
Deploying function foo [ --------------------------------
        LambdaFunction                 AWS::Lambda::Function
Deployed function barbar [ ==============================

🛑 The following resources failed to deploy:
Resource Name: LambdaFunction (AWS::Lambda::Function)
Event Type: update
Reason: Resource handler returned message: "1 validation error detected: Value '[functionbarbarArn]' at 'layers' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 140, Member must have length greater than or equal to 1, Member must satisfy regular expression pattern: (arn:[a-zA-Z0-9-]+:lambda:[a-zA-Z0-9-]+:\d{12}:layer:[a-zA-Z0-9-_]+:[0-9]+)|(arn:[a-zA-Z0-9-]+:lambda:::awslayer:[a-zA-Z0-9-_]+), Member must not be null] (Service: Lambda, Status Code: 400, Request ID: 0771c7cf-18ea-4d21-ac31-01bdec89dec1)" (RequestToken: 2a135d18-3e22-225a-ef41-827c8907fb65, HandlerErrorCode: InvalidRequest)
URL: https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/arn%3Aaws%3Acloudformation%3Aeu-west-1%3##########%3Astack%2Famplify-bar-dev-94213-functionfoo-#######/events


🛑 Resource is not in the state stackUpdateComplete

Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

Session Identifier: ##############


Additional information

No response

ymentha14 avatar Nov 24 '22 23:11 ymentha14

Hey @ymentha14, thank you for reaching out. I was able to reproduce the issue from the provided reproduction steps. Marking this as bug.

If the intention is to remove the existing Lambda layer, I was able to mitigate the issue by utilizing the following steps.

  1. amplify remove function (remove lambda layer)
  2. amplify update function
? Select the Lambda function you want to update <function name>
? Which setting do you want to update? Lambda layers configuration
? Do you want to enable Lambda layers for this function? Yes
? Enter up to 5 existing Lambda layer ARNs (comma-separated): (hit return/enter)
No Lambda layers were selected
Removing 1 previously added Lambda layer from Lambda function
? Do you want to edit the local lambda function now? No
  1. amplify push The updates push successfully without any errors.

ykethan avatar Nov 28 '22 15:11 ykethan

Hey @ykethan , the original intent was to try and bypass the deployment size limit (cf serverless-layers#51) which was suddenly preventing me from pushing. As a temporary fix I duplicated the whole environment after modifying my function and was able to push the newly created resources.

ymentha14 avatar Nov 28 '22 22:11 ymentha14

Note for fix: consider skipping the following prompt when updating a function and choosing to modify the Lambda Layer Configuration

? Do you want to enable Lambda layers for this function? Yes

josefaidt avatar Nov 29 '22 21:11 josefaidt

I'm getting this same error message but without making any changes to my lambda functions or layers. This issue appears following an upgrade from cli 10.8.1 to 11.0.3

naedx avatar Mar 30 '23 01:03 naedx

I was able to get around the issue by locating the the specific lambda function whose deployment triggered the error, then removing the lambda layer configurations, push, then re-add the layer.

naedx avatar Mar 31 '23 03:03 naedx

I'm experiencing a possibly related issue. I

  • Added a dep to my Pipfile in python lambda
  • Tried to amplify push, it failed due to size restraints
  • Removed the dep, tried to push again, and it still fails as the CLI fails to remove the large deps from the dist/latest-build.zip

This occurs, despite using the exact same Pipfile and Pipfile.lock that was previously working.

Where does Amplify keep the cache related to the builds? Is there anyway to clear this?

Can open a separate issue ticket if needed.

Update: Amplify unit/pull does not reset this cache, still seeing the inflated dist. For context, this is an M1 MacBook Pro.

e-simpson avatar Jan 18 '24 20:01 e-simpson

I've tried:

  • clearing the pipenv cache (pipenv --clear)
  • deleting the related deployment artifacts from S3
  • Deleted the lambda with amplify remove function and then re-created it with the same name

No luck. Still getting the old dependencies in the builds.

e-simpson avatar Jan 19 '24 16:01 e-simpson

Not sure why this wasn't working before.

Using 'pipenv clean' removed the old deps for me.

Although it is standard practice. Perhaps this needs to be included in the python lambda build steps. Or mentioned in the docs & cli error messages. I'll create some PRs if I find the time.

e-simpson avatar Jan 22 '24 20:01 e-simpson