sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.09k stars 129 forks source link

S3 Access Denied error on Next.js app #418

Closed felipemotarocha closed 1 month ago

felipemotarocha commented 1 month ago

I'm getting these errors when accessing my deployed app:

{
  clientName: 'S3Client',
  commandName: 'GetObjectCommand',
  input: {
    Bucket: 'doutor-sim-dev-doutorsimassets-bornuaok',
    Key: '_cache/__fetch/SkKefIaxlUil7N2C5yboG/798268c93d5277a6d976a47d5b32349c99b1f82a52275be21ea9426701d313bd'
  },
  error: AccessDenied: Access Denied
      at Oq (file:///var/task/index.mjs:12:4767)
      at file:///var/task/index.mjs:12:4908
      at K (file:///var/task/index.mjs:44:75449)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async file:///var/task/index.mjs:3:9009
      at async file:///var/task/index.mjs:44:6976
      at async file:///var/task/index.mjs:12:11162
      at async file:///var/task/index.mjs:47:47451
      at async file:///var/task/index.mjs:43:42211
      at async file:///var/task/index.mjs:43:42556 {
    '$fault': 'client',
    '$metadata': {
      httpStatusCode: 403,
      requestId: 'XDAQHE6B9NVHPRS2',
      extendedRequestId: 'kG34AdtJCwyczVCQQWQHIsDqr/Z4WmaCuYs73zni8R0EIQ9wrn1lmWf6Qb6OTSANSvxmnQaNXqQ=',
      cfId: undefined,
      attempts: 1,
      totalRetryDelay: 0
    },
    Code: 'AccessDenied',
    RequestId: 'XDAQHE6B9NVHPRS2',
    HostId: 'kG34AdtJCwyczVCQQWQHIsDqr/Z4WmaCuYs73zni8R0EIQ9wrn1lmWf6Qb6OTSANSvxmnQaNXqQ='
  },
  metadata: {
    httpStatusCode: 403,
    requestId: 'XDAQHE6B9NVHPRS2',
    extendedRequestId: 'kG34AdtJCwyczVCQQWQHIsDqr/Z4WmaCuYs73zni8R0EIQ9wrn1lmWf6Qb6OTSANSvxmnQaNXqQ=',
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  }
}
Failed to get fetch cache AccessDenied: Access Denied
    at Oq (file:///var/task/index.mjs:12:4767)
    at file:///var/task/index.mjs:12:4908
    at K (file:///var/task/index.mjs:44:75449)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///var/task/index.mjs:3:9009
    at async file:///var/task/index.mjs:44:6976
    at async file:///var/task/index.mjs:12:11162
    at async file:///var/task/index.mjs:47:47451
    at async file:///var/task/index.mjs:43:42211
    at async file:///var/task/index.mjs:43:42556 {
  '$fault': 'client',
  '$metadata': {
    httpStatusCode: 403,
    requestId: 'XDAQHE6B9NVHPRS2',
    extendedRequestId: 'kG34AdtJCwyczVCQQWQHIsDqr/Z4WmaCuYs73zni8R0EIQ9wrn1lmWf6Qb6OTSANSvxmnQaNXqQ=',
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  Code: 'AccessDenied',
  RequestId: 'XDAQHE6B9NVHPRS2',
  HostId: 'kG34AdtJCwyczVCQQWQHIsDqr/Z4WmaCuYs73zni8R0EIQ9wrn1lmWf6Qb6OTSANSvxmnQaNXqQ='
}

The app works fine with sst dev next dev, this problem only happens on the deployed version (sst deploy).

My SST config file:

export default $config({
  app(input) {
    return {
      name: 'doutor-sim',
      removal: input?.stage === 'production' ? 'retain' : 'remove',
      home: 'aws',
    }
  },
  async run() {
    const topics = createTopics()

    createSubscribers(topics)

    new sst.aws.Nextjs('DoutorSim', {
      link: [
        topics.admissionFormSendingRequestedTopic,
        topics.admissionJourneyEventCreatedTopic,
        topics.creditAnalysisRequestedTopic,
        topics.creditAnalysisSentTopic,
      ],
    })
  },
})

My package.json:

{
  "name": "doutor-sim",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "build": "next build",
    "dev": "sst dev next dev",
    "lint": "next lint",
    "prepare": "husky && prisma generate",
    "setup": "prisma db push && prisma db seed",
    "start": "next start",
    "test": "jest"
  },
  "dependencies": {
    "@auth/prisma-adapter": "^2.0.0",
    "@aws-sdk/client-sns": "^3.569.0",
    "@hookform/resolvers": "^3.3.4",
    "@prisma/client": "^5.12.1",
    "@radix-ui/react-accordion": "^1.1.2",
    "@radix-ui/react-alert-dialog": "^1.0.5",
    "@radix-ui/react-dialog": "^1.0.5",
    "@radix-ui/react-label": "^2.0.2",
    "@radix-ui/react-popover": "^1.0.7",
    "@radix-ui/react-select": "^2.0.0",
    "@radix-ui/react-separator": "^1.0.3",
    "@radix-ui/react-slot": "^1.0.2",
    "@radix-ui/react-switch": "^1.0.3",
    "@radix-ui/react-toast": "^1.1.5",
    "@radix-ui/react-tooltip": "^1.0.7",
    "@sentry/nextjs": "^7.114.0",
    "@tanstack/react-table": "^8.16.0",
    "aws-cdk-lib": "^2.140.0",
    "aws-lambda": "^1.0.7",
    "axios": "^1.6.8",
    "bcrypt": "^5.1.1",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.0",
    "cmdk": "^0.2.0",
    "dayjs": "^1.11.10",
    "fs-extra": "^11.2.0",
    "gerador-validador-cpf": "^5.0.2",
    "jose": "^5.2.4",
    "jsonwebtoken": "^9.0.2",
    "lodash.debounce": "^4.0.8",
    "lucide-react": "^0.372.0",
    "next": "14.1.4",
    "next-auth": "^4.24.7",
    "next-safe-action": "^6.2.0",
    "next-themes": "^0.3.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-hook-form": "^7.51.3",
    "react-icons": "^5.1.0",
    "react-loader-spinner": "^6.1.6",
    "react-number-format": "^5.3.4",
    "react-slick": "^0.30.2",
    "react-transition-group": "^4.4.5",
    "resend": "^3.2.0",
    "server-only": "^0.0.1",
    "slick-carousel": "^1.8.1",
    "sonner": "^1.4.41",
    "sst": "^3.0.1",
    "twilio": "^5.0.4",
    "zod": "^3.23.0"
  },
  "devDependencies": {
    "@faker-js/faker": "^8.4.1",
    "@svgr/webpack": "^8.1.0",
    "@testing-library/jest-dom": "^6.4.2",
    "@testing-library/react": "^15.0.2",
    "@types/aws-lambda": "^8.10.137",
    "@types/bcrypt": "^5.0.2",
    "@types/jest": "^29.5.12",
    "@types/jsonwebtoken": "^9.0.6",
    "@types/lodash.debounce": "^4.0.9",
    "@types/node": "20.12.7",
    "@types/react": "18.2.79",
    "@types/react-dom": "18.2.25",
    "@types/react-slick": "^0.23.13",
    "@types/react-transition-group": "^4.4.10",
    "autoprefixer": "^10.4.19",
    "chalk": "^4.1.2",
    "eslint": "8.44.0",
    "eslint-config-next": "14.1.4",
    "eslint-plugin-simple-import-sort": "^12.1.0",
    "husky": "^9.0.11",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",
    "lint-staged": "^15.2.2",
    "postcss": "8.4.38",
    "prettier": "^3.2.5",
    "prettier-plugin-tailwindcss": "^0.5.14",
    "prisma": "^5.12.1",
    "tailwind-merge": "^2.3.0",
    "tailwindcss": "3.4.3",
    "tailwindcss-animate": "^1.0.7",
    "ts-node": "^10.9.2",
    "typescript": "5.4.5"
  },
  "prisma": {
    "seed": "ts-node prisma/seed.ts"
  }
}