Skip to content

Amplify Hosting SSR compute role: no credentials in a custom deployment-spec (v1) server

0

We host an SSR app on Amplify Hosting (WEB_COMPUTE, us-east-1) using a custom deployment-spec v1 artifact rather than a framework adapter: .amplify-hosting/compute/default/server.js, with computeResources [{"name":"default","entrypoint":"server.js","runtime":"nodejs20.x"}].

We attached an IAM SSR compute role (trust policy: amplify.amazonaws.com, sts:AssumeRole, as in the docs). At startup, the server uses the AWS SDK for JavaScript v3 default credential chain to read SSM Parameter Store SecureStrings.

What we tried (each release succeeded at BUILD/DEPLOY/VERIFY):

  1. Role attached at branch level, runtime nodejs20.x
  2. Role attached at branch level, runtime nodejs22.x
  3. Role set as the app default role (branch override cleared), runtime nodejs22.x

In every case, CloudTrail shows Amplify assuming the role. But inside the running SSR function, the SDK throws CredentialsProviderError before making any SSM call, and none of these are set: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_CONTAINER_CREDENTIALS_FULL_URI, AWS_CONTAINER_CREDENTIALS_RELATIVE_URI, AWS_CONTAINER_AUTHORIZATION_TOKEN, AWS_WEB_IDENTITY_TOKEN_FILE, AWS_ROLE_ARN.

The compute-role docs say the credentials are "immediately available in the runtime of your SSR function", but the examples are all Next.js.

Questions:

  • Does the SSR compute role deliver credentials to custom deployment-spec (v1) apps, or only to framework-adapter deployments such as Next.js?
  • If it does, how should server code obtain them? Is there a different provider or endpoint than the SDK's default chain?
  • If it doesn't, what is the supported way for a deployment-spec SSR server to get runtime AWS access without a long-lived key in the artifact?
2 Answers
0

The public docs don't clearly answer your first question. The compute-role page only says credentials are "immediately available in the runtime of your SSR function". It doesn't mention deployment-spec apps, which frameworks are supported, or how the credentials are delivered. The AWS launch blog post only shows Next.js.

There is indirect evidence that it does work with deployment-spec apps. Nuxt deploys to Amplify through Nitro's aws-amplify preset, which writes a deployment-spec artifact (.amplify-hosting/deploy-manifest.json plus compute/default/) rather than using a Next.js adapter. In a re:Post thread, a Nuxt user had exactly your symptom (no container credentials, SDK couldn't find credentials). It went away once they used a compute role instead of a service role. So the mechanism isn't limited to Next.js, and something specific to your setup is the more likely cause. I haven't found an official statement that confirms this.

What to check first

  1. Your bundler may be rewriting process.env. This is the most likely cause with a custom server.js. esbuild's define, webpack's DefinePlugin/EnvironmentPlugin, and Vite/Rollup replace plugins can turn process.env.X into a build-time constant, which is undefined in the build container. The SDK's fromEnv reads the same variables, so it gets nothing and you see CredentialsProviderError. To test, log something the bundler can't rewrite, at startup and inside a request handler:

    const env = globalThis["process"]["env"];
    console.log(Object.keys(env).filter(k => k.startsWith("AWS_")).sort());
    • If you see AWS_REGION, AWS_LAMBDA_FUNCTION_NAME and AWS_EXECUTION_ENV, you're reading the real Lambda environment.
    • If the Lambda variables show up but your earlier check found no credentials, the bundler was hiding them from your check.
    • If even the Lambda variables are missing, the code isn't reading the runtime environment at all, which again points at the bundler or a subprocess.
  2. Child processes. If server.js spawns or forks a worker with a filtered env, the credentials don't reach it.

  3. Code running at build time. Make sure the SSM read isn't also happening during build or prerender. There, the service role applies, not the compute role, and a failure in build logs is easy to mistake for a runtime failure.

  4. Deploy after the role change. Your three attempts each did a fresh release, so you've probably covered this. The role applies to deployments made after it's attached, and a redeploy of an old artifact may not pick it up.

  5. Manifest shape. Confirm the file is .amplify-hosting/deploy-manifest.json with "version": 1, and that server.js sits at .amplify-hosting/compute/default/server.js.

How server code should get credentials

I'm not aware of any Amplify-specific provider or endpoint. The documented pattern is new S3Client({}) with the default chain, so your approach is the intended one. On Lambda, credentials normally arrive as the standard AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_SESSION_TOKEN variables, which fromEnv reads. Amplify doesn't document its delivery method, so treat that as the usual Lambda behavior rather than a guarantee.

Also create the SSM client lazily, or inside a function. Avoid reading the variables into constants at the top level of a bundled module, since the bundler may rewrite them there.

If the check shows the variables really are absent

  • Open an AWS Support case. Include the app ID, branch, the manifest, and the process.env key dump. That output would be a clear platform bug report.
  • A stopgap with no long-lived keys: keep secrets out of the SSR function and have it call an API Gateway + Lambda (or a Lambda function URL with IAM or auth-token checks). That function runs with its own execution role and reads SSM.
  • Build-time injection: Amplify can expose SSM parameters as secrets during the build, and you'd write them into the artifact. It needs no long-lived AWS keys, but the secret values end up inside the deployed artifact. You wanted to avoid that, so treat it as a last resort.

If you share the AWS_* key list from the check, I can help narrow down which case you're in.

Sources:

EXPERT

answered 2 months ago

0

Hello.

In every case, CloudTrail shows Amplify assuming the role. But inside the running SSR function

Does this mean that no errors occurred in the CloudTrail logs?
The IAM role must trust the amplify.amazonaws.com service to allow sts:AssumeRole.
If an error occurs with AssumeRole, you need to review the IAM role configuration.

There are no specific steps, such as a restart, required to apply role updates to the application; therefore, if the compute role has been successfully configured in the Amplify console, you should be able to use the IAM role.

Please use the following commands to verify whether computing roles are configured at both the app level and the branch level.
https://docs.aws.amazon.com/cli/latest/reference/amplify/get-app.html
https://docs.aws.amazon.com/cli/latest/reference/amplify/get-branch.html

aws amplify get-app \
  --app-id <APP_ID> \
  --region us-east-1 \
  --query 'app.computeRoleArn'

aws amplify get-branch \
  --app-id <APP_ID> \
  --branch-name <BRANCH_NAME> \
  --region us-east-1 \
  --query 'branch.computeRoleArn'
EXPERT

answered 2 months ago

EXPERT

reviewed 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.