You could implement an AWSCredentialsProvider
, which is an interface for supplying credentials to SDK clients. For example the DefaultAWSCredentialsProviderChain
is an implementation which looks in multiple places for credentials (the environment, a properties file, and EC2 instance profile).
You can check out the implementation of several credentials providers in the AWS SDK for Java Github repo.