Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISR Regeneration Lambda fails with "A header you provided implies functionality that is not implemented" #2179

Closed
4 tasks done
quinnturner opened this issue Aug 18, 2021 · 7 comments
Labels
archived This issue has been locked.

Comments

@quinnturner
Copy link

quinnturner commented Aug 18, 2021

Before opening, please confirm:

App Id

d3fdiq126p9gfo

Region

us-east-1

Amplify Console feature

SSR

Describe the bug

Next.js ISR route fails with this error in the regeneration lambda:

{
    "errorType": "NotImplemented",
    "errorMessage": "A header you provided implies functionality that is not implemented",
    "Code": "NotImplemented",
    "Header": "Transfer-Encoding",
    "RequestId": "EM1D6FXAQFQHHYN0",
    "HostId": "QqfYlkbVkXfogMy7LmWqUlrWdt4ci+MPJuHJ98l1dVicFtjJPZuQhcKt1eM7njCjAGtHUPN5EYs=",
    "name": "NotImplemented",
    "$fault": "client",
    "$metadata": {
        "httpStatusCode": 501,
        "extendedRequestId": "QqfYlkbVkXfogMy7LmWqUlrWdt4ci+MPJuHJ98l1dVicFtjJPZuQhcKt1eM7njCjAGtHUPN5EYs=",
        "attempts": 1,
        "totalRetryDelay": 0
    },
    "stack": [
        "NotImplemented: A header you provided implies functionality that is not implemented",
        "    at deserializeAws_restXmlPutObjectCommandError (/var/task/PutObjectCommand-75c64cca.js:2994:41)",
        "    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
    ]
}

I believe it is failing to upload the built file to S3. It might be that the upload is missing the Content-Length header, though I do not know.

Expected behavior

Not to fail the Lambda

Reproduction steps

Here's the getStaticProps (removed some identifying info):

export const getStaticProps: GetStaticProps = async ({ params }) => {
  const queryClient = new QueryClient();
  if (!params) {
    throw new Error("Excepted params");
  }
  const { slug } = params;

  const { promises: fs } = await import("fs");

  if (!metadata) {
    metadata = await fs
      .readFile("./src/assets/metadata/metadata.json", "utf-8")
      .then((t) => JSON.parse(t) as Metadata)
      .catch(() => ({} as Metadata));
  }

  if (!cacheLoaded) {
    cache = await fs
      .readFile(FILE_PATH, "utf-8")
      .then((t) => JSON.parse(t) as Record<string, IRecord>)
      .catch(() => ({} as Record<string, IRecord>));
    cacheLoaded = true;
  }

  const getQuery: () => IMeta | Promise<IMeta | IApiError> = () =>
    cache[slug] ?? getMeta({ slug });

  await queryClient.prefetchQuery<IMeta | Promise<IMeta | IApiError>>(
    ["meta", slug],
    getQuery
  );

  return {
    props: {
      dehydratedState: dehydrate(queryClient),
      seo: {
        description: metadata?.description ?? null,
        title: metadata?.title ?? null,
        keywords: metadata?.keywords ?? null,
      },
    },

    revalidate: 60 * 2, // in seconds
  };
};

Build Settings

version: 1
frontend:
  phases:
    preBuild:
      commands:
        # The scripting library zx requires Node 14.
        - nvm install 14
        - nvm use 14
        - yarn install
    build:
      commands:
        - yarn build
    postBuild:
      commands:
        - cd ./scripts && node ./on-post-amplify-build.mjs
  artifacts:
    baseDirectory: .next
    files:
      - "**/*"
  cache:
    paths:
      - node_modules/**/*
      - .next/cache/**/*

Additional information

Lambda ID: xrpzjukr-uurw6df

@Athena96
Copy link
Contributor

Hi @quinnturner can you try my suggestion here, I think it might be related to the issue you are facing. Thanks!

@quinnturner
Copy link
Author

Thanks, @Athena96. Setting target: "serverless" on Next.js 11.1.0 did not work. Unfortunately, I would strongly prefer to not downgrade to Next.js 10.x due to performance issues during local development. Could this be as simple as adding the Content-Length header in the S3 request on Amplify's side?

@Athena96
Copy link
Contributor

Hi @quinnturner, it looks like its a separate issue, but we have a fix for this that will allow you to us Next.js 11, as a workaround you can downgrade to Next.js 10.2.3 and we'll follow up here when this is rolled out.

@quinnturner
Copy link
Author

Woohoo! Thank you @Athena96

@Athena96
Copy link
Contributor

Hi @quinnturner this should be resolved now. Can you try with the latest version of next: next: 11.1.2 and the latest version of Amplify SSR (in the Build Settings, set the Next.js Version to latest: https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html#update-app-nextjs-version)

@quinnturner
Copy link
Author

This issue is resolved. I am experiencing a different ISR issue related to inconsistency between branches/apps but I will open up a new issue for that. Thanks!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot added the archived This issue has been locked. label Oct 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived This issue has been locked.
Projects
None yet
Development

No branches or pull requests

2 participants