Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The official AWS SDK for Ruby.

License

NotificationsYou must be signed in to change notification settings

zencoder/aws-sdk-ruby

 
 

Repository files navigation

![Gitter](https://badges.gitter.im/Join Chat.svg)Build StatusCode ClimateCoverage Status

This is version 2 of theaws-sdk gem.Version 1 can be found in theaws-sdk-v1 branch.

Links of Interest

NameError: uninitialized constant AWS

If you receive this error, you likely have upgraded to version 2 of theaws-sdk gem unintentionally. Version 2 uses theAws namespace, notAWS.This allows version 1 and version 2 to be used in the same application.

Seethis blog post for more information.

Installation

The AWS SDK for Ruby is available as theaws-sdk gem from RubyGems. Pleaseuse a major version when expressing a dependency onaws-sdk.

gem'aws-sdk','~> 2'

Configuration

You need to configure:credentials and a:region to make API calls. It is recommended that you provide these via your environment. This makes it easier to rotate credentials and it keeps your secrets out of source control.

The SDK searches the following locations for credentials:

  • ENV['AWS_ACCESS_KEY_ID'] andENV['AWS_SECRET_ACCESS_KEY']
  • The shared credentials ini file at~/.aws/credentials (more information)
  • From an instance profile when running on EC2

The SDK searches the following locations for a region:

  • ENV['AWS_REGION']

Configuration Options

You can configure default credentials and region viaAws.config.In version 2,Aws.config is a vanilla Ruby hash, not a method like it was in version 1.

Aws.config.update({region:'us-west-2',credentials:Aws::Credentials.new('akid','secret'),})

Valid region and credentials options are:

You may also pass configuration options directly to resource and client constructors. These options take precedence over the environment andAws.config defaults.

# resource constructorsec2=Aws::EC2::Resource.new(region:'us-west-2',credentials:credentials)# client constructorsec2=Aws::EC2::Client.new(region:'us-west-2',credentials:credentials)

Please take care tonever commit credentials to source control. We strongly recommended loading credentials from an external source.

require'json'creds=JSON.load(File.read('secrets.json'))Aws.config[:credentials]=Aws::Credentials.new(creds['AccessKeyId'],creds['SecretAccessKey'])

API Clients (aws-sdk-core gem)

Construct a service client to make API calls. Each client provides a 1-to-1mapping of methods to API operations. Refer to theAPI documentationfor a complete list of available methods.

# list buckets in Amazon S3s3=Aws::S3::Client.newresp=s3.list_bucketsresp.buckets.map(&:name)#=> ["bucket-1", "bucket-2", ...]

API methods accept a hash of additional request parameters and returnstructured response data.

# list the first two objects in a bucketresp=s3.list_objects(bucket:'aws-sdk-core',max_keys:2)resp.contents.eachdo |object|puts"#{object.key} =>#{object.etag}"end

Paging Responses

Many AWS operations limit the number of results returned with each response.To make it easy to get the next page of results, every AWS response objectis enumerable:

# yields one response object per API call made, this will enumerate# EVERY object in the named buckets3.list_objects(bucket:'aws-sdk').eachdo |response|putsresponse.contents.map(&:key)end

If you prefer to control paging yourself, response objects have helper methodsthat control paging:

# make a request that returns a truncated responseresp=s3.list_objects(bucket:'aws-sdk')resp.last_page?#=> falseresp.next_page?#=> trueresp=resp.next_page# send a request for the next response pageresp=resp.next_pageuntilresp.last_page?

Waiters

Waiters are a utility methods that poll for a particular state. To invoke awaiter, call#wait_until on a client:

beginec2.wait_until(:instance_running,instance_ids:['i-12345678'])puts"instance running"rescueAws::Waiters::Errors::WaiterFailed=>errorputs"failed waiting for instance running:#{error.message}"end

Waiters have sensible default polling intervals and maximum attempts. You canconfigure these per call to#wait_until. You can also register callbacksthat are triggered before each polling attempt and before waiting.See the API documentation for more examples and for a list of supportedwaiters per service.

Resource Interfaces (aws-sdk-resources gem)

Resource interfaces are object oriented classes that represent actualresources in AWS. Resource interfaces built on top of API clients and provideadditional functionality.

s3=Aws::S3::Resource.new# reference an existing bucket by namebucket=s3.bucket('aws-sdk')# enumerate every object in a bucketbucket.objects.eachdo |obj|puts"#{obj.key} =>#{obj.etag}"end# batch operations, delete objects in batches of 1kbucket.objects(prefix:'/tmp-files/').delete# single object operationsobj=bucket.object('hello')obj.put(body:'Hello World!')obj.etagobj.delete

REPL - AWS Interactive Console

Theaws-sdk-core gem ships with a REPL that provides a simple way to testthe Ruby SDK. You can access the REPL by runningaws.rb from the command line.

$aws.rbAws>ec2.describe_instances.reservations.first.instances.first[Aws::EC2::Client2000.2166150retries]describe_instances()<structinstance_id="i-1234567",image_id="ami-7654321",state=<structcode=16,name="running">, ...>

You can enable HTTP wire logging by setting the verbose flag:

$ aws.rb -v

In the REPL, every service class has a helper that returns a new client object.Simply downcase the service module name for the helper:

  • Aws::S3 =>s3
  • Aws::EC2 =>ec2
  • etc

Versioning

This project usessemantic versioning. You can safelyexpress a dependency on a major version and expect all minor and patch versionsto be backwards compatible.

Supported Services

Service NameService ClassAPI Version
AWS CloudFormationCloudFormation2010-05-15
AWS CloudTrailCloudTrail2013-11-01
AWS CodeDeployCodeDeploy2014-10-06
AWS ConfigConfigService2014-11-12
AWS Data PipelineDataPipeline2012-10-29
AWS Direct ConnectDirectConnect2012-10-25
AWS Directory ServiceDirectoryService2015-04-16
AWS Elastic BeanstalkElasticBeanstalk2010-12-01
AWS Identity and Access ManagementIAM2010-05-08
AWS Import/ExportImportExport2010-06-01
AWS Key Management ServiceKMS2014-11-01
AWS LambdaLambda2015-03-31
AWS LambdaLambdaPreview2014-11-11
AWS OpsWorksOpsWorks2013-02-18
AWS Security Token ServiceSTS2011-06-15
AWS Storage GatewayStorageGateway2013-06-30
AWS SupportSupport2013-04-15
Amazon CloudFrontCloudFront2014-11-06
Amazon CloudHSMCloudHSM2014-05-30
Amazon CloudSearchCloudSearch2013-01-01
Amazon CloudSearch DomainCloudSearchDomain2013-01-01
Amazon CloudWatchCloudWatch2010-08-01
Amazon CloudWatch LogsCloudWatchLogs2014-03-28
Amazon Cognito IdentityCognitoIdentity2014-06-30
Amazon Cognito SyncCognitoSync2014-06-30
Amazon DynamoDBDynamoDB2012-08-10
Amazon EC2 Container ServiceECS2014-11-13
Amazon ElastiCacheElastiCache2015-02-02
Amazon Elastic Compute CloudEC22015-04-15
Amazon Elastic File SystemEFS2015-02-01
Amazon Elastic MapReduceEMR2009-03-31
Amazon Elastic TranscoderElasticTranscoder2012-09-25
Amazon GlacierGlacier2012-06-01
Amazon KinesisKinesis2013-12-02
Amazon Machine LearningMachineLearning2014-12-12
Amazon RedshiftRedshift2012-12-01
Amazon Relational Database ServiceRDS2014-10-31
Amazon Route 53Route532013-04-01
Amazon Route 53 DomainsRoute53Domains2014-05-15
Amazon Simple Email ServiceSES2010-12-01
Amazon Simple Notification ServiceSNS2010-03-31
Amazon Simple Queue ServiceSQS2012-11-05
Amazon Simple Storage ServiceS32006-03-01
Amazon Simple Systems Management ServiceSSM2014-11-06
Amazon Simple Workflow ServiceSWF2012-01-25
Amazon SimpleDBSimpleDB2009-04-15
Amazon WorkSpacesWorkSpaces2015-04-08
Auto ScalingAutoScaling2011-01-01
Elastic Load BalancingElasticLoadBalancing2012-06-01

License

This library is distributed under theApache License, version 2.0

copyright 2013. amazon web services, inc. all rights reserved.licensed under the apache license, version 2.0 (the "license");you may not use this file except in compliance with the license.you may obtain a copy of the license at    http://www.apache.org/licenses/license-2.0unless required by applicable law or agreed to in writing, softwaredistributed under the license is distributed on an "as is" basis,without warranties or conditions of any kind, either express or implied.see the license for the specific language governing permissions andlimitations under the license.

About

The official AWS SDK for Ruby.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby96.5%
  • Gherkin2.9%
  • Other0.6%

[8]ページ先頭

©2009-2025 Movatter.jp