AWS Credentials for Amazon S3 Access
Learn how AWS credentials authenticate S3 requests, configure AWS CLI profiles, use IAM roles and temporary credentials, apply least privilege, and troubleshoot access failures.
AWS credentials are information used to authenticate a request to AWS. When you use the AWS CLI, an SDK, or an application to access Amazon S3, AWS must identify the principal: the user, role, or federated session making the request.
Authentication answers “Who is making this request?” Authorization answers “Is that principal allowed to perform this action on this resource?” Valid credentials solve only the authentication part. IAM policies, bucket policies, access point policies, permission boundaries, service control policies, and explicit denies affect authorization.
How credentials control S3 access
An AWS CLI or SDK obtains credentials, creates a request, and signs it using AWS Signature Version 4. The signed request contains information that allows AWS to verify the caller and detect changes to the request.
- The CLI, SDK, or workload searches its credential provider chain.
- The selected credentials sign the S3 request.
- AWS authenticates the request and identifies the principal.
- IAM and S3 resource policies evaluate whether the principal may perform the requested action.
- S3 returns the result or an error such as
AccessDenied.
A request can therefore fail even when credentials are present. For example, a principal may be authenticated but lack s3:PutObject permission for the destination object, or a bucket policy may contain an explicit deny.
AWS identity and credential types
An AWS credential method determines how an identity obtains permission to call AWS APIs. Long-lived access keys are convenient for some local cases but increase the risk of exposure. Temporary credentials are preferred because they expire.
Credential components
- Access key ID: A public identifier associated with an access key. It is not sufficient by itself to authenticate a request.
- Secret access key: A private value used to sign requests. Treat it like a password; AWS generally cannot show the original secret again after creation.
- Session token: An additional value required with temporary credentials. The access key ID, secret access key, and session token must come from the same session.
- Region: The AWS geographic region used by the client. It is configuration rather than a credential, but an incorrect region can cause endpoint or signature errors.
- Expiration: Temporary credentials work only until their session expiration time. Supported SSO, role, and workload providers can refresh them automatically.
Creating least-privilege S3 access
Least privilege means granting only the permissions needed for a defined task. Avoid solving an S3 error by granting broad administrator permissions.
S3 permissions apply to different resource types. Bucket-level actions commonly use a bucket ARN, while object-level actions use object ARNs that include a key or prefix.
This policy grants only upload permission to one prefix:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::example-bucket/uploads/*"
}
]
}The policy does not grant listing, reading, or deletion. Actual requirements can also depend on encryption, KMS permissions, bucket ownership settings, access points, and organizational controls.
Installing and configuring the AWS CLI
Install the AWS CLI using your organization's approved installation method, then verify that it is available:
aws --versionConfigure a default access-key-based profile with:
aws configureThe prompts normally request an access key ID, secret access key, default region, and output format. For example, the region might be us-east-1 and the output format might be json. Do not paste real secrets into scripts or examples.
For a separate environment, create a named profile:
aws configure --profile developmentSelect it explicitly for a command:
aws sts get-caller-identity --profile development
aws s3 ls --profile developmentYou can select a profile for the current shell:
export AWS_PROFILE=developmentOn Windows PowerShell, use $env:AWS_PROFILE = "development". Check the selected profile carefully because an environment variable can cause commands to use a different identity than expected.
Shared credentials and configuration files
The shared credentials file stores access-key-based profiles. The AWS config file stores settings such as regions, output formats, role profiles, and SSO configuration.
- Linux and macOS normally use
~/.aws/credentialsand~/.aws/config. - Windows normally uses
%USERPROFILE%\.aws\credentialsand%USERPROFILE%\.aws\config. AWS_SHARED_CREDENTIALS_FILEandAWS_CONFIG_FILEcan point to alternate locations.- The default profile is written as
[default]in the credentials file and commonly as[default]in the config file. - Named profiles use a name such as
[development]in the credentials file and[profile development]in the config file.
Protect these files with operating-system permissions. On a Unix-like system, a local access-key file should normally be readable only by its owner:
chmod 600 ~/.aws/credentials
chmod 600 ~/.aws/configDo not commit either file to version control. Add credential files to .gitignore and use secret scanning in repositories and CI systems.
Role profiles
A role profile uses one profile as the source identity and obtains temporary credentials for another role:
[profile production-readonly]
role_arn = arn:aws:iam::123456789012:role/ProductionReadOnly
source_profile = development
region = us-east-1The source identity must be allowed by the role's trust policy to call sts:AssumeRole. The role's permissions policy then controls what it can do in the target account.
SSO profiles
Create an AWS IAM Identity Center profile with:
aws configure sso --profile workforce
aws sso login --profile workforce
aws sts get-caller-identity --profile workforceThe prompts and organization-specific sign-in settings depend on the Identity Center configuration. The resulting profile uses a temporary session rather than a permanent IAM user secret.
Credential provider precedence
The credential provider chain is the ordered set of locations that the CLI or SDK checks for credentials. Exact details vary by SDK and operation, but explicit settings and environment configuration commonly take precedence over local files and workload metadata.
SDKs use a similar provider-chain concept. Avoid ambiguity by using one deliberate method per execution environment, checking the active identity, and removing obsolete environment variables.
Using credentials with S3 operations
These commands use a fictional bucket and a named profile:
aws sts get-caller-identity --profile development
aws s3 ls --profile development
aws s3 ls s3://example-bucket/ --profile development
aws s3 cp ./report.csv s3://example-bucket/uploads/report.csv --profile development
aws s3 cp s3://example-bucket/uploads/report.csv ./report.csv --profile development
aws s3 cp s3://example-bucket/uploads/report.csv s3://example-bucket/archive/report.csv --profile developmentaws s3 ls may require permission to list buckets or may fail even though access to a particular bucket is allowed. Object upload requires permission for the destination object, commonly s3:PutObject. The signed request identifies the caller; S3 does not infer permission from the local filename or profile name.
Temporary credentials and role assumption
STS, the AWS Security Token Service, issues temporary credentials. AssumeRole is an STS operation that lets a trusted principal obtain credentials for an IAM role.
Temporary credentials reduce the impact of exposure because they expire. A role requires both:
- A trust policy stating which principals may assume it.
- A permissions policy stating which AWS actions the role may perform.
Role sessions have a configured duration and expiration. SSO tools, role profiles, EC2 instance profiles, ECS task roles, Lambda execution roles, and supported SDK providers can refresh credentials automatically. A cross-account workflow typically signs in to an identity in one account, assumes a role trusted by the target account, and uses the resulting session to access the target S3 resource. The target bucket policy may also need to allow the role or its account.
Workload identity
Applications running on AWS should normally use workload identity rather than embedded access keys:
- Attach an IAM role to an EC2 instance through an instance profile.
- Assign an IAM task role to an ECS task.
- Assign an execution role to a Lambda function.
- Use web identity federation for supported Kubernetes or other federated workloads.
The AWS SDK obtains temporary credentials from the environment's provider and refreshes them when supported. The application should not read or write permanent credentials on disk.
Credential security practices
- Use IAM roles, Identity Center, or an approved external secret-management system instead of static keys where possible.
- Never embed credentials in source code, browser code, images, documentation, container images, or committed configuration.
- Use
.gitignore, pre-commit checks, repository secret scanning, and CI secret detection. - Rotate long-lived access keys and deactivate or delete keys that are no longer needed.
- If a secret may have been exposed, stop using it, deactivate or replace it immediately, investigate usage, and remove it from repositories and logs.
- Require MFA for appropriate human access and use organizational controls for sensitive operations.
- Review IAM credential reports and monitor API activity with CloudTrail.
Troubleshooting S3 credential failures
First separate credential discovery problems from authorization problems. Run:
aws configure list
aws sts get-caller-identity
aws sts get-caller-identity --profile developmentResolving AccessDenied on upload
- Run
aws sts get-caller-identitywith the same profile used for the upload. - Confirm that the role or user has
s3:PutObjecton the exact destination ARN, including the prefix. - Check whether encryption requires additional KMS permissions.
- Review the bucket policy and access point policy for conditions or explicit denies.
- Check permission boundaries, organization service control policies, VPC endpoint policies, and identity or network conditions.
- Do not grant administrator access merely to make the error disappear.
Exam-relevant notes
- Authentication identifies the principal; authorization evaluates permissions.
- An access key ID is not secret, but the secret access key is private.
- Temporary credentials require a session token.
- IAM roles normally provide temporary credentials and are preferred for AWS workloads.
s3:ListBucketapplies to a bucket resource;s3:GetObject,s3:PutObject, ands3:DeleteObjectapply to object resources.- An explicit deny overrides an allow.
- Always verify the active principal with
aws sts get-caller-identitybefore diagnosing an S3 permission problem. - Credential provider precedence can cause a valid but unintended identity to be used.
For a shorter reference, see AWS credentials quick reference.