AWS Builder Center
πŸ”‘  Amazon Bedrock API Keys: Simplified Developer Authentication

πŸ”‘ Amazon Bedrock API Keys: Simplified Developer Authentication

Learn how Amazon Bedrock's new API keys simplify authentication with short-term and long-term options. No complex signatures needed - just secure, flexible access.

Developer Advocate/SDE, GenAI
Amazon Bedrock now offers Β two types of API KeysΒ  to simplify programmatic authentication, each designed for different use cases:

🟒 Short-term API Keys (Recommended)

  • Duration: Up to 12 hours or remaining console session time
  • Technology: Pre-signed URLs with AWS Signature Version 4
  • Permissions: Inherit the same permissions as the generating identity
  • Generation: Bedrock console, Python package Β aws-bedrock-token-generatorΒ 
  • Security: Lower risk due to short duration

🟑 Long-term API Keys (For development)

  • Duration: From 1 day up to 365 days (or never expires)
  • Association: Linked to specific IAM users
  • Limit: Maximum 2 keys per IAM user
  • Auto-policy: Β AmazonBedrockLimitedAccessΒ  automatically attached to user
  • Security: Higher risk - requires regular rotation

πŸ› οΈ How to Generate Long-term API Keys

Prerequisites

  1. Existing IAM user
  1. Required IAM permissions:
JSON
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:CreateServiceSpecificCredential",
"iam:ListServiceSpecificCredentials",
"iam:UpdateServiceSpecificCredential",
"iam:DeleteServiceSpecificCredential",
"iam:ResetServiceSpecificCredential"
],
"Resource": "arn:aws:iam::*:user/username"
}
]
}

πŸ–₯️ Method 1: AWS Console

  1. Navigate to IAM Console β†’ Users
  1. Select the IAM user
  1. Security credentials tab
  1. API keys for Amazon Bedrock section β†’ Generate API Key
ο»Ώ
Configure expiration (1, 5, 30, 90, 365 days or custom) - For long-term API key
ο»Ώ
IMPORTANT! Download/copy the key immediately - you cannot retrieve it later
ο»Ώ

⌨️ Method 2: AWS CLI

To generate an Amazon Bedrock long-term API key using the AWS CLI, use Β Generating a long-term API Key for Amazon Bedrock (AWS CLI)stepsΒ .

πŸ’» Code Implementation

🌐 Environment Variable Setup
Β export AWS_BEARER_TOKEN_BEDROCK=your-api-key-hereΒ 
🌐Or use in applications
Β import os api_key = os.getenv('AWS_BEARER_TOKEN_BEDROCK') import requestsΒ 
Configuration
JSON
url = "https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1:0/invoke"
payload = {
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Hello, Bedrock!"
}
]
}
],
"max_tokens": 1000,
"anthropic_version": "bedrock-2023-05-31"
}
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_BEDROCK_API_KEY"
}
response = requests.post(url, json=payload, headers=headers) print(response.json())
Use Amazon Bedrock API Β in your favorite SDKΒ .

🎯 When to Use Each Type?

ο»Ώ

ο»Ώ

πŸ“Š Key Benefits

βœ… Simplified Authentication - No complex signature calculations
βœ… Flexible Duration - Choose expiration that fits your needs
βœ… Enhanced Security - Service-specific credentials limit scope
βœ… Existing IAM Controls - Respects all current permissions
Best,
Eli :)
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