- Newest
- Most votes
- Most comments
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
-
Your bundler may be rewriting
process.env. This is the most likely cause with a customserver.js. esbuild'sdefine, webpack'sDefinePlugin/EnvironmentPlugin, and Vite/Rollup replace plugins can turnprocess.env.Xinto a build-time constant, which isundefinedin the build container. The SDK'sfromEnvreads the same variables, so it gets nothing and you seeCredentialsProviderError. 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_NAMEandAWS_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.
- If you see
-
Child processes. If
server.jsspawns or forks a worker with a filteredenv, the credentials don't reach it. -
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.
-
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.
-
Manifest shape. Confirm the file is
.amplify-hosting/deploy-manifest.jsonwith"version": 1, and thatserver.jssits 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.envkey 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:
- Adding an SSR Compute role to allow access to AWS resources – AWS Amplify Hosting
- IAM Compute Roles for Server-Side Rendering with AWS Amplify Hosting (AWS blog)
- re:Post: Amplify Hosting (SSR) cannot access Aurora DSQL – IAM role credentials not passed to Lambda environment
- re:Post: Amplify CredentialsProviderError with S3 storage and Next.js SSR
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'
Relevant content
asked 5 years ago
