Serverless-next.js: Deployment fails with --aws-s3-accelerate

Created on 13 Oct 2019  ·  23Comments  ·  Source: serverless-nextjs/serverless-next.js

Describe the bug
Deployment of the serverless-next.js component fails when using --aws-s3-accelerate.

To Reproduce
We can see this behaviour on a failing github action:
https://github.com/Meemaw/next-aws-lambda/runs/258201271

Expected behavior
Deployment should work

Most helpful comment

Hi folks. Sorry I've not been able to look into this before.

After reading the AWS Documentation for S3 bucket acceleration I think it would be worth trying to check whether the bucket has acceleration enabled before uploading. I suspect putBucketAccelerateConfiguration may be eventually consistent, therefore causing a race condition when we try uploading straight after creating the bucket.
I am in the process of creating a new package for handling static assets uploads to S3 that removes the dependency to the aws-s3 component. Once that's ready I'll make sure this issue is fixed.

All 23 comments

@Meemaw did you manage to solve this? I found a build in your project that seems to have gone well: https://github.com/Meemaw/next-aws-lambda/runs/286431375

I am experiencing the same issue when trying to deploy from within a AWS CodeBuild container.

@Meemaw did you manage to solve this? I found a build in your project that seems to have gone well: https://github.com/Meemaw/next-aws-lambda/runs/286431375

I am experiencing the same issue when trying to deploy from within a AWS CodeBuild container.

I ran into the same issue and I have the solution post on here: https://medium.com/@jimmdd/next-js9-serverless-component-set-up-for-aws-codebuild-and-cloudfront-deployment-ca6452568a01
Just checkout the IAm permission you have to add, make sure you have all I list in the post.

For me, the solution was just to use --no-aws-s3-accelerate param when calling serverless

I'm having almost the same issue, but in my case like 50% of builds are working correctly and the another half fails. It just randomly crashes when uploading public directory to S3.

89   DEBUG ─ Checking if bucket asdf exists.
90   DEBUG ─ Bucket qwerty-asdf does not exist. Creating...
91   DEBUG ─ Bucket qwerty-asdf created. Confirming it's ready...
92   DEBUG ─ Bucket qwerty-asdf creation confirmed.
93   DEBUG ─ Setting acceleration to "true" for bucket qwerty-asdf.
94   DEBUG ─ Bucket qwerty-asdf was successfully deployed to the us-east-1 region.
95   DEBUG ─ Starting upload to bucket qwerty-asdf in region us-east-1
96   DEBUG ─ Uploading directory /builds/asdf/.next/static to bucket qwerty-asdf
97   DEBUG ─ Starting upload to bucket qwerty-asdf in region us-east-1
98   DEBUG ─ Uploading directory /builds/asdf/public to bucket qwerty-asdf
99   error:
100   InvalidRequest: S3 Transfer Acceleration is not configured on this bucket
101     at Request.extractError (/root/.serverless/components/registry/npm/[email protected]/node_modules/aws-sdk/lib/services/s3.js:816:35)

Sometimes the deployment works like a charm:

89   DEBUG ─ Bucket trololol does not exist. Creating...
90   DEBUG ─ Bucket trololol created. Confirming it's ready...
91   DEBUG ─ Bucket trololol creation confirmed.
92   DEBUG ─ Setting acceleration to "true" for bucket trololol.
93   DEBUG ─ Bucket trololol was successfully deployed to the us-east-1 region.
94   DEBUG ─ Starting upload to bucket trololol in region us-east-1
95   DEBUG ─ Uploading directory /builds/asdf/.next/static to bucket trololol
98   DEBUG ─ Starting upload to bucket trololol in region us-east-1
97   DEBUG ─ Uploading directory /builds/asdf/public to bucket trololol
98   DEBUG ─ Starting deployment of lambda trololol-lambda to the us-east-1 region.
99   DEBUG ─ Syncing role trololol-role in region us-east-1.

I don't know what would be the issue here, maybe some async issue, acceleration is done asynchronous and some server somewhere is still out of date when trying to upload files to bucket? "Funny" thing is that serverless --no-aws-s3-accelerate doesn't seem to help, I'm getting same random crashes.

I ran also into this when trying to deploy with AWS Amplify. Next run was success with "npx serverless --no-aws-s3-accelerate". Next run after that failed to the same error so seems like @omjokine is correct.

EDIT: Actually next build created another fresh environment so is this related to first build to new environment?

This is really flaky for me too, I even have the serverless --no-aws-s3-accelerate in there.

I'm getting this issue on overhalf my deploys - it appears to be a race condition as you can repeatedly run the deployment until it works.

Current workaround is to use a precreated bucket already configured with acceleration and use the bucketName option.

The issue is much more apparent when I switched to using serverless from within a Github Action workflow.

Same issue here 🤚 @danielcondemarin do you know a workaround? 🙏

Hi folks. Sorry I've not been able to look into this before.

After reading the AWS Documentation for S3 bucket acceleration I think it would be worth trying to check whether the bucket has acceleration enabled before uploading. I suspect putBucketAccelerateConfiguration may be eventually consistent, therefore causing a race condition when we try uploading straight after creating the bucket.
I am in the process of creating a new package for handling static assets uploads to S3 that removes the dependency to the aws-s3 component. Once that's ready I'll make sure this issue is fixed.

We found that setting a bucket name and AccelerateConfiguration in the serverless.yml file solved the problem, like this:

site:
  component: serverless-next.js
  inputs:
        bucketName: my-bucket-name
        AccelerateConfiguration:
          AccelerationStatus: Enabled

We haven't had a single deployment issue since!

@james-calmus-dt That input doesn't exist in the next.js component. Where did you find it?

@danielcondemarin we found a reference to AccelerateConfiguration in this example, and thought we'd try the options listed in our own as above

Also what do you mean the input doesn't exist in the next.js component @danielcondemarin?

@james-calmus-dt Your example uses plain cloud formation. That doesn't work in the next.js component inputs, so passing AccelerateConfiguration: ... will have no effect.

Hi folks 👋 I have just released [email protected] that uses this package for uploading static assets to S3 instead of the aws-s3 component.

I've added this check to ensure bucket acceleration is enabled before trying to use it. Hopefully it will solve this issue.

Volunteers to test this release and feedback would be much appreciated 🙏

Hi @danielcondemarin just tried the new package and have come up against the same S3 Transfer Acceleration is not configured on this bucket error. I removed the bucket name from inputs to test it because having a consistent bucket name seems to fix the issue for us. Let me know if you need any more info.

@james-calmus-dt Could you share your serverless.yml?

@danielcondemarin Kudos for the quick turnaround time after you said you were going to work on this issue. I've also tried the alpha release and the newly released non-alpha 1.11.1 and I'm still experiencing the same S3 Transfer Acceleration error as before.

I can see that the bucket is created correctly - but is a race condition as before, if I re-run the workflow again it will successfully deploy as the bucket is ready.

With Debug enabled, I'm able to see the new steps taking place - and seem to be successful but still results in a failure. Sorry for the omissions, my org is a tight on data leakage; I'm happy to help with more info where I can.

DEBUG ─ Deploying bucket <omitted> in region us-east-1.
DEBUG ─ Checking if bucket <omitted> exists.
DEBUG ─ Bucket <omitted> does not exist. Creating...
DEBUG ─ Bucket <omitted> created. Confirming it's ready...
DEBUG ─ Bucket <omitted> creation confirmed.
DEBUG ─ Setting acceleration to "true" for bucket <omitted>.
DEBUG ─ Bucket <omitted> was successfully deployed to the us-east-1 region.

Serverless.yml

app:
  component: serverless-next.js
  inputs:
    domain: 
      - ${env.SERVERLESS_SUBDOMAIN}
      - ${env.SERVERLESS_DOMAIN}
    bucketName: ${env.SERVERLESS_BUCKET_NAME}

Error Output

error:
  InvalidRequest: S3 Transfer Acceleration is not configured on this bucket

@codeurge Could you try pinning the version to @1.11.1?

You need to:

app:
  component: [email protected]

Just to be sure an older version is not cached or something.

@danielcondemarin Good suggestion, unfortunately still the same error -- and tried this time with a randomly generated bucket name instead.

@james-calmus-dt Could you share your serverless.yml?

Serverless.yml

site:
  component: [email protected]

At the moment it seems to be deploying correctly but I'll monitor it and let you know if we experience any other problems.

Just implemented a CI/CD pipeline (was experimenting with this component from my machine until now). Removed all my previous infrastructure and wanted to deploy it all during CI/CD with syncing a brand new .serverless folder that was kicked off from CI/CD.

Failed on first build using [email protected] with S3 Transfer Acceleration is not configured on this bucket.

All builds after the first work fine so far.

Wanted to add that this is still an issue as of 1.15.1 for fresh deploys.

Like the others above the subsequent deploys fixes the issue.

Error message if it helps:

error:
--
950 | { InvalidRequest: S3 Transfer Acceleration is not configured on this bucket
951 | at Request.extractError (/root/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/services/s3.js:837:35)
Was this page helpful?
0 / 5 - 0 ratings