
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. 5).
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\creden-
tials (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_AC-
CESS_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
permissions, as shown in Using IAM Roles for Amazon EC2 Instances with the AWS SDK for
Ruby (p. 9).
The AWS SDKs and CLIs use a provider chain to look for default AWS credentials, or you can specify
the appropriate credentials explicitly. For more information, see Specifying Credentials (p. 5).
Specifying AWS Credentials for SDK for Ruby
Applications
For an SDK for Ruby application to access Amazon Web Services, you must provide the application with
a set AWS credentials that have appropriate permissions.You specify which credentials your application
Version v1.0.0
5
AWS SDK for Ruby Developer Guide
Specifying Credentials
Kommentare zu diesen Handbüchern