AwsCredentials constructor

AwsCredentials({
  1. String? awsAccessKeyId,
  2. String? awsSecretAccessKey,
  3. String? awsSessionToken,
  4. Map<String, String>? environment,
  5. Map<String, String>? containerCredentials,
})

Implementation

AwsCredentials(
    {this.awsAccessKeyId,
    this.awsSecretAccessKey,
    this.awsSessionToken,
    this.environment,
    this.containerCredentials}) {

  final env = environment ?? Platform.environment;
  environment ??= Platform.environment;
  awsAccessKeyId = awsAccessKeyId ?? env['AWS_ACCESS_KEY_ID'];
  awsSecretAccessKey = awsSecretAccessKey ?? env['AWS_SECRET_ACCESS_KEY'];

  var isInContainer = env['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'];

  if ((isInContainer != null || containerCredentials != null) &&
      (awsAccessKeyId == null && awsSecretAccessKey == null)) {
    var data = containerCredentials ?? waitFor(getContainerCredentials(env));
    if (data != null) {
      awsAccessKeyId = data['AccessKeyId'];
      awsSecretAccessKey = data['SecretAccessKey'];
      awsSessionToken = data['Token'];
    }
  }

  if (awsAccessKeyId == null || awsSecretAccessKey == null) {
    throw ArgumentError(
        'You must provide a valid Access Key and Secret for AWS.');
  }
}