aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.43k stars 2.13k forks source link

Amplify JS support for Node #7058

Open GeorgeBellTMH opened 4 years ago

GeorgeBellTMH commented 4 years ago

I am having trouble figuring out how to make use of the process.env.AWS_ACCESS_KEY_ID/process.env.AWS_SECRET_ACCESS_KEY in a lambda/dynamodb trigger that I have created. Would be great to auto login with AWS_IAM...

I assume everything is nearly in place for this to just work, since it does when using aws-sdk...

I don't see anything in Amplify.default.configure() or from Amplify.Auth.signIn() to allow this to happen, and I don't see any documentation on how to do this...

ammarkarachi commented 4 years ago

@GeorgeBellTMH what do you intend to do with the keys? A little more context would be helpful

GeorgeBellTMH commented 4 years ago

Sure. For example, with aws-sdk it uses them to automatically become the aws_iam user, so without any extra work I can access ses or dynamo etc...however I would like to use my graphql using the amplify mechanisms - ie auth: iam, private - and be able to do further read/writes without having to either login as an iam user manually, or you a user pool.

My use case is sending alerts to users from a message table...the message dynamo table has a lambda trigger which then needs to look up more information about the user to determine if it can send them a message...it gets the message in the lambda trigger properties, then uses amplify.API to look up the user, followed by using ses to send the email. Ses doesn't require a login, amplify does.

kaustavghosh06 commented 4 years ago

@GeorgeBellTMH Amplify JS is not currently support for NodeJS lambda's and is supported only for web-browsers for now. You can still use the GraphQL API from your Lambda function using the steps mentioned here - https://docs.amplify.aws/cli/function#graphql-from-lambda

GeorgeBellTMH commented 4 years ago

Understood. This would go a long way to allowing it to be supported in lambda's.

This would open up ability for things like automatically putting the API.ts and queries/mutations into the lambdas via lambda layers from the cli.

I would suggest that at the least Auth and API should be supported in lambda to make development of more complex lambdas easier.

Let me know if I should make a more general ticket/feature request.

Just from my personal experience it does run, just you have to login manually - which means passing user/password around.

kaustavghosh06 commented 4 years ago

Got it. Yes, I'll move over the Amplify for NodeJS support to the Amplify JS repo for them to track.