opensite-ai/opensite-skills / aws-sdk-python-usage
aws-sdk-python-usage
UnverifiedAWS SDK for Python (boto3/botocore) development patterns. You MUST use this skill when writing Python code that uses AWS services via boto3 or botocore. This includes creating service clients or resources, configuring sessions and credentials, handling errors with ClientError, using paginators and waiters, S3 file transfers and presigned URLs, DynamoDB table operations, and any boto3/botocore client configuration. Use this skill whenever Python code imports boto3 or botocore, or when the user asks about AWS operations in Python.
| File | Kind | Size |
|---|---|---|
| .aws-skill-metadata | other | 18 B |
| SKILL.md | skill md | 8.0 KB |
| references/configuration.md | markdown | 3.7 KB |
| references/credentials.md | markdown | 3.7 KB |
| references/dynamodb.md | markdown | 8.4 KB |
| references/error-handling.md | markdown | 4.5 KB |
| references/pagination.md | markdown | 3.0 KB |
| references/s3.md | markdown | 5.1 KB |
| references/waiters.md | markdown | 3.3 KB |
references/credentials.md
View on GitHub# Credentials Reference
## Default Credential Chain
boto3 resolves credentials in this order:
1. Explicit `aws_access_key_id`/`aws_secret_access_key` passed to `Session()` or `client()`
2. `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY` / `AWS_SESSION_TOKEN` env vars
3. Assume role (`role_arn` + `source_profile` / `credential_source` in the active profile)
4. Web identity token (EKS IRSA via `AWS_WEB_IDENTITY_TOKEN_FILE` / `AWS_ROLE_ARN`, or `web_identity_token_file` in profile)
5. SSO credentials (IAM Identity Center profile; token from `aws sso login`)
6. `~/.aws/credentials` file (default or named profile)
7. Login session (`login_session` in profile; requires `botocore[crt]`)
8. Credential process (`credential_process` in profile)
9. `~/.aws/config` file (static keys in profile)
10. Legacy boto config (`BOTO_CONFIG`, `~/.boto`, `/etc/boto.cfg`)
11. Container credentials — ECS task role / EKS Pod Identity (`AWS_CONTAINER_CREDENTIALS_RELATIVE_URI` or `AWS_CONTAINER_CREDENTIALS_FULL_URI`)
12. EC2 instance metadata (IMDS)
In most cases, let the default chain handle credential resolution rather than hardcoding credentials.
## Sessions
```python
import boto3
# Default session -- shared across boto3.client()/boto3.resource() calls
client = boto3.client("s3")
# Explicit session -- isolated credentials and config
session = boto3.Session(
profile_name="dev-account",
region_name="us-west-2",
)
client = session.client("s3")
# Multiple sessions for cross-account access
dev = boto3.Session(profile_name="dev")
prod = boto3.Session(profile_name="prod")
dev_s3 = dev.client("s3")
prod_s3 = prod.client("s3")
```
Use explicit sessions when you need multiple credential sets or profiles in the same process.
## Named Profiles
```python
# Use a profile from ~/.aws/credentials or ~/.aws/config
session = boto3.Session(profile_name="my-profile")
client = session.client("s3")
# Or set via environment variable
# AWS_PROFILE=my-profile
```
## Assume Role (STS)
```python
import boto3
# Assume a role and create a client with the temporary credentials
sts = boto3.client("sts")
response = sts.assume_role(
RoleArn="arn:aws:iam::123456789012:role/MyRole",
RoleSessionName="my-session",
DurationSeconds=3600,
)
creds = response["Credentials"]
client = boto3.client(
"s3",
aws_access_key_id=creds["AccessKeyId"],
aws_secret_access_key=creds["SecretAccessKey"],
aws_session_token=creds["SessionToken"],
)
```
For automatic credential refresh when the assumed role expires, use a profile with `role_arn` in `~/.aws/config`:
```ini
[profile cross-account]
role_arn = arn:aws:iam::123456789012:role/MyRole
source_profile = default
```
```python
session = boto3.Session(profile_name="cross-account")
client = session.client("s3") # credentials auto-refresh
```
## Chained Role Assumption
```ini
# ~/.aws/config
[profile role-a]
role_arn = arn:aws:iam::111111111111:role/RoleA
source_profile = default
[profile role-b]
role_arn = arn:aws:iam::222222222222:role/RoleB
source_profile = role-a
```
## Environment Variables
| Variable | Purpose |
|---|---|
| `AWS_ACCESS_KEY_ID` | Access key |
| `AWS_SECRET_ACCESS_KEY` | Secret key |
| `AWS_SESSION_TOKEN` | Session token (temporary creds) |
| `AWS_DEFAULT_REGION` | Default region |
| `AWS_PROFILE` | Named profile |
| `AWS_ROLE_ARN` | Role ARN for web identity |
| `AWS_WEB_IDENTITY_TOKEN_FILE` | Path to OIDC token file (EKS) |
| `AWS_CONFIG_FILE` | Override config file path |
| `AWS_SHARED_CREDENTIALS_FILE` | Override credentials file path |
## STS Get Caller Identity
Useful for verifying which credentials are in use:
```python
sts = boto3.client("sts")
identity = sts.get_caller_identity()
print(identity["Account"], identity["Arn"])
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |