Amplify-cli: Adding Lambda Layer to existing function clears "dependsOn" in backend-config.json

Created on 16 Jul 2020  路  6Comments  路  Source: aws-amplify/amplify-cli

Note: If your issue/bug is regarding the AWS Amplify Console service, please log it in the
Amplify Console GitHub Issue Tracker

Describe the bug
Adding Lambda Layer to existing function clears "dependsOn" in backend-config.json

Amplify CLI Version
4.24.2

To Reproduce

  1. Create new Amplify project (I followed getting started for JavaScript)
  2. amplify add api (GraphQL, default settings)
  3. amplify add function (NodeJS, Hello World Function).
  4. amplify add function (create new Layer).

At this moment function is not using the layer. This is backend-config.json

"testclilambda6938ce0a": { "build": true, "providerPlugin": "awscloudformation", "service": "Lambda", "dependsOn": [ { "category": "api", "resourceName": "testclilambda", "attributes": [ "GraphQLAPIIdOutput", "GraphQLAPIEndpointOutput" ] } ] },

  1. amplify update function (add the layer created in step 4 to the function)
    backend-config.json is now:

"testclilambda6938ce0a": { "build": true, "providerPlugin": "awscloudformation", "service": "Lambda", "dependsOn": [ { "category": "function", "resourceName": "myLayer", "attributes": [ "Arn" ] } ] }

Dependency on API dissapeared. If we push the Lambda now, environment variable will not have GraphQL API endpoint and Id.

Expected behavior
Adding the layer should add to existing dependsOn, not replace them.

Screenshots
This is what ENV variables look like after the deployment:

image

Desktop (please complete the following information):

  • OS: Windows 10
  • Node Version. v12.17.0

Additional context

Here's a question: How to rebuild my function - i.e. eve after manually updating backend-config.json - when deployed, the function still does not have environemtent variables set?

bug functions

Most helpful comment

This is a bug with amplify update function.

The current workaround to update a function without losing dependsOn data, is to always answer yes to "Do you want to update the Lambda function permissions to access other resources in this project?" and confirm any existing permissions. Then you can add a Lambda layer or schedule invocation without it overwriting data in the dependsOn array.

All 6 comments

Found an answer to my own question: after manually updating backend-config.json, you should run

amplify env checkout <env-name>

https://github.com/aws-amplify/amplify-cli/issues/3426

+1 - unexpectedly having to re-add dependencies to all my functions. Thank you for adding layers though!

+1. I'm seeing same issue. In my case my lambda function had a dependsOn auth category.

This is a bug with amplify update function.

The current workaround to update a function without losing dependsOn data, is to always answer yes to "Do you want to update the Lambda function permissions to access other resources in this project?" and confirm any existing permissions. Then you can add a Lambda layer or schedule invocation without it overwriting data in the dependsOn array.

Somewhat related warning for those also using layers... https://github.com/aws-amplify/amplify-cli/issues/4892. Be very careful and check your dev amplify env first to see if things are resetting.

A fix was merged and deployed in Amplify CLI version 4.26.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jkeys-ecg-nmsu picture jkeys-ecg-nmsu  路  3Comments

amlcodes picture amlcodes  路  3Comments

darrentarrant picture darrentarrant  路  3Comments

onlybakam picture onlybakam  路  3Comments

kangks picture kangks  路  3Comments