Sign in
Log inSign up
Michael Liendo

2 likes

·

2.5K reads

6 comments

Chris Zirkel
Chris Zirkel
Mar 22, 2022

Hi Michael!

I'm using Amplify on the frontend and it provides an API class to make Cognito authenticated requests. What is the recommended approach to make requests in a Node.js Lambda function with IAM? Amplify refers to this: docs.amplify.aws/lib/graphqlapi/graphql-fr…

That looks quite similar to your post. I was wondering if I also could use the official AWS AppSync SDK?

1
·
·2 replies
Michael Liendo
Michael Liendo
Author
·Mar 22, 2022

Hey! Yea, Totally doable without much work.

I have a blog post up that shows the code to do so, checkout the “Automatically Creating Users” section here: blog.focusotter.com/combining-nextjs-aws-a…

Let me know if that helps and thanks for checking out the post!

1
·
Chris Zirkel
Chris Zirkel
Mar 23, 2022

Michael Liendo it seems like the URL in my first comment got removed, so it was probably not 100% clear what I meant.

The AWS documentation for clients accessing GraphQL from the backend (like Lambdas) says:

To connect to your AWS AppSync GraphQL endpoints from your backend applications (such as AWS Lambda function or Amazon EC2 instances), we recommend using an HTTP client and signing your requests using IAM by following the Authorization and authentication guide. For more information on working with GraphQL in the backend, see GraphQL from NodeJS.

Then it links to the Amplify documentation about Signing a request from Lambda

I had some issues accessing my GraphQL API via HTTP and IAM and was wondering if there are other ways to access it from Lambda, for example the official AWS.AppSync SDK?

·
Pepe Medel
Pepe Medel
May 18, 2022

Hi Michael Liendo!

I think you have an error in your cdk routine, on line 49:

rule.addTarget(new targets.LambdaFunction(sampleFuncToAppSync)) I think the attribute/var that is passed to LambdaFunction should be "coffeeOrderReceivedFunc".

On the other hand, I have not been able to do something almost identical, in my case it is using the eventPattern aws.s3. the trigger is not added inside my lambda function, therefore it is not called when eventbridge detects the event from s3.

I've read a lot about this and am about to conclude that it's not possible to use addTarget on previously created resources from the amplify CLI, or at least not this command. This only works for resources created on the same CDK stack, apparently...

At the end of the Importing existing external resources section in /cdk/v2/guide/resources.html, says:

"Although you can use an external resource anywhere you'd use a similar resource defined in your app, you cannot modify the external resource. For example, calling addToResourcePolicy (Python: add_to_resource_policy) on an external s3.Bucket does nothing."

In your case, has it worked for you?

Thanks a lot and best regards.

·
·1 reply
Oscar Nevarez
Oscar Nevarez
Jul 14, 2022

Hey Pepe, you're right. You can't modify amplify resources through CDK.

I created a Lambda permission within the cloudformation file of my lambda function, referincing my Eventbridge rule created in CDK.

Hope it helps.

·
Selva Raj
Selva Raj
Oct 26, 2022

Hi Michael!

When we using the IAM update from lambda function the subscription query return the empty data. I have followed the your example. and subscription return value is onUpdateOrder: {status: null} from reactJs side. Please let me know how to solve this issues. update data working fine from lambada function inside. i have confirmed data with Dynamodb side.

·
Selva Raj
Selva Raj
Oct 28, 2022

Hello Michael! When we are using IAM update from lambda functions, the subscription query returns only empty data. I have followed your example and below is the subscription return value "onUpdateOrder: {status: null}" from reactJs side.

Please let me know how to solve this issue. Update data is working fine from lambda function. i have confirmed the data with our DynamoDB.

·