最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon web services - Next.js assetPrefix is breaking with ECS + S3 + cloudfront - Stack Overflow

programmeradmin5浏览0评论

I am trying to deploy next.js application on ECS. this is my next.config.js

const nextConfig = {
  generateBuildId : async () => {
    return process.env.NEXT_BUILD_ID || "default-build-id";
  },
  assetPrefix: '',
  output: "standalone",
  images: {
    domains: [],
  },
  reactStrictMode: true,
};
  
module.exports = nextConfig;

next.js version is 13.4.13 and using page router

I am using github actions to build and deploy the docker image to ECS

I am extracting .next/static from built docker image in github workflow

      - name: Extract .next/static from Docker image
        run: |
          CONTAINER_ID=$(docker create ${{ env.ECR_REPOSITORY_NAME }}:${{ env.IMAGE_TAG }})
          docker cp $CONTAINER_ID:/app/.next/static ./next-static/
          docker rm $CONTAINER_ID

then updating the s3 bucket under the folder _next/static/ - before deploying to ECS step

  - name: Upload and Tag Files in S3 - next/static
        run: |
          echo "Syncing new static assets to S3..."
              aws s3 cp --recursive ./next-static/ s3://${{ env.ASSETS_BUCKET_NAME }}/_next/static/ \
          --cache-control "public, max-age=172800, immutable"

Now issue is after copying files , if i navigate to any page - it breaks saying page not found but on refresh everything works.

Tried invalidating cloudfront cache as a last step in workflow still not resolved.

Any help or suggestions are highly valuable to me. thank you

发布评论

评论列表(0)

  1. 暂无评论