aws-amplify / aws-amplify/amplify-cli

Removing dependency on layer for lambda function fails to push

Open
#11,471 8 comments 1 reaction 0 assignees View on GitHub
bug functions lambda-layers ops-functions p3
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

### 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](https://github.com/aws-amplify/amplify-cli/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-cli/blob/dev/CONTRIBUTING.md#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

2. `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.

3. `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
to skip)
✅ Lambda layer folders & files created:
amplify/backend/function/barbar

4. `amplify push --yes`
5. `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

6. `amplify push --yes`
7. `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

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

### GraphQL schema(s)

```graphql
# 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_

Contributor guide

Open the contributing guide

Research direction

Start with the Amplify CLI function update and push flow described in the reproduction, focusing on how Lambda layer configuration is translated into the CloudFormation LambdaFunction update. Reproduce the sequence with the Python function and layer, then inspect the generated deployment state and confirm that a removed layer is absent from the update; done means push completes and the cloud function has no layer dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
backend, cli, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.