Annotation Type InjectSessionCredentials
@Target({TYPE,METHOD,FIELD,PARAMETER})
@Retention(RUNTIME)
@Tag("AWSSessionCredentials")
public @interface InjectSessionCredentials
Annotation that can used on method or constructor parameters to inject AWS
named profiles to be used for testing purposes. This ensures that we make
actual AWS service API calls and tests whether the resource handlers work as
designed. Here is the code on how to use
InjectProfileCredentials and
InjectSessionCredentials with a junit5 test framework.
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) // we order the tests to follow C to U to D
@ExtendWith(InjectProfileCredentials.class)
@EnabledIfSystemProperty(named = "desktop", matches = "true")
@TestInstance(TestInstance.Lifecycle.PER_CLASS) // IMP PER_CLASS
public class LifecycleTest extends AbstractTestBase {
public LifecycleTest(@InjectSessionCredentials(profile = "cfn-logs-integration") AWSCredentials credentials) {
super(credentials);
}
To make the tests run only on our desktop/laptop use system properties to
control how you run these test as they rely on local box credentials. For our regular
pipelines we don't run these tests as the system properties are not enabled.
For Named Profiles see https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html
we recommend using roles for session credentials which mimic the way you integrate with CFN
~/.aws/credentials
[user]
aws_access_key_id=[YOUR_ACCESS_KEY]
aws_secret_access_key=[YOUR_SECRET_KEY]
~/.aws/config
[profile kinesis]
role_arn = arn:aws:iam::123456789012:role/kinesis
source_profile = user
region = us-west-2