aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 820 forks source link

add lambda trigger for auth post signup via `function add` #3927

Open cyrfer opened 4 years ago

cyrfer commented 4 years ago

Is your feature request related to a problem? Please describe.

I'd like to insert a new record into a user collection when a user confirms signup. This seems like a trivial thing. It's not. Since GraphQL mutations can be observed, I'd like to use the API (from the triggler lambda) to insert the record.

It seems impossible to add a trigger for auth post-confirm events that can invoke the API.

The closest I've come is:

amplify auth add
...
amplify api add
...
amplify auth update
...choose crazy options to let me setup a trigger
...MISSING ABILITY TO DEFINE PERMISSIONS TO ACCESS API RESOURCE

With this flow, I am blocked as I cannot get access to the API resource injected into my lambda code.

Also, I don't love the name chosen for the lambda resource. It seems based on the poorly chosen name for the auth resource.

Describe the solution you'd like

I expect the following flow to work:

amplify auth add
...
amplify api add
...
amplify function add
...
? What event source do you want to associate with Lambda trigger? (Use arrow keys)
❯ Amazon DynamoDB Stream 
  Amazon Kinesis Stream 
  Amazon Cognito User Pool Post Confirm // CURRENTLY MISSING
...
...choose permissions to access API resource
...
# no longer needed - amplify auth update

Describe alternatives you've considered Already mentioned above.

Additional context Has anyone used the lambda trigger feature? It's touted here and here, but it's really difficult to setup.

I mean, how do you even start the mentioned "manual Auth CLI workflow"? It's really buried under "amplify auth update". https://aws-amplify.github.io/docs/cli-toolchain/quickstart#adding-a-lambda-trigger

cyrfer commented 4 years ago

...and I just learned that the code generated has no file named index.js which is expected by the deployment and runtime errors occur because it is missing. Instead custom.js has the .handler entry point.

🐛 BUG

hisham commented 4 years ago

+1. Any update on this? I want to add a "Migrate User Lambda Trigger" but the new documentation does not mention how to add triggers at all: https://docs.amplify.aws/cli/auth/overview

cyrfer commented 4 years ago

I have a new plan for solving this. I think you can use the CLI to scaffold a basic function resource, and then manually enhance the generated cloudformation template.

There is a pretty nice DSL for passing parameters around, and you can hack the cloudformation template to accept and use these parameters. For an example injecting parameters, see https://github.com/aws-amplify/amplify-cli/issues/3240#issuecomment-623499312

smakinson commented 4 years ago

Noticed this issue after I opened a related one, so linking it: https://github.com/aws-amplify/amplify-cli/issues/4326

Stvad commented 3 years ago

Any updates on this?

AndyMeagher commented 2 years ago

Any updates?

exaucae commented 1 year ago

Looks like this is an old request. I recently opened https://github.com/aws-amplify/amplify-cli/issues/12608 for the same reasons.