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

Lambda trigger cannot access other lambda functions

Open nxia416 opened this issue 3 years ago • 1 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?

yarn

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

v16.14.2

Amplify CLI Version

9.1.0

What operating system are you using?

Mac

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

Describe the bug

The new lambda trigger for dynamodb, cannot access other lambda functions (or dynamo tables).

Expected behavior

The lambda trigger should get the response from the callee lambda.

Reproduction steps

  1. create a new, clean amplify project
  2. add graphql API. I am using the one-to-many example

image

  1. create a function to be called (testCallee)

image

  1. add the lambda trigger

image

  1. update the function

image

  1. the output log (from test event)

image

The problem is the await lambda.invoke(params).promise() line not working. There should be some erorrs or reponses, but it seems the thread is killed silently.

GraphQL schema(s)

# Put schemas below this line
# This "input" configures a global authorization rule to enable public access to
# all models in this schema. Learn more about authorization rules here: https://docs.amplify.aws/cli/graphql/authorization-rules
input AMPLIFY {
  globalAuthRule: AuthRule = { allow: public }
} # FOR TESTING ONLY!
type Blog @model {
  id: ID!
  name: String!
  posts: [Post] @hasMany
}

type Post @model {
  id: ID!
  title: String!
  blog: Blog @belongsTo
  comments: [Comment] @hasMany
}

type Comment @model {
  id: ID!
  post: Post @belongsTo
  content: String!
}


Project Identifier

➜ testTrigger amplify diagnose --send-report

Learn more at https://docs.amplify.aws/cli/reference/diagnose/

✅ Report saved: /var/folders/2j/4v3x_j4x7x509ghkl7dwcps80000gp/T/testTrigger/report-1662357560078.zip

✔ Done

Project Identifier: f5a3b30854f88a8b2a2549e91d848f02

Log output

# Put your logs below this line


Additional information

No response

nxia416 avatar Sep 05 '22 06:09 nxia416

Hey @nxia416 :wave: thanks for raising this! I noticed you're using async with Array.forEach, which unfortunately is likely the cause of what you're seeing. If you migrate this to use for..of does it function as expected?

for (const record of event.Records) {
  // ...
  await invoke(params)
}

For reference here is a short gist I found that explains this issue with async/await and forEach in more detail: https://gist.github.com/joeytwiddle/37d2085425c049629b80956d3c618971

josefaidt avatar Sep 06 '22 13:09 josefaidt