Amazonas is a Kotlin library aiming to make interaction with the Amazon Web Services API as simple as possible. It was mainly developed to be used in Gradle build scripts but it can be used in any other JVM language project.
You should include the following dependency into your build.gradle.kts file:
buildscript {
val amazonasVersion by extra { "0.0.5-SNAPSHOT" }
repositories {
mavenLocal()
}
dependencies {
classpath("cloud.rio:amazonas:$amazonasVersion")
}
}
NOTE: The library is not, yet available on any public repository. Therefore you have to build and publish it to your own maven repository in order to use it.
This is an example of how you could use the MfaCredentialsProvider:
val awsCredentialsProvider: AWSCredentialsProvider by lazy {
if (System.getProperty("profile") != null) {
MfaCredentialsProvider(System.getProperty("profile"))
} else {
DefaultAWSCredentialsProviderChain()
}
}
This will initialize a MfaCredentialsProvider if you call gradle with the JVM property "profile"
set to your aws profile's name. (e.g. ./gradlew -Dprofile=[Name of the Profile to be used] [Your Task Name]
).
If you don't set the profile property the DefaultAWSCredentialsProviderChain will be used (e.g. on an EC2 instance).
Your ~/.aws/credentials file should look like this:
[default]
aws_access_key_id = <Your access key ID>
aws_secret_access_key = <Your secret access Key>
[<Name of the Profile to be used>]
role_arn = <The ARN of the role that you want to assume>
source_profile = default
mfa_serial = <The ARN of your MFA device>
Please make sure everything is in the credentials file, as the usage of the config file is not supported by this library!
Amazonas is licensed under the Apache 2.0 license.