serverless-nextjs / serverless-next.js

⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
MIT License
4.46k stars 457 forks source link

1.20.0-alpha4 Version has S3 bucket region bug when bucket region is specfied in config file. #1111

Closed yk-matsu closed 3 years ago

yk-matsu commented 3 years ago

Describe the bug

When I specify bucket region. InvaliadParameterValueException error is occured. like below.

next-serverless:
  component: "@sls-next/serverless-component@1.20.0-alpha.4"
  inputs:
    roleArn: "{custom role}"
    bucketRegion: 'ap-northeast-1'

Actual behavior

Actual behavior is written in Screenshots/Code/Logs section.

Expected behavior

ap-northeast-1 region's S3 bucket is created and ISR works.

Steps to reproduce

Screenshots/Code/Logs

  error:
  InvalidParameterValueException: Function does not exist
    at Object.extractError (/Users/{username}/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.4/node_modules/aws-sdk/lib/protocol/json.js:52:27)
    at Request.extractError (/Users/{username}/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.4/node_modules/aws-sdk/lib/protocol/rest_json.js:55:8)
    at Request.callListeners (/Users/{username}/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.4/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/Users/{username}/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.4/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/Users/{username}/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.4/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/Users/{username}/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.4/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/{username}/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.4/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/{username}/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.4/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Users/{username}/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.4/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Users/{username}/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.4/node_modules/aws-sdk/lib/request.js:690:12) {
  code: 'InvalidParameterValueException',
  time: 2021-05-23T13:24:46.183Z,
  requestId: '18399683-0ad5-467a-9ffb-1fa6b666ddfb',
  statusCode: 400,
  retryable: false,
  retryDelay: 83.94330763177335
}

  140s › next-serverless › InvalidParameterValueException: Function does not exist

Versions

next-serverless:
  component: "@sls-next/serverless-component@1.20.0-alpha.4"
  inputs:
    roleArn: "{custom role}"
    bucketRegion: 'ap-northeast-1'
{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "@aws-amplify/ui-react": "^1.1.0",
    "aws-amplify": "^3.4.0",
    "aws-appsync": "^4.0.3",
    "aws-sdk": "^2.907.0",
    "better-sqlite3": "^7.4.0",
    "graphql-tag": "^2.12.4",
    "hdb-pool": "^0.1.6",
    "ioredis": "^4.27.2",
    "mongodb": "^3.6.6",
    "mongodb-client-encryption": "^1.2.3",
    "mysql": "^2.18.1",
    "mysql2": "^2.2.5",
    "next": "10.2.0",
    "next-auth": "^3.23.0",
    "next-auth-dynamodb": "^0.3.3",
    "oracledb": "^5.1.0",
    "pg": "^8.6.0",
    "pg-native": "^3.0.0",
    "pg-query-stream": "^4.1.0",
    "pino-pretty": "^4.8.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "sqlite3": "^5.0.2",
    "typeorm-aurora-data-api-driver": "^2.1.0"
  },
  "devDependencies": {
    "@types/node": "^15.0.2",
    "@types/react": "^17.0.5",
    "typescript": "^4.2.4"
  }
}

Additional context

Bucket region is not specfied in serverless.yml. us-east-1 S3 bucket is created, and ISR works.

like below.

# serverless.yml
next-serverless:
  component: "@sls-next/serverless-component@1.20.0-alpha.4"
  inputs:
    roleArn: "{custom-role}"

Checklist

dphang commented 3 years ago

The stacktrace above doesn't show it but I assume it is probably this line that fails, since you mention ISR: https://github.com/serverless-nextjs/serverless-next.js/blob/e7031355d4bf6dcac5bef6009456fbaae1f3b98c/packages/serverless-components/nextjs-component/src/component.ts#L555

Wondering if there is some delay in Lambda creation in ap-northeast-1. Do you see the function created at all? Maybe worth investigating if there is a more reliable way to wait for Lambda to be created. I thought https://github.com/serverless-nextjs/serverless-next.js/blob/e7031355d4bf6dcac5bef6009456fbaae1f3b98c/packages/serverless-components/nextjs-component/src/component.ts#L550 would do so since it is awaiting for the Lambda, but maybe it is less reliable on AP regions.

cc @kirkness

ckjoris commented 3 years ago

i'm seeing same error with 1.20.0-alpha.16, in eu-central-1 region.

  DEBUG ─ Deploying bucket j1p5vt-s6j2zta in region eu-central-1.
  DEBUG ─ Checking if bucket j1p5vt-s6j2zta exists.
  DEBUG ─ Setting acceleration to "true" for bucket j1p5vt-s6j2zta.
  DEBUG ─ Bucket j1p5vt-s6j2zta was successfully deployed to the eu-central-1 region.
  DEBUG ─ Starting deployment of lambda j1p5vt-s6j2zta to the eu-central-1 region.
  DEBUG ─ Syncing role j1p5vt-9rrmai8 in region us-east-1.
  DEBUG ─ Updating service for role j1p5vt-9rrmai8.
  DEBUG ─ Updating policy for role j1p5vt-9rrmai8.
  DEBUG ─ Saved state for role j1p5vt-9rrmai8.
  DEBUG ─ Role j1p5vt-9rrmai8 was successfully deployed to region us-east-1.
  DEBUG ─ Deployed role arn is arn:aws:iam::066589566831:role/j1p5vt-9rrmai8.
  DEBUG ─ Packaging lambda code from /home/circleci/repo/.serverless_nextjs/regeneration-lambda.
  DEBUG ─ Uploading j1p5vt-s6j2zta lambda code.
  DEBUG ─ Updating j1p5vt-s6j2zta lambda config.
  DEBUG ─ Successfully deployed lambda j1p5vt-s6j2zta in the eu-central-1 region.

  error:
  InvalidParameterValueException: Function does not exist
    at Object.extractError (/home/circleci/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.16/node_modules/aws-sdk/lib/protocol/json.js:52:27)
    at Request.extractError (/home/circleci/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.16/node_modules/aws-sdk/lib/protocol/rest_json.js:55:8)
    at Request.callListeners (/home/circleci/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.16/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/home/circleci/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.16/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/circleci/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.16/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/home/circleci/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.16/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/circleci/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.16/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/circleci/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.16/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/circleci/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.16/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/circleci/.serverless/components/registry/npm/@sls-next/serverless-component@1.20.0-alpha.16/node_modules/aws-sdk/lib/request.js:690:12) {
  code: 'InvalidParameterValueException',
  time: 2021-06-02T19:13:52.100Z,
  requestId: '788d7483-bd3a-462f-bc52-4c498403a531',
  statusCode: 400,
ckjoris commented 3 years ago

added some logging before await sqs.addEventSource(regenerationLambdaResult.name); in serverless-next.js/packages/serverless-components/nextjs-component/src/component.ts but it doesn't seem to go there, no logs printed.

But deployment succeeded after changing https://github.com/serverless-nextjs/serverless-next.js/blob/e7031355d4bf6dcac5bef6009456fbaae1f3b98c/packages/serverless-components/aws-sqs/serverless.js#L19 region to 'eu-central-1'.

mikejcooper commented 3 years ago

added some logging before await sqs.addEventSource(regenerationLambdaResult.name); in serverless-next.js/packages/serverless-components/nextjs-component/src/component.ts but it doesn't seem to go there, no logs printed.

But deployment succeeded after changing

https://github.com/serverless-nextjs/serverless-next.js/blob/e7031355d4bf6dcac5bef6009456fbaae1f3b98c/packages/serverless-components/aws-sqs/serverless.js#L19

region to 'eu-central-1'.

Changing this also worked +1

dphang commented 3 years ago

Thanks, makes sense since Lambda for regeneration is using bucket region specified but SQS queue does not use same region, and it is using us-east-1 by default. So it cannot find the function since it's in the wrong region. Will fix it by using bucketRegion for SQS's region.