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 821 forks source link

Can I use lambda functions inside pipelines? #3685

Closed Ricardo1980 closed 4 years ago

Ricardo1980 commented 4 years ago

Hello,

Right now I am using pipelines in several use cases, very often, in the first function I get info about the current user, and in the second function, I do something. Those both functions use SQL and Aurora serverless. I had to do that manually editing the cloud formation templates.

Now I would like to do this: A pipeline with 2 functions, the first one gets the current user from Aurora Serverless using SQL, and the second function is a lambda function that using SES sends an email. Is this technically possible? Using SQL and Lambda in the same pipeline? If that is the case, do you know any sample or website?

Here I read about the @function directive, but seems useless in my scenario, basically because when the client calls the function, I do need a SQL request to get info about the current user. https://aws-amplify.github.io/docs/cli-toolchain/graphql#usage-1

Maybe, another option is to retrieve the current user inside the lambda function, but seems more complex and I have no idea about how to pass database access credentials to the lambda function. Seems a pipeline could be easier, moreover, I reuse my function to get the current user a lot in several pipelines. What do you think?

When adding a lambda function, I see this: "CRUD function for Amazon DynamoDB table (Integration with Amazon API Gateway and Amazon DynamoDB)" Can you add the same option but for Aurora? When adding an API, we have that option.

Thanks a lot for your suggestions.

Which Category is your question related to? APIs, databases and lambda.

Amplify CLI Version 4.13.3

What AWS Services are you utilizing? AppSync, Aurora, Lambda, CloudFormation

Ricardo1980 commented 4 years ago

Well, yes, it is possible. Here an example: https://github.com/incr3m/aws-amplify-starter/blob/master/amplify/backend/api/testampl2/stacks/AppVersionQueryResource.json

You use Lambda resolvers, and once that is working, embed it into a pipeline. https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html

Mine is already working. Just note that the arguments passed, can be accessed in the second function, I thought stash was needed, but nope.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.