APIs: Concepts, Design, Requests, Responses, and Integration
AWS Credentials for API Access
Learn how AWS credentials authenticate API requests, how IAM authorizes actions, and how to configure, rotate, troubleshoot, and securely use temporary and long-term credentials.
AWS credentials are values used to authenticate a caller to an AWS API endpoint. They tell AWS which principal—such as an IAM user, IAM role, federated identity, or workload—is making a request.
Authentication answers “Who is making this request?” Authorization answers “Is that principal allowed to perform this action on this resource?” AWS credentials establish identity; IAM policies determine permissions.
How AWS Credentials Authenticate API Requests
Most AWS API requests are authenticated with AWS Signature Version 4, commonly called SigV4. An SDK or command-line tool uses the credential material to create a signature over important request data, including the HTTP method, path, selected headers, body hash, region, service name, and timestamp.
- The application obtains credentials from a configured provider.
- The SDK creates a canonical representation of the request.
- The SDK calculates a signature using the secret access key.
- The signed request is sent to an AWS service.
- AWS verifies the signature, identifies the principal, and evaluates IAM policies.
- The service either performs the action or returns an authentication or authorization error.
Signing helps AWS verify both the caller and the integrity of the request. Changing a signed header, request body, region, endpoint, or timestamp after signing can invalidate the signature. Official SDKs should handle signing automatically unless an integration specifically requires direct HTTP requests.
AWS Credential Components
| Component | Meaning | Security and usage notes |
|---|---|---|
| Access key ID | A non-secret identifier associated with an access key. | It is sent with the request and helps identify the credential pair, but it must still be handled carefully. |
| Secret access key | Confidential key material used to calculate request signatures. | Never disclose it or commit it to source control. |
| Session token | An additional token issued with temporary security credentials. | It must be included in requests made with temporary credentials. |
| Expiration time | The time at which temporary credentials stop being valid. | Applications should refresh credentials before expiration. |
| Region and service name | Inputs commonly used by SigV4. | A wrong region or service identifier can produce a signature mismatch. |
Credential Types
| Credential type | Components | Typical lifetime | Common source | Recommended use | Key security consideration |
|---|---|---|---|---|---|
| Long-term access keys | Access key ID and secret access key | Until rotated, deactivated, or deleted | IAM user | Only when a long-term programmatic identity is unavoidable | Greater exposure risk; rotate and restrict carefully |
| Temporary security credentials | Access key ID, secret access key, and session token | Limited session duration | AWS STS, IAM roles, federation, or workload identity | Preferred for people, applications, CI/CD, and workloads | Must refresh before expiration and include the session token |
| IAM user credentials | Console credentials and optionally long-term access keys | Long-lived unless changed | An IAM user | Specific legacy or unavoidable programmatic cases | Do not use broad permissions or share users |
| IAM role credentials | Temporary security credentials | Limited session duration | STS role assumption or workload attachment | Preferred for AWS workloads and delegated access | Constrain trust and permission policies |
| Root-user credentials | Account root sign-in and optional root access keys | Account-level | The AWS account root user | Only exceptional account-management tasks | Do not create or use root access keys for normal development or applications |
| Federated identity credentials | Temporary role credentials obtained after external authentication | Limited session duration | IAM Identity Center or an external identity provider | Human and enterprise access | Protect the external identity and restrict role trust |
| Workload identity credentials | Temporary role credentials | Limited and renewable | EC2 instance profiles, ECS task roles, or EKS web identity | AWS-hosted applications and containers | Avoid sharing static keys among workloads |
IAM Roles and Temporary Credentials
An IAM role is an assumable identity with permission policies. When a principal assumes a role through AWS Security Token Service (STS), AWS returns temporary security credentials. These credentials expire automatically, which reduces the useful lifetime of leaked material and supports narrowly scoped sessions.
Temporary role-based credentials are generally preferred because they avoid embedding permanent secrets, support different permissions for different workloads, and can be refreshed by the runtime or SDK.
Common workload identity choices
| Runtime | Preferred identity mechanism | Credential delivery method | Example AWS services accessed |
|---|---|---|---|
| Amazon EC2 | IAM role attached through an instance profile | Temporary credentials from the EC2 instance metadata service | Amazon S3, Amazon DynamoDB, Amazon CloudWatch |
| Amazon ECS | ECS task role | Temporary credentials exposed to the task through the container credential provider | Amazon DynamoDB, Amazon SQS, Amazon S3 |
| Amazon EKS | IAM role for service accounts or another web identity mechanism | A Kubernetes service-account token is exchanged for temporary role credentials | Amazon S3, Amazon Secrets Manager, Amazon Kinesis |
| CI/CD | Federation from the CI platform into a deployment role | Short-lived STS session | CloudFormation, Amazon ECR, deployment services |
| Human users | IAM Identity Center, federation, or an external identity provider | Interactive authentication followed by temporary role credentials | AWS console and approved CLI or SDK operations |
Credential Provider Chains
An AWS SDK or tool usually searches an ordered credential provider chain. The first usable source supplies credentials. Exact order varies by SDK, SDK version, language, and runtime, so consult the relevant SDK behavior when diagnosing precedence.
| Source | Typical environment | How credentials are supplied | Supports temporary credentials | Operational notes |
|---|---|---|---|---|
| Explicit application settings | Special integrations and tests | Credentials or a provider passed directly to the SDK | Yes | Use carefully; explicit secrets can override safer sources |
| Environment variables | Local sessions and CI jobs | Access key ID, secret access key, session token, and region variables | Yes | Limit shell exposure and never commit values |
| Shared credentials file | Developer workstation | Named profiles in the user home directory | Yes | Keep outside repositories and restrict permissions |
| Shared configuration file | Developer workstation and role workflows | Profiles containing region, role assumption, SSO, or source-profile settings | Yes | Profiles select named identity and configuration sets |
| Web identity token file | EKS and federated workloads | Token file plus role information | Yes | Commonly exchanges a trusted token for an IAM role session |
| Container metadata endpoint | ECS tasks | Runtime-provided task-role credentials | Yes | Requires correct task-role configuration and network access |
| EC2 instance metadata | EC2 instances | Credentials for the attached instance profile | Yes | Requires the instance role and metadata service to be available |
An AWS profile is a named set of settings and, sometimes, credentials. Profiles help separate accounts, environments, regions, and role-assumption paths. Do not assume that the default profile is the intended identity.
Configuring Credentials for Local Development
For local work, use IAM Identity Center, federation, or a profile that assumes a role whenever possible. The AWS CLI can create or update a default profile:
aws configure
Use a named profile to separate development environments:
aws configure --profile development
Verify the principal before investigating resource permissions:
aws sts get-caller-identity --profile development
Use a selected profile for one command:
AWS_PROFILE=development aws s3 ls
A shared configuration profile can assume a role using a base profile:
[profile development]
region = us-east-1
role_arn = arn:aws:iam::123456789012:role/DeveloperRole
source_profile = base
Environment variables are useful for temporary local sessions and CI jobs:
export AWS_ACCESS_KEY_ID='...'
export AWS_SECRET_ACCESS_KEY='...'
export AWS_SESSION_TOKEN='...'
export AWS_REGION='us-east-1'
Keep shared credential and configuration files in the user home directory, outside repositories. On systems that support it, restrict file permissions so only the owning user can read credential files. Use repository secret scanning and review changes for accidental secret inclusion.
Using Credentials with SDKs and AWS APIs
SDKs normally load credentials automatically from their provider chain and refresh temporary credentials when the selected provider supports refresh. Applications may explicitly select a profile or provider when multiple identities are available, such as a development profile versus a deployment role.
When using temporary credentials, the access key ID, secret access key, and session token form one credential set. Omitting the session token can result in an invalid-token or signature-related failure even when the key pair is correct.
Prefer an official AWS SDK because it handles credential discovery, SigV4 signing, retries, endpoint details, and temporary credential refresh. Direct signing is appropriate only when an integration requires manually constructed HTTP requests.
Conceptual inputs to a directly signed request
- HTTP method, URI path, query string, and request headers.
- Request body hash when a body is present.
- AWS region and service name.
- Current timestamp and credential scope.
- Access key ID and, for temporary credentials, the session token.
- Secret access key, which remains confidential and is used to calculate the signature.
After signing, do not modify signed headers, the body, endpoint region, or timestamp. A clock that is substantially out of sync can also cause authentication failure.
Authentication Versus Authorization with IAM
Successful authentication does not guarantee that an operation is permitted. After AWS identifies the principal, IAM evaluates applicable policies and restrictions.
- Identity-based policies attach permissions to users, groups, or roles.
- Resource-based policies attach permissions directly to resources such as S3 buckets or SQS queues.
- Permissions boundaries limit the maximum permissions an identity-based policy can grant.
- Service control policies can restrict accounts and organizational units in AWS Organizations.
- Explicit denies override matching allows in the applicable policy evaluation.
Apply least privilege: grant only the actions and resources required for a task. For example, a role that reads reports from one S3 prefix might use a policy shaped like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::example-bucket/reports/*"
}
]
}
Listing a bucket is a separate action and may require separate, narrowly scoped permission. Do not add it unless the application needs it.
Credential Lifecycle and Rotation
Long-term IAM user access keys have a lifecycle: create, activate, use, deactivate, and delete. If long-term keys cannot yet be eliminated, use two-key rotation so a replacement can be tested before the old key is disabled.
| Step | Action | Validation | Rollback or safety consideration |
|---|---|---|---|
| 1 | Identify the owning system, principal, and current key. | Review configuration and CloudTrail activity. | Do not disable an unknown key before identifying dependencies. |
| 2 | Create a second access key while the existing key remains active. | Confirm the new key is active and stored securely. | Keep the old key available for short-term rollback. |
| 3 | Update the dependent application or job. | Run an identity check and a least-privilege functional test. | Do not print secret values in test output. |
| 4 | Deactivate the former key. | Monitor the system for failed calls and review CloudTrail. | Reactivate only briefly if rollback is necessary and the key is not exposed. |
| 5 | Delete the former key after the observation period. | Confirm no required callers use it. | Deletion is permanent; preserve audit records, not secrets. |
Temporary credentials should be renewed or refreshed automatically by STS-aware providers. Fixed environment variables do not refresh themselves; a long-running process using exported session values may fail when those values expire.
If a key may have been exposed, immediately identify the affected principal, deactivate or delete the key, replace dependent credentials, review CloudTrail activity, and investigate repository, build, and deployment logs. Use access analysis and related auditing tools to find unintended access paths.
Secrets Management and Secure Application Design
- Do not embed AWS credentials in source code, browser code, mobile clients, container images, or public configuration.
- Use IAM roles for AWS-hosted workloads instead of injecting static keys.
- Use CI/CD federation and short-lived deployment roles instead of stored deployment keys where possible.
- Use AWS Secrets Manager or Systems Manager Parameter Store for application secrets that are not AWS credentials.
- Enable repository and pipeline secret scanning, and treat detections as possible incidents until investigated.
- Use separate roles for development, testing, and production, with only the permissions needed by each environment.
Common Failures and Diagnosis
| Symptom or error | Likely cause | How to verify | Recommended remediation |
|---|---|---|---|
| No credentials are found | No profile or environment variables; wrong profile; unavailable metadata service | Run an identity check, inspect the selected profile and relevant variables, and verify workload role attachment. | Configure the intended profile or identity system, or attach the correct workload role. Do not hard-code keys. |
| Invalid access key | Typo, wrong key pair, or deactivated/deleted key | Check the active credential source and key status in IAM where applicable. | Use the correct active identity or move to a role-based identity. Rotate if integrity is uncertain. |
| Expired temporary session | STS or federated session expired; process does not refresh; old environment variables remain set | Check expiration details and determine whether the provider supports refresh. | Reauthenticate or re-assume the role. Use a refresh-capable runtime provider. |
| Missing session token | Temporary key pair supplied without its session token | Determine whether the credentials came from STS, federation, or a workload role. | Supply the matching session token or use the SDK's temporary credential provider. |
| AccessDenied | Missing action, mismatched resource or condition, explicit deny, boundary, SCP, or resource-policy restriction | Identify the principal, requested action, resource ARN, and all applicable policies. | Grant only the missing permission or correct its scope when justified. |
| SignatureDoesNotMatch | Wrong secret, missing token, wrong region or service, clock skew, or request changed after signing | Confirm credential type, region, service, system time, and canonical signing inputs. | Use an official SDK where possible and correct signing inputs. |
| Metadata credential retrieval failure | Missing role attachment, blocked metadata or container endpoint, incorrect task role, or broken EKS web identity configuration | Verify the runtime identity configuration and required network or token settings. | Repair the role attachment or provider configuration; do not substitute shared static keys. |
Practical Credential Patterns
Local developer with a named profile
- Authenticate through the approved identity system or configure a limited base profile.
- Use a named profile such as
developmentfor the intended account and region. - Run
aws sts get-caller-identity --profile development. - Run AWS commands with
--profile developmentor setAWS_PROFILE=developmentfor the process. - Investigate authorization only after confirming the authenticated identity.
EC2 application reading an S3 prefix
Attach an instance profile containing a least-privilege IAM role. The SDK obtains temporary credentials from instance metadata, signs S3 requests, and refreshes credentials without access keys in application configuration.
ECS task accessing DynamoDB
Assign an ECS task role rather than placing credentials in the image or task source. Grant only the required DynamoDB actions and table resources. The SDK uses the container credential provider automatically.
EKS workload accessing AWS services
Map a Kubernetes service account to an IAM role using web identity federation. The pod uses its service-account token to obtain temporary AWS credentials, avoiding shared static credentials among pods.
CI/CD deployment assuming a role
Configure the CI platform to federate into a deployment role. Restrict trust to the expected project, branch, or workflow claims, limit deployment permissions and resources, and use a short-lived session rather than a stored deployment key.
Exam-Relevant Notes
- An access key ID is an identifier; the secret access key is confidential signing material.
- Temporary credentials contain three values: access key ID, secret access key, and session token.
- Authentication identifies the principal; authorization determines whether the action is allowed.
- IAM roles usually provide temporary credentials and are preferred for workloads.
- EC2 uses instance profiles, ECS uses task roles, and EKS commonly uses web identity with an IAM role.
- Explicit denies take precedence over allows.
- A valid credential can still receive
AccessDenied. - Most AWS API requests use SigV4, and incorrect region, service, clock, or signed request contents can cause a signature mismatch.
For related learning, review AWS credential configuration and API access alongside IAM policies, STS role assumption, SDK provider behavior, and CloudTrail auditing.