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