I’m trying the <https://serverless-stack.com/examp...
# sst
b
I’m trying the ‘create a nextjs app’ example. I’m on Mac, using AWS SSO with no default profile. I can successfully run:
AWS_PROFILE=uat npx sst start
I then go into the
frontend
directory to try and run the nextjs front end using
npm run dev
(which is mapped as follows in package.json
"dev": "sst-env -- next dev"
) Which works fine, but when I load the page in a browser and click on the button wired up to an nextjs api function that calls DynamoDB via the AWS SDK I get this error after ~20 seconds:
“CredentialsError”,“message”:“Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1”
Any ideas on what I can try? I’m not clear how the AWS SDK in the API function gets it’s AWS credentials information.
m
Can I see how you're initializing aws in frontend?
Do you have
.env
file in your project? @Benjamin Mitchell
b
Hi @manitej I’m using this from the example to create a new DynamoDB client in the API function (from the example here)
Copy code
import AWS from "aws-sdk";

const dynamoDb = new AWS.DynamoDB.DocumentClient({
  region: process.env.REGION,
});
And I don’t have a
.env
in that frontend folder or in that api folder.
m
Got it. I think you haven't installed aws cli locally. Follow this guide https://serverless-stack.com/chapters/configure-the-aws-cli.html
b
I have the awscli locally:
aws --version
aws-cli/2.4.16 Python/3.9.10 Darwin/21.1.0 source/arm64 prompt/off
I don’t have a default profile set because I’m using AWS SSO and have many accounts / profiles.
m
Run these with your details
Copy code
$ export AWS_ACCESS_KEY_ID="your_key_id"
$ export AWS_SECRET_ACCESS_KEY="your_secret_key"
Aws sdk need account credentials in order to query on the user behalf. If you don't want to set default account locally, You can pass
credentials
object during initialization
b
Thanks @manitej, I really appreciate your help. I went over the sample again and it’s now working.
m
happy to help @Benjamin Mitchell 🙂
t
@Benjamin Mitchell what version of sst were you using
b
SST: 0.63.0
but I think it may have been user-error on my side that caused my initial problem; when I copied the files over again I was able to get the frontend to connect to the API and the DynamoDB without issue.