Вы находитесь на странице: 1из 29

AWS CloudFormation | AWS Blog https://aws.amazon.

com/blogs/aws/category/aws-cloud-formation/

1 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

2 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

test-stack-configuration.json

3 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

prod-stack-configuration.json

4 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

- CidrIp: 0.0.0.0/0
FromPort: '443'
IpProtocol: tcp
ToPort: '443'

5 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

LambdaFunctionSource

{
"BucketName" : { "Fn::GetArtifactAtt" : ["LambdaFunctionSource", "BucketName"]},
"ObjectKey" : { "Fn::GetArtifactAtt" : ["LambdaFunctionSource", "ObjectKey"]}
}

Fn::GetParam

Fn:GetArtifactAtt Fn::GetParam

6 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

7 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

Parameters:
DBName:
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: must begin with a letter and contain only alphanumeric
characters.
Default: wordpressdb
Description: The WordPress database name
MaxLength: '64'
MinLength: '1'
Type: String

GetAtt Base64 FindInMap "Fn::GetAtt"


!GetAtt

- Fn::FindInMap:
- AWSInstanceType2Arch
- Ref: InstanceType
- Arch

!FindInMap [AWSInstanceType2Arch, !Ref InstanceType, Arch]

!Base64 !Sub
!Base64 Fn::Sub

8 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

CreateChangeSet CreateStack UpdateStack


GetTemplate

Outputs:
TSSG:
Value: !Ref TroubleShootingSG
Export:
Name: AccountSG

ImportValue

EC2Instance:
Type: AWS::EC2::Instance
Properties:
SecurityGroups:
- !ImportValue AccountSG

fn::Join

fn::Sub
${variable_name}

configure_wordpress:
commands:
01_set_mysql_root_password:
command: !Sub |
mysqladmin -u root password '${DBRootPassword}'
test: !Sub |
$(mysql ${DBName} -u root --password='${DBRootPassword}' >/dev/null 2>&1 </dev/null); (( $?
02_create_database:
command: !Sub |
mysql -u root --password='${DBRootPassword}' < /tmp/setup.mysql
test: !Sub |
$(mysql ${DBName} -u root --password='${DBRootPassword}' >/dev/null 2>&1 </dev/null); (( $?

${} ${variable} ${!} ${!variable}

9 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

10 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

UpdateStack CreateChangeSet DescribeChangeSet ExecuteChangeSet

11 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

12 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

13 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

14 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

15 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

16 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

17 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

18 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

19 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

exports.handler = function(event, context) {


var start = new Date().getTime();
var bytesRead = 0;

event.Records.forEach(function(record) {
// Kinesis data is base64 encoded so decode here
payload = new Buffer(record.kinesis.data, 'base64').toString('ascii');
bytesRead += payload.length;

// log each record


console.log(JSON.stringify(record, null, 2));
});

// collect statistics on the function's activity and performance


console.log(JSON.stringify({
"recordsProcessed": event.Records.length,
"processTime": new Date().getTime() - start,
"bytesRead": bytesRead,
}, null, 2));

20 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

21 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

22 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

23 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

24 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

25 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

26 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

27 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

28 of 29 3/15/2017 8:55 PM
AWS CloudFormation | AWS Blog https://aws.amazon.com/blogs/aws/category/aws-cloud-formation/

29 of 29 3/15/2017 8:55 PM