Hello all, I'm deploying my Next.js app via SST, a...
# help
w
Hello all, I'm deploying my Next.js app via SST, and I'm proxying all requests to the API through Next.js server
/api/graphql
in
pages/api/graphql.js
I have Cognito auth middleware When I do
sst start
it works fine but when I do
sst deploy
I got
503
error Any idea why I'm getting this please
f
Hey @Wael Zoaiter, it’s likely that the Lambda function doesn’t have permission to Cognito.
Can I see how you are creating the
NextjsSite
?
w
I tried to give it all permissions and I still got the same error
Sure
Copy code
.
.    
const elvira = new sst.NextjsSite(this, 'Elvira', {
      path: 'ui/elvira',
      customDomain: {
        domainName: `elvira-sst-${scope.stage}.${host}`,
        hostedZone: host,
      },
      defaultFunctionProps: {
        timeout: 30,
      },
      environment: {
        NEXT_PUBLIC_API_URL: api.cordovaUrl,
        NEXT_PUBLIC_AWS_COGNITO_USER_POOL_ID: api.userPoolId,
        NEXT_PUBLIC_AWS_COGNITO_CLIENT_ID: api.elviraUserPoolClientId,
        NEXT_PUBLIC_AWS_COGNITO_ADMIN_USER_NAME: process.env.AWS_COGNITO_ADMIN_USER_NAME,
        NEXT_PUBLIC_AWS_COGNITO_ADMIN_PASSWORD: process.env.AWS_COGNITO_ADMIN_PASSWORD,
        NEXT_PUBLIC_VEHICLES_API: process.env.VEHICLES_API,
        NEXT_PUBLIC_ROBOTS_TXT: process.env.ROBOTS_TXT,
        NEXT_PUBLIC_CONFIGCAT_TOKEN: process.env.CONFIGCAT_TOKEN,
        NEXT_PUBLIC_GOOGLE_RECAPTCHA_KEY: process.env.GOOGLE_RECAPTCHA_KEY,
        NEXT_PUBLIC_STRIPE_TOKEN: process.env.STRIPE,
        NEXT_PUBLIC_ELVIRA_GOOGLE_TRACKING_ID: process.env.ELVIRA_GOOGLE_TRACKING_ID,
        NEXT_PUBLIC_PUBLIC_GOOGLE_TRACKING_ID: process.env.PUBLIC_GOOGLE_TRACKING_ID,
        NEXT_PUBLIC_GOOGLE_MAPS_API_KEY: process.env.GOOGLE_MAPS_API_KEY,
        NEXT_PUBLIC_ENVIRONMENT: process.env.ENVIRONMENT,
        NEXT_PUBLIC_GOOGLE_ANALYTICS: process.env.GOOGLE_ANALYTICS,
        NEXT_PUBLIC_ALEXA_KEY: process.env.ALEXA_KEY,
        NEXT_PUBLIC_PAYPAL_CLIENT_ID: process.env.PAYPAL_CLIENT_ID,
      },
    });

    elvira.attachPermissions(sst.PermissionType.ALL);
.
.
f
That looks right! Let’s try this: 1. go into ur Lambda console; 2. look for a Lambda function that starts with 
ApiFunction
 in its name; 3. open up the 
Configuration
 tab 4. select
Permissions
on the left panel 5. click on Role name link on the right, it will take you to the IAM console 6. expand on the policy, like in the screenshot. And if you could copy and paste the permissions here
w
Copy code
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "s3:GetObject*",
        "s3:GetBucket*",
        "s3:List*",
        "s3:DeleteObject*",
        "s3:PutObject*",
        "s3:Abort*"
      ],
      "Resource": [
        "arn:aws:s3:::dev-cordova-web-elvirabucketdce49cc2-1rbnluolf0tv6",
        "arn:aws:s3:::dev-cordova-web-elvirabucketdce49cc2-1rbnluolf0tv6/*"
      ],
      "Effect": "Allow"
    },
    {
      "Action": [
        "sqs:SendMessage",
        "sqs:GetQueueAttributes",
        "sqs:GetQueueUrl"
      ],
      "Resource": "arn:aws:sqs:us-east-1:763610264561:dev-cordova-web-elvirabucketdce49cc2-1rbnluolf0tv6.fifo",
      "Effect": "Allow"
    },
    {
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:us-east-1:763610264561:function:dev-cordova-Web-ElviraRegenerationFunction091C74EC-4HNy9O0ab4z2",
      "Effect": "Allow"
    },
    {
      "Action": "*",
      "Resource": "*",
      "Effect": "Allow"
    }
  ]
}
f
That looks right as well. What’s the name of your Lambda function?
w
Copy code
dev-cordova-Web-ElviraApiFunctionE01E71E9-MC0BUVyFdPuh
f
Alright, let’s take a quick look at the log for this function. Try this: 1. go to CloudWatch console > select Log Groups on the left 2. because this is a Lambda@Edge function, you need to switch to the AWS region you made the request from, ie.
eu-west-1
. 3. search for function name
dev-cordova-Web-ElviraApiFunctionE01E71E9-MC0BUVyFdPuh
, you should see a log group called
/aws/lambda/us-east-1.dev-cordova-Web-ElviraApiFunctionE01E71E9-MC0BUVyFdPuh
4. go into the log group, and select the first log stream Do you see an error in there?
w
Yes
Looks like it's the cognito auth middleware, it's throwing
"UserNotFoundException: User does not exist."
So this is what causing the
503
right ?
f
Yup
Better error message will definitely help here.
w
Got it Thanks a lot @Frank I appreciate your help 🙏
f
All good @Wael Zoaiter. Just opened an issue for making it easier to debug such issues https://github.com/serverless-stack/serverless-stack/issues/851