AWS Elastic Beanstalk – Environment Resource Support + Updated PHP Runtime
AWS Elastic Beanstalk can now provision and configure AWS resources to power your application. In conjunction with a new version of our PHP runtime, you get more control and more flexibility with less code.
In October, we announced the Elastic Beanstalk configuration files and talked about how they can help you configure EC2 instances without creating and maintaining custom AMIs. We have extended these configuration files to allow you to provision and configure resources such as SQS queues and DynamoDB tables for your Elastic Beanstalk application. The configuration file format is YAML-based, and you can find the details in the AWS Elastic Beanstalk Developer Guide.
We are also announcing an updated PHP runtime that supports configuration files as well as the seamless integration with Amazon RDS and Amazon VPC – see my previous blog post for details. The PHP runtime supports 5.3 and 5.4. You can also install dependencies using Composer. Visit the Elastic Beanstalk Developer Guide to learn more about the updated PHP runtime and for walkthroughs of how to deploy CakePHP and Symfony2.
I’d lke to show you how simple and powerful it is to use Elastic Beanstalk to create and configure the new environment resources. Ill use the updated PHP runtime and show you how to configure DynamoDB backed session management. You can find the full example in the AWS Elastic Beanstalk Developer Guide.
Here’s what you need to do:
- Launch an Elastic Beanstalk PHP environment (see the AWS Elastic Beanstalk Developer Guide).
- Create an IAM role with enough permission to read and write to the DynamoDB table (lets call it SessionRole).
- Add an .ebextensions directory to your application.
- In that directory, create a configuration file called dynamodb.config with the following content:
- Add the role to the Elastic Beanstalk environment (this and all of the subsequent snippets also belong in the dynamodb.config file):
- Pass the details of the DynamoDB table to the EC2 instances in your environment:
- Add a CloudWatch Alarm so that you are alerted when requests to DynamoDB get throttled:
- Make sure to include a require for the AWS SDK for PHP 2 in your composer.json file:
- Finally, add the following code to your PHP application to connect it to the configuration file:
As you can see, you can use this new Elastic Beanstalk feature to set up and configure the AWS resources needed by your application.
– Jeff, with lots of help from Saad