AI coding agents are becoming capable of doing much more than generating application code. They can inspect AWS resources, execute deployment commands, update Lambda functions, read CloudWatch logs, and interact with infrastructure through the AWS CLI, SDKs, and Model Context Protocol (MCP) tools.
These capabilities introduce an important security question: what happens if an AI agent receives access to an AWS account using permanent access keys?
A developer might create an IAM user, generate an access key and secret access key, and store them in a local environment file so the agent can deploy an application. This may work, but it also creates a credential-management problem.
If the agent's environment is compromised, its logs expose credentials, or a configuration file is accidentally committed to source control, an attacker may gain access to AWS resources until the credentials are disabled.
A better approach is to use temporary credentials issued through AWS Identity and Access Management (IAM) and AWS Security Token Service (STS).
Temporary credentials expire automatically, reducing the period during which exposed credentials can be used. When combined with narrowly scoped IAM permissions, they provide a safer way to let AI coding agents interact with AWS resources.
This article explains how temporary credentials work, how to configure an AWS role for an AI coding agent, and how to verify that the agent is using the intended identity and permissions.
Why Long Lived AWS Access Keys Are a Problem
AWS programmatic access commonly uses an access key ID and a secret access key.
An access key pair associated with an IAM user can remain valid until it is deactivated or deleted.
Consider a developer who configures an AI coding agent to deploy a Lambda function.
The developer creates an IAM user and generates access keys:
aws configure --profile coding-agent
The AWS CLI asks for:
AWS Access Key ID
AWS Secret Access Key
Default region name
Default output format
The credentials are stored in the local AWS configuration and credentials files.
The agent can now execute commands such as:
aws lambda list-functions \
--profile coding-agent
The problem is not that the AWS CLI is unsafe. The problem is the lifetime and authority of the credentials supplied to it.
If the credentials are exposed, an attacker may continue using them until someone detects the problem and disables the access key.
This creates several risks:
- Credentials may accidentally appear in terminal output or application logs.
- Developers may commit credential files or environment variables to repositories.
- An AI agent may read files containing secrets while inspecting a project.
- Multiple tools may share the same credentials without clear separation.
- Forgotten access keys may remain active after a project is no longer maintained.
AWS recommends temporary credentials instead of long-lived access keys wherever possible.
Understanding Temporary Credentials in AWS
AWS Security Token Service provides temporary security credentials that applications and users can use to access AWS resources.
These credentials contain three values:
- Access key ID
- Secret access key
- Session token
Unlike long-lived IAM user access keys, temporary credentials have an expiration time.
For example, an IAM role can issue credentials that remain valid for a limited session. Once the credentials expire, AWS no longer accepts requests signed with them.
The basic process looks like this:
Developer authenticates
|
v
Identity provider or AWS IAM
|
v
Temporary credentials issued
|
v
AI coding agent uses AWS CLI or SDK
|
v
AWS evaluates IAM permissions
|
v
Request allowed or denied
|
v
Credentials expire
The important advantage is that developers do not need to distribute permanent AWS access keys to the agent.
The agent receives credentials for a specific session, and AWS validates those credentials when it receives API requests.
Temporary credentials are not automatically restricted to read-only access. They can have powerful permissions if the role that issues them allows those permissions.
Therefore, credential lifetime and permission scope must be considered separately.
Understanding IAM Roles and AWS STS
IAM roles provide a practical foundation for temporary access.
An IAM role is an AWS identity with an associated set of permissions. Unlike an IAM user, it does not have permanent access keys associated with it.
Instead, a trusted identity assumes the role and receives temporary security credentials.
Two important policies control how this works.
Trust policy
The trust policy defines which identities can assume the role.
For example, an IAM role might trust an IAM Identity Center session, an existing IAM role, or a federated identity provider.
The exact trust configuration depends on how the coding agent authenticates.
Permissions policy
The permissions policy defines what the role session can do after the role is assumed.
For example, a deployment agent might need permission to update one Lambda function and read its CloudWatch logs.
It should not automatically receive permission to delete every Lambda function or modify IAM users.
This separation is important because authentication and authorization solve different problems.
Authentication establishes which identity is making the request. Authorization determines which operations that identity is allowed to perform.
Creating a Dedicated IAM Role for an AI Coding Agent
A good starting point is to create a separate IAM role for the agent instead of reusing an administrator identity.
Consider an agent responsible for deploying one development Lambda function.
Its responsibilities might include:
- Updating the function code.
- Reading the function configuration.
- Retrieving its execution logs.
The agent does not need permission to manage unrelated S3 buckets, databases, IAM users, or production resources.
A sample permissions policy could look like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadAndUpdateDevelopmentFunction",
"Effect": "Allow",
"Action": [
"lambda:GetFunction",
"lambda:GetFunctionConfiguration",
"lambda:UpdateFunctionCode"
],
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:my-dev-function"
},
{
"Sid": "ReadDevelopmentFunctionLogs",
"Effect": "Allow",
"Action": [
"logs:DescribeLogStreams",
"logs:GetLogEvents",
"logs:FilterLogEvents"
],
"Resource": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/lambda/my-dev-function:*"
}
]
}
Replace the account ID, Region, and resource names with the actual values from your AWS environment.
This policy grants access to a specific Lambda function and its associated log group.
It does not grant general administrator access.
The permissions should be adjusted according to the actual deployment workflow. For example, a deployment process that updates Lambda configuration or publishes versions will require additional actions.
Also remember that IAM policies are evaluated together with other applicable controls, including permission boundaries, service control policies, and resource-based policies.
The final effective permissions may therefore be more restrictive than this example.
Using AWS IAM Identity Center for Developer Authentication
For local development, AWS IAM Identity Center is a useful way to authenticate developers without creating permanent access keys.
Instead of storing an IAM user's access key and secret access key, the developer signs in through the organization's identity provider and obtains temporary credentials.
First, configure an IAM Identity Center permission set with the required AWS account and permissions.
Then configure the AWS CLI:
aws configure sso
The command asks for the IAM Identity Center start URL, Region, and other configuration details.
After configuration, sign in:
aws sso login --profile coding-agent
The AWS CLI opens a browser-based authentication flow.
After successful authentication, the profile can be used to execute AWS commands:
aws sts get-caller-identity \
--profile coding-agent
This command returns information about the identity currently being used.
A coding agent can use the same AWS profile when executing supported AWS CLI commands.
For example:
aws lambda list-functions \
--profile coding-agent
This approach avoids manually distributing permanent IAM access keys.
However, the permissions assigned to the Identity Center session still matter. If the session has administrator permissions, the agent can exercise that authority while its credentials remain valid.
For stronger isolation, use a dedicated permission set or a controlled role-assumption workflow with permissions appropriate for the agent's task.
Using AWS STS AssumeRole for Temporary Access
Another approach is to use AWS STS AssumeRole.
This is useful when a developer already has an authenticated AWS identity but wants the coding agent to operate through a separate role with more limited permissions.
The flow looks like this:
Developer's authenticated AWS identity
|
v
AWS STS
|
v
AssumeRole
|
v
Dedicated agent IAM role
|
v
Temporary session credentials
|
v
AI coding agent
For example, an existing authenticated profile can assume a deployment role:
aws sts assume-role \
--role-arn arn:aws:iam::123456789012:role/DevAgentRole \
--role-session-name coding-agent-session \
--duration-seconds 3600 \
--profile developer
The command requests a one-hour session.
If the caller is authorized and the role's trust policy permits the operation, AWS returns temporary credentials.
The response includes an access key ID, secret access key, session token, and expiration time.
These credentials can be used by AWS CLI and SDK clients.
Avoid copying the returned credentials into source files, prompts, or agent conversation history. Prefer a configured credential provider or role-assumption mechanism that supplies and refreshes credentials without exposing their values to the agent.
The requested duration must also respect the role's maximum session duration and the limits of the authentication mechanism being used.
Restricting Temporary Credentials Further With Session Policies
Sometimes a developer needs to reduce the permissions of an already authenticated session without creating a completely separate identity.
AWS STS provides mechanisms for narrowing permissions.
For example, AssumeRole supports session policies. The effective permissions of the resulting role session are the intersection of the role's identity-based permissions and the session policy.
AWS also provides GetScopedCredentials, which can narrow an existing temporary session while preserving its identity.
This is particularly relevant to agent workflows.
Imagine that a developer has an authenticated session with permission to deploy multiple development services. A specific coding task only requires updating one Lambda function.
A scoped session can restrict the agent to that smaller set of actions and resources.
The following example illustrates a policy that permits updating a single development function:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:GetFunction",
"lambda:UpdateFunctionCode"
],
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:my-dev-function"
}
]
}
When used as a scope-down policy, this policy cannot grant permissions that the original session does not already have.
It only narrows the permissions available to the resulting session.
This distinction is important: a session policy is not a replacement for a properly configured IAM role. The role must already have the permissions the task requires.
Connecting an AI Coding Agent to AWS Credentials
Once the authentication mechanism is configured, the next step is connecting the agent to the correct AWS credential source.
Different coding agents support different integration methods, but common approaches include:
- Executing AWS CLI commands through a terminal.
- Using AWS SDK credential providers.
- Connecting through an MCP server.
- Using environment-specific credential providers in a development container.
For example, if the agent uses the AWS CLI, it can execute:
aws sts get-caller-identity \
--profile coding-agent
This verifies the identity associated with the selected profile.
An agent using an SDK can also rely on the SDK's default credential provider chain instead of receiving access keys directly.
For example, in a .NET application using the AWS SDK:
using Amazon;
using Amazon.S3;
var client = new AmazonS3Client(
RegionEndpoint.USEast1);
The SDK can resolve credentials through its configured credential sources, including supported IAM Identity Center and role-based providers.
The application does not need to hardcode access keys.
For AI agents, the same principle applies: the credential provider should handle authentication and refresh, while the agent should focus on the requested AWS operation.
One important precaution is to verify every access path.
A terminal session and an MCP server may use different credential sources. Confirming the identity in one does not prove that another integration uses the same identity.
Verifying the Agent's AWS Identity Before Deployment
Before allowing an AI coding agent to create, update, or delete AWS resources, verify which account and identity it is using.
The AWS CLI provides a simple command:
aws sts get-caller-identity
A response looks like this:
{
"UserId": "AROAEXAMPLE:agent-session",
"Account": "123456789012",
"Arn": "arn:aws:sts::123456789012:assumed-role/DevAgentRole/agent-session"
}
The response identifies the AWS account and the caller's ARN.
The ARN should indicate the expected role session rather than an unexpected administrator or user identity.
Also verify the AWS Region:
aws configure get region \
--profile coding-agent
Before a deployment, check the following:
- The account ID matches the intended development account.
- The role ARN identifies the expected agent role.
- The Region matches the target environment.
- The role permissions are limited to the required resources.
- The agent is not using a different credential source through another tool.
This check should be part of the deployment workflow, not something performed only during initial setup.
Using AWS's New AI Coding Tool Connection Experience
AWS also provides a project-based workflow for connecting supported AI coding tools to AWS resources.
In this experience, developers can open AWS Settings, select a project, and choose the option to use AWS credentials with AI coding tools.
AWS provides an agent setup prompt that helps configure the connection and the associated tooling.
The credentials generated through this specific project experience are intended for supported AWS CLI, AWS Tools for PowerShell, and AWS SDK workflows. AWS documentation currently describes a 12-hour access period, with renewal through the AWS CLI.
For example:
aws login --profile MyDevelopmentProject
The command opens a browser-based flow in which the developer selects the appropriate AWS project.
Each project can have its own CLI profile, helping developers distinguish between different development environments.
This is a useful option for supported coding agents, but it should not be confused with a universal credential mechanism for every third-party agent or MCP integration. Verify that the tool actually uses the configured AWS credential source.
Also, connecting an agent to an AWS project does not automatically establish least-privilege access. Review the permissions associated with the identity before allowing it to perform infrastructure operations.
Monitoring and Auditing Agent Activity
Temporary credentials reduce the risk associated with exposed credentials, but they do not eliminate the need for monitoring.
An agent can still make an incorrect or unauthorized request while its session is active if its permissions allow that operation.
AWS CloudTrail records API activity and can help identify which identity performed an operation.
For example, teams can monitor:
- Lambda function updates.
- S3 object changes.
- IAM policy modifications.
- Infrastructure deployment operations.
- Access-denied events.
- Unexpected changes outside the intended development environment.
Use meaningful role session names and, where appropriate, source identity and session tags to make activity easier to associate with a task or execution context.
Avoid placing sensitive information in session names or audit metadata.
For important operations, combine AWS authorization with execution controls. An agent may propose a deployment, but a human approval step can be required before production changes are applied.
The prompt can guide the agent, while the execution environment and IAM policies enforce the actual restrictions.
Common Mistakes When Giving AWS Access to Coding Agents
A few mistakes can undermine an otherwise well-designed credential strategy.
Assuming Temporary Credentials Are Automatically Safe
Temporary credentials expire, but they can still have broad permissions while active.
A one-hour administrator session can cause significant damage in less than a minute.
Use temporary credentials together with least-privilege policies.
Reusing a Developer's Administrator Session
An agent that inherits a developer's administrator credentials receives the same broad authority.
Create a dedicated role or permission set for agent tasks rather than automatically reusing a personal administrator session.
Passing Credentials Through Prompts
Never paste secret access keys, session tokens, or credential files into an AI conversation.
The agent should use an approved credential provider or execution environment.
Forgetting That Different Tools May Use Different Identities
The AWS CLI, SDK, and MCP server may use different profiles or authentication mechanisms.
Verify the identity through each integration that can access AWS.
Treating Expiration as a Permission Boundary
Credential expiration limits how long a session remains valid. It does not limit which operations are permitted during that session.
Use resource-level policies, role permissions, session policies, and other authorization controls to restrict actions.
Ignoring Credential Caches
Temporary credentials and authentication tokens may still be cached locally.
Protect local credential files, browser sessions, developer machines, and build environments. Avoid sharing credential directories between unrelated users or agent processes.
Summary
AI coding agents can simplify AWS development, but giving them permanent access keys creates unnecessary security risks.
AWS IAM roles and STS provide a better foundation by issuing temporary credentials that expire automatically. Developers can use IAM Identity Center, role assumption, and supported credential providers to authenticate agents without embedding long-lived access keys in projects or prompts.
However, temporary credentials alone are not enough. A secure design also requires dedicated roles, narrowly scoped permissions, identity verification, and monitoring through CloudTrail.
Before an agent performs an AWS operation, verify its account, role, Region, and effective permissions. For sensitive deployments, combine these controls with human approval and separate development and production environments.
The goal is not simply to make AWS credentials temporary. It is to ensure that an AI coding agent receives only the authority required for its current task, for only as long as that access is needed.
Join the conversation! Your thoughts help the community grow.