miasma-rb / miasma-aws

Miasma AWS API
Other
8 stars 8 forks source link

Don't know miasma well, want to find account number #62

Open webframp opened 5 years ago

webframp commented 5 years ago

Hi 👋

I still don't know this library well so it's mostly magic used by sfn, which is pretty reliable. Thanks!

I want to remove the aws sdk dependency in a registry item I have that does an account number lookup. Is this supported? What do you recommend?

Registry item code:

require 'aws-sdk-core'
iam = ::Aws::IAM::Client.new
sts = ::Aws::STS::Client.new

SfnRegistry.register(:current_account) do
  # Example ARN: arn:aws:iam::3564258112302:user/iam-user-yancy-random-nibbler
  begin
    iam.get_user.user.arn.split(':')[4] # this is terrible
  rescue Aws::IAM::Errors::ValidationError
    sts.get_caller_identity.account
  end
end

Background: we use the account number as an index into another hash of odd account specific settings we keep in code.