voxxit / s3-static-site

Using Ruby and Capistrano, build and deploy a static website to Amazon S3
MIT License
22 stars 47 forks source link

Use AWS-SDK default mechanism to find credentials #13

Open nprbsg opened 9 years ago

nprbsg commented 9 years ago

AWS-SDK provides robust support for finding credentials in standard places in the process's context, including well-known environment variables and EC2 metadata when IAM instance profiles are in use. Additionally, there are more options that a user may want to specify to the AWS.config() method (e.g. :region), which is possible now by set a hash value for the :aws_connect_options.

Using these features together, it is possible also to explicitly assume an IAM role in a capistrano configuration like this:

AWS.config
sts = AWS::STS.new
assumption = sts.assume_role({
        :role_arn => 'arn:aws:iam::012345678901:role/UpdateSite',
        :role_session_name => 's3-static-site',
        :duration_seconds => 900
})

set :aws_connect_options, assumption[:credentials]

The initial call to AWS.config uses credentials from the environment, and then the gem will uses the credentials that result from the STS AssumeRole call.

nprbsg commented 9 years ago

I've structured the code so that existing configurations that explicitly set :access_key_id and :secret_access_key will still work as expected.

voxxit commented 9 years ago

Thanks for the PR! Can you write some quick specs for this, please? :)

nprbsg commented 9 years ago

Ok? I mean I could I guess, but currently there's no corpus of specs to add to so it'd be a little hard to know what was adequate.