v1.1.0 Ability to pass in AwsCredentialsProvider with custom duration for creating token (#4)
Added getToken(AwsCredentials credentials, Region region, Duration expiry) method to generate token with custom duration Moved to builder pattern for creating instance Minor refactoring Backward compatible changes
Co-authored-by: Anand Khinvasara khinvasa@amazon.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
AWS Bedrock Token Generator for Java
The AWS Bedrock Token Generator for Java is a lightweight utility library that generates short-term bearer tokens for AWS Bedrock API authentication. This library simplifies the process of creating secure, time-limited tokens that can be used to authenticate with AWS Bedrock services without exposing long-term credentials.
Installation
Maven
Add the following dependency to your
pom.xml:Gradle
Add the following to your
build.gradle:Quick Start
NOTE - You may specify a custom token duration (e.g., 1 hour, 6 hours), but the actual token lifetime will be: min(specified duration, credentials expiry, 12 hours). Default is set to 12 hours
Usage 1 - Using Default Providers
Usage 2 - Passing in Provider and Region
Usage 3 - creating token using static method by passing Credentials, Region, and Expiry (Optional)
API Reference
BedrockTokenGenerator
Static Method:
getToken(AwsCredentials credentials, Region region, Duration expiry)Generates a bearer token for AWS Bedrock API authentication using static method.
Parameters:
credentials(AwsCredentials): AWS credentials to use for signingregion(Region): AWS region object (e.g., Region.US_WEST_2)expiry(Duration): Token expiration duration (e.g., Duration.ofHours(12))Returns:
String: A bearer token valid for specified duration, prefixed with “bedrock-api-key-“Example:
Builder Pattern:
builder()Creates a BedrockTokenGenerator instance using the builder pattern.
Builder Methods:
region(Region region): Set the AWS regioncredentialsProvider(AwsCredentialsProvider provider): Set credentials providerexpiry(Duration expiry): Set token expiration durationbuild(): Create the BedrockTokenGenerator instanceInstance Method:
getToken(): Generate token using configured settingsExample:
Token Format
The generated tokens follow this format:
bedrock-api-key-identifies the token type&Version=1for future compatibilitySecurity Considerations
Requirements
Examples
Complete Example with Error Handling
Using with Different Credential Providers
Using Builder with Different Configurations
Building from Source
The build will generate:
aws-bedrock-token-generator-1.1.0.jar- Main library with dependenciesaws-bedrock-token-generator-1.1.0-sources.jar- Source codeaws-bedrock-token-generator-1.1.0-javadoc.jar- API documentationContributing
We welcome contributions! Please see CONTRIBUTING.md for details on how to contribute to this project.
Development Setup
git clone https://github.com/aws/aws-bedrock-token-generator-java.gitmvn clean compilemvn test5. Package:mvn packageSupport
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Related Projects
Changelog
See CHANGELOG.md for a list of changes and version history.