Damiano Dotto
Damiano Dotto

Reputation: 89

NextJS SSR AWS Amplify - Production env is slow on load

My Nextjs SSR App on AWS Amplify is too slow:

The same app on local pc started with commands yarn build && yarn start it is fast enough but on aws:

The getServerSideProps() doesn't call 999 API but just retrieve user data from cognito :

export async function getServerSideProps(context) {
  let req = context.req;
  const { Auth } = withSSRContext({ req });
  try {
    let user = await Auth.currentAuthenticatedUser();
    return {
      props: {
        param1: context.params.param1,
        param2: context.params.param2,
        user: user,
        ...(await serverSideTranslations(context.locale, ["common", "dashboard", "footer","fs"])),
      },
    };
  } catch (err) {
    return {
      redirect: {
        permanent: false,
        destination: "/auth/signin",
      },
      props: {},
    };
  }
}

After the first time click page, the same page (with other params) it's faster (~2.1 sec)... I tried to enable "amplify performance mode" that it should lengthen the time of caching but no real improvement. How can I fixed that?

Upvotes: 6

Views: 860

Answers (1)

Damiano Dotto
Damiano Dotto

Reputation: 89

[UPDATE] Today I realized that entering amplify, an update was proposed to me for "improvements and performance using nextjs 12".

I did that and it actually got much faster... It messed up my backend environment though...

AWS Amplify Performance Boost with NextJS 12 - Unexpected Backend Environment Switch

Upvotes: 1

Related Questions