So, adding an enumerable interface to Aws::SharedCredentials would provide you the ability to enumerate profiles, but there is not currently anything analgous to AWS.regions in the v2 SDK.
The v1 SDK maintained a static json document of regions, but the v2 SDK does not ship with this, as it was a maintenance burden.
["eu-central-1", "sa-east-1", "ap-northeast-1", "eu-west-1", "us-east-1", "us-west-1", "us-west-2", "ap-southeast-2", "ap-southeast-1”]
- This currently omit gov cloud and the newer cn-north-1 region (as these require different accounts). In theory, calling this from a gov cloud endpoint would returns different results, as would calling it against a cn-north-1 endpoint would. I would need to know how your credentials are scoped to know what enpdoints they would be valid against. Without some initial config I can not bootstrap that call.
@santana The purpose of supporting a path is to allow the instance profile credentials to be loaded in environments where a/the home directory is not available for the current user, but the file is available on disk.
Wouldn’t the following work?
Aws::InstanceProfileCredentials.new.each_profile do |profile_name, credentials|
# yielded creds are Aws::Credentials
end
Hey everyone. I’m attempting to get a stubbed Aws::AssumeRoleCredentials
instance with the following
aws_sts_client = Aws::STS::Client.new( credentials: credentials,
region: DEFAULT_AWS_REGION)
Aws::AssumeRoleCredentials.new( client: aws_sts_client,
role_arn: profile[:role_arn],
role_session_name: "#{profile[:name]}-session",
duration_seconds: DEFAULT_AWS_TOKEN_DURATION)
credentials
is either an instance of Aws::SharedCredentials
or Aws::Credentials
My issue is I keep seeing this error:
NoMethodError:
undefined method `access_key_id' for nil:NilClass
# /Users/brkattk/.rbenv/versions/2.2.2/gemsets/project-name/gems/aws-sdk-core-2.0.37/lib/aws-sdk-core/assume_role_credentials.rb:39:in `refresh'
# /Users/brkattk/.rbenv/versions/2.2.2/gemsets/project-name/gems/aws-sdk-core-2.0.37/lib/aws-sdk-core/refreshing_credentials.rb:20:in `initialize'
# /Users/brkattk/.rbenv/versions/2.2.2/gemsets/project-name/gems/aws-sdk-core-2.0.37/lib/aws-sdk-core/assume_role_credentials.rb:29:in `initialize'
# ./lib/project-name/configuration/aws_parser.rb:106:in `new'
# ./lib/project-name/configuration/aws_parser.rb:106:in `assume_role_credentials'
# ./lib/project-name/configuration/aws_parser.rb:83:in `build_credentials'
# ./lib/project-name/configuration/aws_parser.rb:63:in `block in validate_profiles'
# ./lib/project-name/configuration/aws_parser.rb:60:in `each'
# ./lib/project-name/configuration/aws_parser.rb:60:in `validate_profiles'
# ./lib/project-name/configuration/aws_parser.rb:49:in `validate!'
# ./lib/project-name/configuration/aws_parser.rb:29:in `parse!'
# ./spec/lib/project-name/configuration/aws_parser_spec.rb:186:in `block (9 levels) in <top (required)>'
# ./spec/lib/project-name/configuration/aws_parser_spec.rb:189:in `block (9 levels) in <top (required)>'
Aws.config[:stub_responses] = true
does not construct the actual responses you need, just simply stops the HTTP call from happening, right?
resp = aws_sts_client.assume_role(
role_arn: profile[:role_arn],
role_session_name: "#{profile[:name]}-session",
duration_seconds: DEFAULT_AWS_TOKEN_DURATION)
resp.context.http_response.status_code
resp.context.http_response.headers
resp.context.http_response.body_contents
I have an app that uses multiple different AWS credentials to do various things and eventually upload a file to S3. I’ve got an array of environments
like so
[
{
:name=>"default”,
:bucket_name=>”my.bucket”,
:bucket_region=>”us-east-1”,
:credentials=>#<Aws::SharedCredentials profile_name="default" path="/Users/brkattk/.aws/credentials”>
},
{
:name=>”secondary",
:bucket_name=>”my.bucket”,
:bucket_region=>”us-east-1”,
:credentials=>#<Aws::SharedCredentials profile_name=“secondary" path="/Users/brkattk/.aws/credentials”>
}
]
I’ve got a Report class that will upload a CSV to an environment’s designated bucket:
class Report
att_reader :csv, :environment
def initialize(environment, csv)
@environment = environment
@csv = csv
end
def upload!
s3_bucket.put_object(
body: csv.to_csv,
key: csv.to_filename,
content_type: 'text/csv')
end
private
def s3_resource
::Aws::S3::Resource.new(client: s3_client)
end
def s3_bucket
s3_resource.bucket environment[:bucket_name]
end
def s3_client
::Aws::S3::Client.new(credentials: environment[:credentials], region: environment[:bucket_region])
end
end
I’m looping each environment and producing a report, however, it is uploading both files to the last environment’s bucket.
Am I going insane?
S3::Object.new(bucket_name, key).put(body:’…’, content_type: ‘…')
Aws::S3::Client
, right?
my.bucket