Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
deldrid1 opened this issue Oct 13, 2020 · 2 comments
Open
Labels
API Related to REST API issues feature-request Request a new feature SSR Issues related to Server Side Rendering

Comments

@deldrid1
Copy link

deldrid1 commented Oct 13, 2020

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

  • Authenticates against a Cognito User Pool and acquire a user token using the Auth class
  • When an API call is made
    • With the user token, Amplify gets temporary IAM credentials from the Cognito Identity Pool using the custom role that I have setup
    • the API class uses the IAM credentials to sign our API request with Signature Version 4.

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?

@deldrid1 deldrid1 added the feature-request Request a new feature label Oct 13, 2020
@amhinson amhinson added the SSR Issues related to Server Side Rendering label Oct 19, 2020
@cwomack cwomack self-assigned this Nov 17, 2022
@cwomack
Copy link
Member

cwomack commented Nov 17, 2022

@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

@nadetastic nadetastic added the API Related to REST API issues label Feb 1, 2023
@mtliendo
Copy link

I just ran into this issue today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Related to REST API issues feature-request Request a new feature SSR Issues related to Server Side Rendering
Projects
None yet
Development

No branches or pull requests

5 participants