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

AWS_IAM API Gateway Auth in Next.js getStaticProps() withSSRContext() #6960

Open deldrid1 opened 4 years ago

deldrid1 commented 4 years ago

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

I have an API Gateway setup to use AWS_IAM and require an AWS Signature Version 4 to provide data. I have deployed this using the serverless framework and have lambda's tied into Dynamo DB (using the server side AWS SDK for Javascript) and have tested everything working end to end using a REST Client

I am trying to figure out how to do access this API inside of next.js's getStaticProps using the new withSSRContext() function as described here

Describe the solution you'd like

This may be a documentation gap or a personal knowledge gap, but so far I've struck out. I'm new to the AWS ecosystem so if I am just missing something obvious please point it out.

I don't see an API Gateway equivalent of AWS.DynamoDB.DocumentClient().get() in the AWS SDK for Node or in Amplify that uses environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to create the needed tokens for trusted server authorization.

On the client side and on the server side in getServerSideProps, my understanding is that AWS Amplify

Unfortunately, I can't figure out how to provide credentials to the API class when there isn't a cognito user in play such as in getStaticProps...

Describe alternatives you've considered

Any thoughts on how to get this all plumbed up?

cwomack commented 1 year ago

@deldrid1, apologies on how long it's taken for you to get a response on this issue. There's been updates to the documentation surrounding Next.js and SSR recently... AND we've just released support today for Next.js v12+ via a new Amplify Hosting compute managed SSR provider. Can you verify if you're still experiencing this issue?

Here's links to the updated guides: Amplify support for Next.js SSR Next.js Tutorial - API with SSR

mtliendo commented 1 year ago

I just ran into this issue today.