AWS Builder Center

From Static to Dynamic: Choosing the Right Way to Get AWS Credentials to Your Workloads Running Outside AWS

It's pretty easy to write an application that accesses an AWS service when your application runs on AWS compute. AWS takes care of the heavy lifting of getting a temporary credential to your compute resource, and rotating it as needed. It's also pretty easy for a developer to get access to AWS from their workstation by running `aws login` or `aws sso login`, but what do you do about workloads running outside of AWS, such as on-premises, other cloud providers, or anything in between?

I evaluate the IAM policies sent to various services by hand and decide who gets access to what
This post is a written version of the talk that myself and my friend/colleague  Meg Peddada  have given at AWS re:Inforce and re:Invent over the years (SEC333/IAM333) where we take a look at different strategies for authenticating workloads that run outside of AWS, to AWS to let them securely use AWS services without the need to provision long term access keys.
You can view the original slides  here . This talk will be re-done at Re:invent 2026 with a slightly different spin as SEC359 and I think it'd be a good use of your time if you're in Vegas this year.

I'll explain to you how the AWS SDK finds credentials, and how we can use that logic to help your applications/tasks/workloads/etc running outside of AWS to get and refresh AWS credentials, and what is the right federation technology to access AWS from outside AWS.




To use AWS services when your app runs on AWS managed compute, like Amazon EC2, AWS Lambda, Amazon ECS, or Amazon EKS, you attach an IAM role. The AWS service creates temporary credentials for that role and makes them available on that compute, rotates those credentials, and the AWS SDKs can safely handle that credential rotation by refreshing the credentials automagically in a long running process.

Workloads running outside of AWS don't have that luxury most of the time. Workloads on your on-premises servers, Cloud hosted CI/CD pipeline such as GitHub/GitLab/CircleCI/Buildkite, other clouds like Azure, Google Cloud, or Oracle. A workload/task/job running in any of these environments may need to access AWS, but AWS cannot safely deliver temporary AWS credentials to compute outside AWS by ourselves.

The lowest-friction way to access AWS from outside AWS has historically been the access key pair, associated with an IAM user. While simple this is a bad idea in practice. In 2025, roughly two thirds of the time a security issue was reported to AWS by a customer the initial access was found to be with a long-lived credential that fell into the possession of an unauthorized user. These access keys are often priority targets by bad actors and are used to facilitate attacks such as ransomware, llmjacking, cryptomining, as well as many other forms of abuse.

The more secure way is temporary credentials for an IAM role. They expire on their own and work with every SDK. The real question is how to get them to a workload that runs outside AWS. This article compares the options.

The foundation: temporary credentials and the AWS SDK

Before comparing strategies, it helps to understand the fundamentals of how applications use AWS credentials

Temporary credentials look almost the same, and that's the point

A long-term access key ID starts with  AKIA . A temporary credential issued by AWS Security Token Service (AWS STS) starts with  ASIA  and comes with a session token. This is an example aws profile with temporary access keys, which in practice is not a good thing to do and we're only doing it here for demonstration purposes.
[default]
aws_access_key_id = ASIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
aws_session_token = SomeVeryLongBase64EncodedEncryptedAndSignedPayload...
Temporary credentials expire automatically, and they work with every currently supported AWS SDK and the AWS CLI. They're used for Signature Version 4 (SigV4) authentication in exactly the same way as long-term keys, and with either kind the secret access key never leaves your machine as part of your request to AWS. The strategies below differ only in how they get these credentials to your workload.

Sigv4 is an HMAC based authentication mechanism pioneered by AWS that is awesome, and solves a lot of the problems inherent with OAuth and bearer token authentication that there are countless addendum RFCs in place to compensate for - but the details of this are for another post :).

The SDK's default credential provider chain

When you create an SDK client without specifying credentials, the SDK checks a series of sources in order and stops at the first valid one. In simplified form, the order is:
  1. Credentials in environment variables ( AWS_ACCESS_KEY_ID ,  AWS_SECRET_ACCESS_KEY , AWS_SESSION_TOKEN )
  1. Web identity environment variables ( AWS_WEB_IDENTITY_TOKEN_FILE ,  AWS_ROLE_ARN )
  1. The default profile in the credentials file (profiles in  ~/.aws/config  and  ~/.aws/credentials ). You can influence the profiles used by modifying the  AWS_PROFILE  and  AWS_SHARED_CREDENTIALS_FILE  to change the profile and credentials file used
  • There can be profile name collisions across the two files. We recommend only keeping credential definitions in one of the files for that reason.
  1. ECS-compatible container credential endpoints (environment variables saying an HTTP endpoint to search)
  1. EC2 instance metadata (IMDS). The default location used for IMDS is 169.254.169.254, but you can override this with environment variables too.

This is known as the default credential provider chain. Implementations may vary slightly across SDKs, but the above holds true in most cases. Consult SDK documentation for specific implementations.

I've worked with some customers to help remove some long lived access keys before that were documented as only supporting IAM user access keys, but in reality the application supported AWS profiles, or the default credential provider so we had a more clever way to support temporary credentials.
Many service providers make statements like "we don't support federation with X" with our client, but in practice that is an untrue statement because their client is built with our SDK, and our SDK doesn't really care about where it gets credentials from, just so long that it can get credentials.

 credential_process : the integration point that does the heavy lifting

A profile can hold more than static keys. It can hold a number of directives, such as the  credential_source  directive to tell the SDK where to look to find credentials, or can be used to configure role-chaining by referencing other profiles to use to assume other roles.
But the most powerful feature is  credential_process . The  credential_process  setting tells the SDK to run an external program whenever it needs credentials:
[profile my-workload]
credential_process = /path/to/credential_helper [arguments]
The program writes JSON to stdout:
{
"Version": 1,
"AccessKeyId": "ASIAVxxxxxxExample",
"SecretAccessKey": "O9mjURdFnkvQtXdAVerySecretKey",
"SessionToken": "LongTokenValue",
"Expiration": "2026-05-15T18:42:51+00:00"
}
The AWS SDKs calls the program again shortly before the credentials expire based on the value set for "Expiration". That gives you automatic renewal without changing any application code, and it lets you put your identity integration logic in one reusable place. Several of the strategies below use this mechanism.

Using credentials in your code.

# Don't do this please :)
session = boto3.Session(aws_access_key_id='ASIA...', aws_secret_access_key='...')

# Do this: use the default provider chain...
session = boto3.Session()

# ...or name a profile explicitly
session = boto3.Session(profile_name='my-workload')
On AWS compute, you can typically safely rely on the default provider chain so that your code works the same on EC2, ECS, Fargate, EKS, and Lambda.

This means that if an application uses the default credentials provider chain when it runs in AWS, it will discover credentials regardless of which service it runs on. If it runs outside of AWS it will do the same credential provider search, and you can use that logic to make AWS credentials available to your application.

As an example, an application running on EC2 or EKS with the default credentials provider, will behave identically to an application running on your on-premises virtual machines if you specify a  [default]  aws profile with a credential_process that sources AWS credentials, such as by the IAM Roles Anywhere Credential Helper.

I've told you all of the above because these implementation details will help you build apps that can "run anywhere" but still use AWS seamlessly.

The strategies at a glance

Strategy
Credential
Best fit
Custom code
Traces back to workload?
Effort
IAM Roles Anywhere
X.509 certificate
Data center and multicloud servers
None
Yes, to the certificate
Medium to high from PKI. I always say "IAMRA is very easy, PKI is very hard"
AssumeRoleWithSAML
SAML assertion
Mature AD or Kerberos environments with a SAML provider like PingFederate or ADFS
Usually
Yes, to the IdP identity
Medium. A lot of very large enterprises do this, and it's basically custom building something not meant for machines.
AssumeRoleWithWebIdentity
OIDC JWT
CI/CD, other clouds, Kubernetes, modern systems.
Little or none
Yes, to JWT claims
Low to medium. This is typically the best answer
SSM hybrid activations
SSM Agent registration
Hosts you also want to manage with aws, simple automation and tasks such as data movement.
None
No, only to the activation code and SSM agent
Low
Credential brokers
Whatever the broker accepts
Organizations already running one for other purposes
None
Depends on the broker
Medium-High

IAM Roles Anywhere

IAM Roles Anywhere flow: (1) the workload sends its X.509 certificate and a signature made with its private key to IAM Roles Anywhere, (2) IAM Roles Anywhere validates the certificate against the trust anchor and gets credentials from AWS STS, (3) AWS STS returns temporary credentials, (4) IAM Roles Anywhere passes them to the workload, and (5) the workload calls Amazon S3

IAM Roles Anywhere is a feature of AWS IAM that allows you to use certificates to authenticate to AWS, and get temporary AWS credentials in return.

You register your certificate authority as a trust anchor. That can be your own Private CA or AWS Private CA. Workloads then exchange a certificate and a signature for temporary credentials. The AWS  aws_signing_helper  works as a  credential_process , as a local IMDS-compatible endpoint (handy as a sidecar), or as a daemon that writes the credentials file. It can read keys from TPMs, PKCS#11 devices, OS certificate stores, or the filesystem. If you don't run a CA today, you can  set up AWS Private CA to issue certificates for IAM Roles Anywhere . Before you roll it out, read  Planning for your IAM Roles Anywhere deployment .
  • Pros: Certificates expire, and keys for those certs can stay in hardware (TPM, HSM) if you like. If you already issue certificates for HTTPS or MTLS, you've done the hard part as those certificates can be used with IAM roles anywhere already. Activity traces back to identities in your PKI/Directory.
  • Cons: PKI ends up on the critical path for AWS access, including issuance, renewal, and revocation. It also takes operational expertise. Starting up a PKI and distributing certificates can be cumbersome if you do not already do so.
  • Choose it if you issue certificates, or are willing to invest the time and money in doing so.

AssumeRoleWithSAML

AssumeRoleWithSAML flow: (1) the workload authenticates to the SAML IdP, (2) the IdP returns a SAML assertion, (3) the workload calls AssumeRoleWithSAML on AWS STS with the assertion, (4) AWS STS returns temporary credentials, and (5) the workload calls Amazon S3

SAML is a browser protocol designed for humans. AssumeRoleWithSAML is an ordinary AWS STS API, though, and any process that can get a SAML assertion from your IdP can call it. Put the IdP integration in a  credential_process  script and you can quickly have a workload federating access to AWS. The AWS Labs  STS SAML Driver  is a starting point, and there's also a  reference script for AD FS  that has been used directly, and also adapted and customized widely by customers.

This is a bit of a hack, but in 2013 when we launched assume role with SAML it immediately gained a tonne of traction with enterprise as OIDC/JWTs were not yet mature, and this integrated with their identity systems so it was the lowest friction, very secure and scalable path.

SAML assertions bound for  AWS STS must contain a list of roles this assertion is valid for , as well as being trusted by the AWS Account and IAM role that is being assumed. Check the above linked documentation to learn more about the requirements for using AssumeRoleWithSAML.
  • Pros: Reuses the workload identity you already have, such as Kerberos or AD. Entitlements and revocation stay in your directory. This pattern scales incredibly well, and many very large customers operating on AWS have large scale on-premises systems which make use of SAML.
  • Cons: SAML wasn't built for machines, so getting an assertion non-interactively usually means custom code that you own. If the IdP goes down, credentials can't renew.
  • Choose it if machines can already authenticate to a SAML IdP and you can map them to roles. Skip it if you don't want to own IdP integration code, or if you're not coming from an enterprise or legacy workload environment.

AssumeRoleWithWebIdentity (OIDC/JWT)

AssumeRoleWithWebIdentity flow: (1) the token issuer gives the workload a signed JWT, (2) the workload calls AssumeRoleWithWebIdentity on AWS STS with the JWT and role ARN, (3) AWS STS fetches the issuer's OIDC discovery document and JWKS to verify the token, (4) AWS STS returns temporary credentials, and (5) the workload calls Amazon S3

AssumeRoleWithWebIdentity is an AWS STS API in which you present a JSON Web Token delivered by any means - OIDC, OAuth, or injected by a scheduler like Kubernetes or githubactions, to authenticate and receive temporary AWS security credentials in return. The JWT MUST be compatible with the OIDC discovery standard. This is the method I would recommend to most customers, most of the time if it is available.

We called it web identity because we wanted to be clear that the intended usage of a given JWT isn't necesarrily OAuth or OIDC related, even though those are some of the most common ways to receive a JWT.

The SDKs support this natively through  AWS_WEB_IDENTITY_TOKEN_FILE  and  AWS_ROLE_ARN  environment variables, in which if these environment variables are present, the SDK will attempt to use the token from the specified file to assume the specified role.
You can also configure a  credential_process  to handle retrieving a JWT for you, and calling this API.

On Kubernetes, the open-source  Amazon EKS Pod Identity Webhook  sets these variables for you on any cluster. This Webhook powers the EKS feature "IAM Roles For Service Accounts (IRSA)"
The AWS Labs  STS OIDC Driver  works as a sample  credential_process  which allows you to use a variety of different OAuth/OIDC grants to call AssumeRoleWithWebIdentity.

Other Cloud and SaaS providers commonly use the JWT as their credentials, and this means other cloud providers can typically call AssumeRoleWithWebIdentity directly. Step-by-step guides exist for  GitHub Actions ,  Microsoft Entra ID , and  Google Cloud . I do not have a guide off hand, but Oracle Cloud, GitLab, Buildkite, Vercel, CircleCI and many others have awesome "OIDC"/AssumeRoleWithWebIdentity integrations that allow you to access your AWS accounts from their platform without long-lived secrets. We are seeing the number of AWS partners, SaaS providers, and cloud providers who support this pattern grow all the time and it would be our default recommended approach if it is available.

If you're using a SaaS that isn't running on AWS and needs to access AWS, this is the pattern you should be asking your provider to adopt.

  • Pros: Often needs nothing on your side because the platform already issues the token. Tokens are short-lived, and trust policies can condition on  sub  and  aud  claims down to a single repository, branch, or service account. Allows for easy key rotation, has a clear quantum safe roadmap, and is very modern.
  • Cons: AWS STS must be able to reach your discovery endpoint from the internet. If your discovery endpoint is private, consider reading my guide on  split horizon DNS  to solve this problem.
  • Choose it for CI/CD, other clouds, and Kubernetes distributions such as kOps, OpenShift, or EKS Anywhere.
  • Be Aware: Review the security model of any third party OIDC/JWT system and make sure you're appropriately scoping different identities to only the IAM roles they need to do their tasks with the relevant claims in role trust policy.

AWS Systems Manager hybrid activations




AWS Systems Manager (SSM) has an awesome feature called "hybrid activations" which allows you to manage a server running "not in AWS" using AWS systems manager. As part of this, systems manager needs to keep a set of valid AWS credentials on the host, so they implemented an oauth-adjacent strategy in which the SSM Agent running on the host can bootstrap a refreshing AWS credential set using an activation code. After the server is enrolled as an SSM hybrid activation, the agent can use the SSM run command with AWS credentials!
You create an activation tied to an IAM role and register SSM Agent with the activation code. From then on, the agent gets and renews its own credentials. For a walkthrough, see  Using AWS Systems Manager in hybrid cloud environments .

I love this solution and its simplicity. If you want to do a simple thing, this is worth taking a look at.

Here's a story I love to share about SSM: Once I had a customer who needed to upload data from Linux-based servers that had data from microscopes and other lab equipment to S3. Their first plan was to store a secret on each device, trade it for a JWT, and call AWS STS. To build this out, this customer was going to spend some months of dev time building this out. After I had a brief chat with them and confirmed their only use case was just moving data from the local file system to S3, I demoed SSM with run command to them. Because their use case was so simple, for them to use SSM was also simple and they had their data flowing the next week instead of months out.

  • Pros: The easiest setup on this list. It includes host management (Run Command, Patch Manager, Session Manager).
  • Cons: The identity belongs to the agent, not the workload, so activity doesn't trace back to your identity source. The agent runs as root. Treat the activation code as a secret until registration finishes.
  • Choose it if you want SSM to manage these hosts and host-level identity is acceptable. Skip it if you need lineage back to your identity source.

Please note the SSM agent is an agent like a "daemon", not an ai agent. This existed before AI agents.

Credential brokers




Workloads authenticate to a broker such as HashiCorp Vault using their identity, which then calls STS with a credential/identity from the broker. The broker then returns AWS credentials. I use Vault as a reference as that is the provider I am most familiar with, but there are other providers as well.

  • Pros: Typically no custom code as there are helper agents/integrations to help your code talk to the broker.
  • Cons: The broker becomes a high-value target. It usually holds a powerful AWS credential, sometimes an IAM user key, so lock that credential down with IP allowlisting, rotation, and least privilege. You take on the burden of operating this broker, and its availability underpins everything else you do on AWS through this broker.
  • Choose it if you already run a broker. Skip it if your workloads already have a credential AWS accepts directly, such as a certificate, or JWT that they might otherwise use to authenticate to the broker.

Recent versions of Vault enterprise can act as an OIDC but older versions of vault had you import a single IAM user access key pair. I'd rather you use 0 IAM users, but the next best number to 0 is 1. If you're going down the IAM user access key path, apply compensating controls like IP allowlisting.

The last resort: IAM user access keys

Use them only when no other option works, the workload can't move to AWS, the need has a known end date, your organization accepts the risk, and you apply compensating controls: least privilege, IP allowlisting, rotation, extreme least privilege, and anomaly monitoring. Embrace the mindset that this access key may be out of your control the moment it is distributed to your workload.

I want to place extra emphasis on IP allowlisting. If you can lock down your IAM user access key to a known-list of trusted public IP address that belong to your organization and are not shared/multi-tenant then you can significantly reduce the risk of impact in the event the key gets leaked. It forces the adversary to persist on your network to use this key which makes it harder, but still not impossible for them to use it. Use a DENY IAM policy statement to create this IP allowlist.

A decision guide for your workloads

  1. Can it run on AWS compute? Use an IAM role assigned to that compute. This is very easy to do
  1. Does the platform already issue tokens (GitHub, GitLab, Azure, Google Cloud, Kubernetes, Vercel, and so many others)? Use AssumeRoleWithWebIdentity with "OIDC"
  1. Do you issue certificates certificates for your workloads? Use IAM Roles Anywhere.
  1. Is your usecase simple, like running a batch/python script on a schedule? Use SSM hybrid activations and the run command.
  1. Can machines already authenticate to a SAML IdP and you're complex/enterprise-y? Use AssumeRoleWithSAML.
  1. Do you already run a broker? Use the broker for AWS too

These can combine well too. e.g. it is possible for your workloads running in Azure to use their Azure credentials to access AWS, but you use PKI and IAM Roles Anywhere with your premises servers to access AWS, or any combination thereof.

Getting started

Prioritize your access keys by risk. Assess which strategy could replace each one. Replace them with short-term credentials. Reduce by deleting unused keys. Govern with policies and automated controls so keys don't come back. Apply Compensating Controls to reduce risk if you cannot move away from long lived access keys right away.

Resources

Foundations
IAM Roles Anywhere
AssumeRoleWithSAML
AssumeRoleWithWebIdentity
AWS Systems Manager
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article