AWS News Blog
AWS CloudFormation Supports HAQM DynamoDB and HAQM CloudFront Dynamic Content
Today, AWS CloudFormation is adding support for HAQM DynamoDB and HAQM CloudFront dynamic content. You can now describe related AWS resources such as EC2 instances, HAQM DynamoDB tables, and HAQM CloudFront distributions using CloudFormation templates. These templates can fully encapsulate the resources needed to run your application on AWS and can be version controlled alongside application source.
HAQM DynamoDB
You can easily provision and manage HAQM DynamoDB tables using CloudFormation. For example, if your application stores session state in HAQM DynamoDB, you can create the table using the CloudFormation snippet below:
“Type” : “AWS::DynamoDB::Table” ,
“Properties” : {
“KeySchema” : {
“HashKeyElement” : {
“AttributeName” : “id” ,
“AttributeType” : “HAQMDynamoDB::TYPE_STRING”
}
} ,
“ProvisionedThroughput” : {
“ReadCapacityUnits” : “5” ,
“WriteCapacityUnits” : “10”
}
}
}
Using the CloudFormation template format, you can quickly launch multiple similar stacks and customize each using the provided parameters. Should your application require more provisioned throughput, you can simply update a running CloudFormation stack and provide different parameters.
HAQM CloudFront Dynamic Content
In a previous post, I talked about how you can now use HAQM CloudFront to distribute static, dynamic, and streaming content. Now you can provision and update HAQM CloudFront distributions using CloudFormation templates. This includes support for multiple origins and dynamic content. To get started:
- You can configure multiple origin servers for your HAQM CloudFront distributions. In the example below, I host all of my pictures in S3 and I send my dynamic content to an Elastic Load Balancer:
“app-distribution” : {
“Type” : “AWS::CloudFront::Distribution” ,
“Properties” : {
“DistributionConfig” : {
“DefaultRootObject” : “index.php” ,
“Origins” : [ {
“Id” : “S3 Origin” ,
“DomainName” : { “Fn::GetAtt” : [ “S3OriginBucket” , “DomainName” ] } ,
“S3OriginConfig” : { }
} , {
“Id” : “Dynamic Origin” ,
“DomainName” : { “Fn::GetAtt” : [ “WebServer” , “PublicDnsName” ] } ,
“CustomOriginConfig” : {
“OriginProtocolPolicy” : “match-viewer”
}
}
] ,
“DefaultCacheBehavior” : {
“TargetOriginId” : “Dynamic Origin” ,
“ForwardedValues” : {
“QueryString” : “true”
} ,
“ViewerProtocolPolicy” : “allow-all”
} ,
“CacheBehaviors” : [ {
“TargetOriginId” : “S3 Origin” ,
“ForwardedValues” : {
“QueryString” : “false”
} ,
“ViewerProtocolPolicy” : “allow-all” ,
“MinTTL” : “500” ,
“PathPattern” : “*.jpg”
} ,
{
“TargetOriginId” : “Dynamic Origin” ,
“ForwardedValues” : {
“QueryString” : “true”
} ,
“ViewerProtocolPolicy” : “allow-all” ,
“MinTTL” : “500” ,
“PathPattern” : “*.php”
}
] ,
“Comment” : “Sample multi-origin CloudFront distribution created using CloudFormation.” ,
“Logging” : {
“Bucket” : { “Fn::GetAtt” : [ “S3LoggingBucket” , “DomainName” ] } ,
“Prefix” : “CloudFrontDistributionSampleLogs”
} ,
“Enabled” : “true”
}
}
} - You can use query string parameters to customize your pages. In the example below, Im forwarding query string parameters to my PHP origin:
“CacheBehaviors” : [ {
“TargetOriginId” : “Dynamic Origin” ,
“ForwardedValues” : {
“QueryString” : “true”
} ,
“ViewerProtocolPolicy” : “allow-all” ,
“PathPattern” : “*.php”
}
] - You can configure cache behaviors for different portions of the website. Here, Im setting a lower minTTL for my static content:
{
“TargetOriginId” : “S3 Origin” ,
“ForwardedValues” : {
“QueryString” : “false”
} ,“ViewerProtocolPolicy” : “allow-all”,
“MinTTL” : “500”,
“PathPattern” : “*.jpg”
}
Of course, if you need to make adjustments to any of the above settings, you can simply modify the template and then update your running CloudFormation stacks. CloudFormation takes care of the rest.
As usual, CloudFormation has also expanded its list of sample templates to provide more examples on how to use HAQM DynamoDB and HAQM CloudFront dynamic content. You can also visit the AWS CloudFormation User Guide to get started.
— Jeff;
P.S: We are looking for highly motivated software developers and product managers who want to work on AWS CloudFormation. If you are interested, send us your resume to aws-cloudformation-jobs at haqm.com.