Tag: SDK


Release: AWS SDK for PHP – Version 2.4.8

by Michael Dowling | on | in PHP | Permalink | Comments |  Share

We would like to announce the release of version 2.4.8 of the AWS SDK for PHP. This release updates the AWS Direct Connect client and updates the Amazon Elastic MapReduce client to add support for new EMR APIs, termination of specific cluster instances, and unlimited EMR steps.

Changelog

  • Updated the AWS Direct Connect client
  • Updated the Amazon Elastic MapReduce client to add support for new EMR APIs, termination of specific cluster instances, and unlimited EMR steps.

Install/Download the Latest SDK

Sending requests through a proxy

by Michael Dowling | on | in PHP | Permalink | Comments |  Share

Some network configurations require that outbound connections be sent through a proxy server. Requiring a proxy for outbound HTTP requests is a common practice in many companies, and is often something that must be configured in a client.

You can send requests with the AWS SDK for PHP through a proxy using the "request options" of a client. These "request options" are applied to each HTTP request sent from the client. One of the option settings that can be specified is the proxy option. This setting controls how the SDK utilizes a proxy.

Request options are passed to a client through the client’s factory method. Here’s an example of how you can specify a proxy for an Amazon S3 client:

use AwsS3S3Client;

$s3 = S3Client::factory(array(
    'request.options' => array(
        'proxy' => '127.0.0.1:123'
    )
));

The above example tells the client that all requests should be proxied through an HTTP proxy located at the 127.0.0.1 IP address using port 123.

Username and password

You can supply a username and password when specifying your proxy setting if needed:

$s3 = S3Client::factory(array(
    'request.options' => array(
        'proxy' => 'username:password@127.0.0.1:123'
    )
));

Proxy protocols

Because proxy support is handled through cURL, you can specify various protocols when specifying the proxy (e.g., socks5://127.0.0.1). More information on the proxy protocols supported by cURL can be found in the online cURL documentation.

Wire Logging in the AWS SDK for PHP

by Jeremy Lindblom | on | in PHP | Permalink | Comments |  Share

One of the features of the AWS SDK for PHP that I often recommend to customers is the LogPlugin, that can be used to do wire logging. It is one of the many plugins included with Guzzle, which is the underlying HTTP library used by the SDK. Guzzle’s LogPlugin includes a default configuration that will output the content of the requests and responses sent over the wire to AWS. You can use it to help debug requests or just learn more about how the AWS APIs work.

Adding the LogPlugin to any client in the SDK is simple. The following shows how to set it up.

$logPlugin = GuzzlePluginLogLogPlugin::getDebugPlugin();
$client->addSubscriber($logPlugin);

The output generated by LogPlugin for a single request looks similar to the following text (this request was for executing an Amazon S3 ListBuckets operation).

# Request:
GET / HTTP/1.1
Host: s3.amazonaws.com
User-Agent: aws-sdk-php2/2.4.6 Guzzle/3.7.3 curl/7.25.0 PHP/5.3.27
Date: Fri, 27 Sep 2013 15:53:10 +0000
Authorization: AWS AKIAEXAMPLEEXAMPLE:eEXAMPLEEsREXAMPLEWEFo=

# Response:
HTTP/1.1 200 OK
x-amz-id-2: EXAMPLE4j/v8onDxyeuFaQFsNvN66EXAMPLE30KQLfq0T6sVcLxj
x-amz-request-id: 4F3EXAMPLEE14
Date: Fri, 27 Sep 2013 15:53:09 GMT
Content-Type: application/xml
Transfer-Encoding: chunked
Server: AmazonS3

<?xml version="1.0" encoding="UTF-8"?>
<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">[...]</ListAllMyBucketsResult>

This is the output generated using the default configuration. You can configure the LogPlugin to customize the behavior, format, and location of what is logged. It’s also possible to integrate with third-party logging libraries like Monolog. For more information, see the section about the wire logger in the AWS SDK for PHP User Guide.

AWS at Web & PHP Con 2013

by Jeremy Lindblom | on | in PHP | Permalink | Comments |  Share

In September, I was able to attend and speak at Web & PHP Con in San
Jose, CA. It was great to be around a good group of PHP developers, talk about web development and AWS, and meet new
friends.

Getting Good with the AWS SDK for PHP

On Wednesday, September 17th, I gave a talk called Getting Good with the AWS SDK for PHP. In my session, I gave a
brief introduction to AWS and its services, taught how to use the AWS SDK for PHP, and walked through some code examples
from a small PHP application built with the SDK using Amazon S3, Amazon DynamoDB, and AWS Elastic Beanstalk. Here is the
slide deck,
joind.in page, and Lanyrd page for the
talk.

Git Educated About Git

On September 18th, I gave a talk called Git Educated About Git – 20 Essential Commands
(slide deck). This talk was not
related to AWS or the AWS SDK for PHP, but I used the development of the SDK as a use case during the presentation.
Since we work on a combination of both publicly available and unannounced features, we don’t have a single canonical
repository. Instead we have two remotes, our public GitHub repository and another private, internal repository. For fun,
I also wrote and performed a song called You’re Doing Git! during my session, and you can watch the performance on
YouTube
.

Attending PHP Conferences

I’ve enjoyed my opportunities to attend various PHP and developer conferences and user group meetings throughout this
year. I’ve found it to be a great opportunity to connect to PHP developers and help them learn more about developing on
AWS and with the AWS SDK for PHP. I hope to see you at future conferences.

Release: AWS SDK for PHP 2.4.4

by Jeremy Lindblom | on | in PHP | Permalink | Comments |  Share

We would like to announce the release of version 2.4.4 of the
AWS SDK for PHP. This release updates the Amazon EC2 client to use the
2013-07-15 API version and fixes issues reported on the forums and GitHub.

Changelog

  • Added support for assigning a public IP address to a VPC instance at launch to the Amazon EC2 client
  • Updated the Amazon EC2 client to use the 2013-07-15 API version
  • Updated the Amazon SWF client to sign requests with Signature V4
  • Updated the Instance Metadata client to allow for higher and more customizable connection timeouts
  • Fixed an issue with the SDK where XML map structures were not being serialized correctly in some cases
  • Fixed issue #136 where a few of the new Amazon SNS mobile push operations were not working properly
  • Fixed an issue where the AWS STS AssumeRoleWithWebIdentity operation was requiring credentials and a signature
    unnecessarily
  • Fixed and issue with the S3Client::uploadDirectory method so that true key prefixes can be used
  • Updated the API docs to include sample code for each operation that indicates the parameter structure
  • Updated the API docs to include more information in the descriptions of operations and parameters
  • Added a page about Iterators to the user guide

Install/Download the Latest SDK

Release: AWS SDK for PHP 2.4.3

by Michael Dowling | on | in PHP | Permalink | Comments |  Share

We would like to announce the release of version 2.4.3 of the AWS SDK for PHP. This release adds support for the Amazon Simple Notification Service mobile push API, adds progress reporting on snapshot restore operations for Amazon Redshift, and addresses an issue with directories and the Amazon S3 stream wrapper.

Changelog

  • Updated the Amazon SNS client API to support mobile push
  • Updated the Amazon Redshift client API to support progress reporting on snapshot restore operations
  • Updated the Amazon Elastic MapReduce client to now use JSON serialization and AWS Signature V4 to securely sign requests
  • AWS SDK for PHP clients now throw AwsCommonExceptionTransferException exceptions when a network error occurs instead of a GuzzleHttpExceptionCurlException. The TransferException class, however, extends from GuzzleHttpExceptionCurlException. You can continue to catch the Guzzle CurlException or catch AwsCommonExceptionAwsException to catch any exception that can be thrown by an AWS client.
  • Fixed an issue with the Amazon S3 stream wrapper where trailing slashes were being added when listing directories

Install/Download the Latest SDK

Release: AWS SDK for PHP 2.4.2

by Jeremy Lindblom | on | in PHP | Permalink | Comments |  Share

We would like to announce the release of version 2.4.2 of the AWS SDK for PHP. This release adds support for custom Amazon Machine Images (AMIs) and Chef 11 to the AWS OpsWorks client, adds the latest snapshot permission features to the Amazon Redshift client, and updates the Amazon EC2 and AWS Security Token Service clients.

Changelog

  • Added support for cross-account snapshot access control to the Amazon Redshift client
  • Added support for decoding authorization messages to the AWS STS client
  • Added support for checking for required permissions via the DryRun parameter to the Amazon EC2 client
  • Added support for custom Amazon Machine Images (AMIs) and Chef 11 to the AWS OpsWorks client
  • Added an SDK compatibility test to allow users to quickly determine if their system meets the requirements of the SDK
  • Updated the Amazon EC2 client to use the 2013-06-15 API version
  • Fixed an unmarshalling error with the Amazon EC2 CreateKeyPair operation
  • Fixed an unmarshalling error with the Amazon S3 ListMultipartUploads operation
  • Fixed an issue with the Amazon S3 stream wrapper "x" fopen mode
  • Fixed an issue with AwsS3S3Client::downloadBucket by removing leading slashes from the passed $keyPrefix argument

Install/Download the Latest SDK

Release: AWS SDK for PHP 2.4.1

by Michael Dowling | on | in PHP | Permalink | Comments |  Share

We would like to announce the release of version 2.4.1 of the AWS SDK for PHP. This release adds support for setting watermark and max frame rate parameters in the Amazon Elastic Transcoder client and resolves issues with the Amazon S3, Amazon EC2, Amazon ElastiCache, AWS Elastic Beanstalk, Amazon EMR, and Amazon RDS clients.

Changelog

  • Added support for setting watermarks and max frame rates to the Amazon Elastic Transcoder client
  • Added MD5 validation to Amazon SQS ReceiveMessage operations
  • Added the AwsDynamoDbIteratorItemIterator class to make it easier to get items from the results of DynamoDB operations in a simpler form
  • Added support for the cr1.8xlarge EC2 instance type. Use AwsEc2EnumInstanceType::CR1_8XLARGE
  • Added support for the suppression list SES mailbox simulator. Use AwsSesEnumMailboxSimulator::SUPPRESSION_LIST
  • Fixed an issue with data formats throughout the SDK due to a regression. Dates are now sent over the wire with the correct format. This issue affected the Amazon EC2, Amazon ElastiCache, AWS Elastic Beanstalk, Amazon EMR, and Amazon RDS clients
  • Fixed an issue with the parameter serialization of the ImportInstance operation in the Amazon EC2 client
  • Fixed an issue with the Amazon S3 client where the RoutingRules.Redirect.HostName parameter of the PutBucketWebsite operation was erroneously marked as required
  • Fixed an issue with the Amazon S3 client where the DeleteObject operation was missing parameters
  • Fixed an issue with the Amazon S3 client where the Status parameter of the PutBucketVersioning operation did not properly support the "Suspended" value
  • Fixed an issue with the Amazon Glacier UploadPartGenerator class so that an exception is thrown if the provided body to upload is less than 1 byte

Install/Download the SDK

You can get the latest version of the SDK via:

New Blog for the AWS SDK for PHP

by Jeremy Lindblom | on | in PHP | Permalink | Comments |  Share

Hello fellow PHP developers!

Welcome to our new blog for the AWS SDK for PHP. I’m Jeremy Lindblom, and I work with Michael Dowling on the AWS SDK for PHP here at Amazon Web Services. We will be working together on this blog to bring you articles and tips about the PHP SDK and post related announcements. As passionate PHP developers, Michael and I hope you enjoy using the SDK and will find the posts on this blog helpful for your PHP projects using AWS.

Let me also quickly point you to some links for our SDK and documentation:

We hope you subscribe to our blog using the RSS feed button at the top of the page and come back often. If you would like us to blog about any specific topics, please let us know and we’ll see what we can do.

Threading with the AWS SDK for Ruby

by Loren Segal | on | in Ruby | Permalink | Comments |  Share

When using threads in an application, it’s important to keep thread-safety in mind. This statement is not specific to the Ruby world; it’s a reality in any language that supports threading. What is specific to Ruby is the fact that many libraries in our language are loaded at run-time, and often, loading code at run-time is not a thread-safe operation.

Autoload and Thread-Safety

Many libraries and frameworks (including Ruby on Rails) use a feature of Ruby known as autoload, which allows components of a library to be lazily loaded only when the constant is resolved in the code path of an executing program. The problem with this feature is that, historically, the implementation has not been thread-safe. In other words, if two threads tried to resolve an autoloaded constant at the same time, weird things would happen. This problem was finally tackled in Ruby 1.9.1 but then regressed in 1.9.2 and re-resolved in 1.9.3 (but only in a later patchlevel), causing a bit of confusion around whether autoload is actually safe to use in a threaded Ruby program.

Thread-Safe in 2.0

For all intents and purposes, autoloading of modules should be considered thread-safe in Ruby 2.0.0p0, as the patch was officially merged into the 2.0 branch prior to release. Any thread-safety issues in Ruby 2.0 should be considered regressions, according to that ticket.

Enter Eager Loading

Of course, guaranteeing support for Ruby 2.0 is not entirely sufficient for most programs still running on 1.9.x, and in some cases, 1.8.x, so you may need to use a more backward-compatible strategy. In Ruby on Rails, this was solved with an eager_autoload method that forcibly loads all modules marked to be lazily loaded. If you are running threaded code, it is recommended that you call this prior to launching threads. Note that in Rails 4.0, the framework will eager load all modules by default, which should help you avoid having to think about these threading issues.

Eager Autoloading in AWS SDK for Ruby

So is this an issue for the AWS SDK for Ruby? In short, if you are using a version prior to Ruby 2.0, the answer is "most likely". The SDK is large enough that lazily loading extra modules is important to keep library load time as fast as possible. The downside of this approach is that it can cause issues in multi-threaded programs.

To solve the problem in the SDK, we use a similar mechanism to Ruby on Rails and created an AWS.eager_autoload! method that requires all modules in the library up front. To use this method, simply call it before you launch any threads:

require 'aws-sdk'

AWS.eager_autoload!

# Now you can start threading
Thread.new do ... end

Focused Eager Loading

Sometimes, loading all of the SDK is unnecessary and slow. Fortunately, as of version 1.9.0 of the Ruby SDK, the AWS.eager_autoload! method now optionally accepts the name of a module to load instead of requiring you to eager load the entire SDK. This means that if you are only using a specific service, or a set of services, like Amazon S3 and Amazon DynamoDB, you can choose to eager load only these modules. This can help to improve load time of your application, especially if you do not need many of the other modules packaged in the SDK. To load a focused set of modules, simply call the eager autoload method with the names of the modules you want to load along with AWS::Core:

AWS.eager_autoload! AWS::Core     # Make sure to load Core first.
AWS.eager_autoload! AWS::S3       # Load the S3 class
AWS.eager_autoload! AWS::DynamoDB # Load the DynamoDB class

# Now you can start threading
Thread.new do ... end

Wrapping Up This Thread

The AWS SDK for Ruby has an AWS.eager_autoload! method that allows you to forcibly load all components in the library up front. If you are writing multi-threaded code in Ruby, you will most likely want to call this method before launching any threads that make use of the SDK in order to avoid any thread-safety issues with autoload in older versions of Ruby. Fortunately, it is very easy to use by adding a single method call to the top of your application. It is also easy to target specific modules to eager load by passing the module name to the method, if load-time performance is important to your library or application.