
Setting up AWS Credentials for Use with the
SDK for Ruby
Note
This documentation is for the AWS SDK for Ruby version 1, which is a legacy version. For the
most recent version of the SDK for Ruby, see AWS SDK for Ruby - Version 2.
To use the SDK for Ruby to access AWS resources, you must provide a set of AWS credentials, which
consist of an access key ID and a secret access key. We recommend that you do not use your account's
root credentials to access AWS. Instead, create one or more IAM users and provide those credentials to
the SDK for Ruby. In addition to providing a better way to manage credentials, each IAM user has one
or more attached policies that specify which resources the user can access, and which actions they can
perform on those resources. For more information, see Best Practices for Managing AWS Access Keys.
The recommended approach for managing credentials is to store them in one of the following ways and
then load them into your application.This avoids putting explicit keys in your code, where they might be
inadvertently exposed. For more information on how to load credentials, see Specifying Credentials (p. 6).
Credentials file
Create one or more profiles in your local system's AWS credentials file, which is located at
~/.aws/credentials (Linux, Unix, and OS X systems) or
C:\Users\User_Name\.aws\credentials (Windows systems). Each profile consists of a name
and a set of credentials in the following format:
[profile_name]
aws_access_key_id = access_key_id
aws_secret_access_key = secret_access_key
Substitute a set of IAM credentials for the access_key_id and secret_access_key.You can
use any name you prefer for the profile name except for the default profile, which must be named
default. For example, if you have multiple IAM users with different policies, you can create a profile
for each user, named with the user name.You can specify the appropriate profile by name for each
application.
Environment variables
Specify default credentials by assigning an access key ID and a secret access key to the
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.
For Linux, OS X, or Unix systems, use export:
export AWS_ACCESS_KEY_ID=access_key_id
export AWS_SECRET_ACCESS_KEY=secret_access_key
For Windows, use set:
set AWS_ACCESS_KEY_ID=access_key_id
set AWS_SECRET_ACCESS_KEY=secret_access_key
IAM role
For applications running on an EC2 instance, the recommended approach is to create an IAM role
with appropriate permissions and assign it to the instance.The application will then run with those
Version v1.0.0
5
AWS SDK for Ruby Developer Guide
Setting up AWS Credentials
Kommentare zu diesen Handbüchern