A service on EC2 can keep failing after the correct IAM role has been attached. The missing step is often identifying which credentials the process actually uses. An SDK can select environment variables or another configured provider before it reaches the instance role. Your interactive shell can therefore succeed while the service fails, or the reverse.
Identify the process, not just the machine
Record the application’s operating-system user, service definition and deployment mechanism. Check whether credentials are supplied through environment configuration, a mounted profile or a deployment wrapper. Inspect configuration names and identity results without dumping complete environments, token files or credential responses into logs.
An STS caller-identity check executed through the application’s credential path can establish the selected principal. Running it under your own CLI profile is a separate test. Compare the resulting account and role with the intended workload identity before making an IAM change.
Understand the role attachment
EC2 uses an instance profile to expose an IAM role to applications. The console often handles the profile details for you, which can make the distinction easy to miss. Confirm that the profile attached to the instance contains the intended role and that its policies authorize the specific application operation.
EC2 also has an instance identity role used by supported AWS integrations. It is not a substitute for the application role that you configure for your own service. Similar names in documentation do not imply identical permission models.
Replace static configuration with a managed credential path
Use a supported SDK and its standard provider chain to obtain temporary role credentials where practical. If you remove stale environment credentials, do so through the service’s normal configuration mechanism and restart or redeploy as required. Simply unsetting variables in your login shell may leave the running service unchanged.
Do not copy instance metadata credentials into application settings. They expire, and copying them defeats the refresh behavior provided by the SDK. Protect the metadata path according to the workload’s requirements and verify the instance metadata configuration rather than weakening it blindly.
Complete the change by testing the actual service operation and a later request after credentials have had an opportunity to refresh. Confirm that secrets were not written to application logs during troubleshooting. The desired outcome is an application with narrowly scoped, renewable credentials and a clear record of which identity it uses.