AWS CloudFormation
User Guide (API 版本 2010-05-15)
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

AWS::OpsWorks::Layer

创建 AWS OpsWorks 层。举例来说,层定义安装的软件包和应用程序及其配置方式。

语法

要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:

JSON

{ "Type": "AWS::OpsWorks::Layer", "Properties": { "Attributes" : { String:String }, "AutoAssignElasticIps" : Boolean, "AutoAssignPublicIps" : Boolean, "CustomInstanceProfileArn" : String, "CustomJson" : JSON object, "CustomRecipes" : Recipes, "CustomSecurityGroupIds" : [ String, ... ], "EnableAutoHealing" : Boolean, "InstallUpdatesOnBoot" : Boolean, "LifecycleEventConfiguration" : LifeCycleEventConfiguration, "LoadBasedAutoScaling" : LoadBasedAutoScaling, "Name" : String, "Packages" : [ String, ... ], "Shortname" : String, "StackId" : String, "Tags" : [ Tags, ... ], "Type" : String, "VolumeConfigurations" : [ VolumeConfiguration, ... ] } }

YAML

Type: "AWS::OpsWorks::Layer" Properties: Attributes: String:String AutoAssignElasticIps: Boolean AutoAssignPublicIps: Boolean CustomInstanceProfileArn: String CustomRecipes: Recipes CustomJson: JSON object CustomSecurityGroupIds: - 字符串 EnableAutoHealing: Boolean InstallUpdatesOnBoot: Boolean LifecycleEventConfiguration: LifeCycleEventConfiguration LoadBasedAutoScaling: LoadBasedAutoScaling Name: String Packages: - 字符串 Shortname: String StackId: String Tags: - Tags Type: String VolumeConfigurations: - VolumeConfiguration

属性

Attributes

要添加到堆栈属性包的一个或多个用户定义的键/值对。

Required: No

类型:键/值对的列表

更新要求无需中断

AutoAssignElasticIps

是否自动将弹性 IP 地址分配给此层中的 Amazon EC2 实例。

Required: Yes

Type: Boolean

更新要求无需中断

AutoAssignPublicIps

对于在 VPC 中运行的 AWS OpsWorks 堆栈,是否自动将公有 IP 地址分配给此层中的 Amazon EC2 实例。

Required: Yes

Type: Boolean

更新要求无需中断

CustomInstanceProfileArn

要用于此层中 Amazon EC2 实例的 IAM 实例配置文件的 Amazon 资源名称 (ARN)。

Required: No

Type: String

更新要求无需中断

CustomJson

AWS OpsWorks 安装在此层的实例上的自定义堆栈配置和部署属性。有关更多信息,请参阅 AWS OpsWorks Stacks API Reference 中的 CreateLayer 操作的 CustomJson 参数。

Required: No

Type: JSON object

CustomRecipes

此层的自定义事件配方。

Required: No

类型AWS OpsWorks Recipes 类型

更新要求无需中断

CustomSecurityGroupIds

此层的自定义安全组 ID。

Required: No

Type: List of String values

更新要求无需中断

EnableAutoHealing

是否自动修复已断开连接或已超时的 Amazon EC2 实例。

Required: Yes

Type: Boolean

更新要求无需中断

InstallUpdatesOnBoot

是否在实例启动时安装操作系统和软件包更新。

Required: No

Type: Boolean

更新要求无需中断

LifecycleEventConfiguration

AWS OpsWorks 层的生命周期事件。

Required: No

类型AWS OpsWorks Layer LifeCycleConfiguration

更新要求无需中断

LoadBasedAutoScaling

AWS OpsWorks 层的基于负载的扩展配置。

Required: No

类型AWS OpsWorks LoadBasedAutoScaling 类型

更新要求无需中断

Name

AWS OpsWorks 层名称。

Required: Yes

Type: String

更新要求无需中断

Packages

用于此层的软件包。

Required: No

Type: List of String values

更新要求无需中断

Shortname

由 AWS OpsWorks 和 Chef 配方在内部使用的层短名称。短名称也用作安装应用程序文件的目录的名称。

该名称最多可以包含 200 个字符,仅限于字母数字字符、“-”、“_”和“.”。

重要

如果您更新需要更换层的属性,则必须指定新的短名称。不能多个层使用相同的短名称。

Required: Yes

Type: String

更新要求无需中断

StackId

将与此层关联的 AWS OpsWorks 堆栈的 ID。

Required: Yes

Type: String

更新要求替换

Tags

指定要与该 AWS OpsWorks 层关联的任意标签组 (键/值对)。使用标签来管理您的资源。

Required: No

Type: AWS CloudFormation 资源标签

更新要求无需中断

Type

层类型。堆栈不能具有多个相同类型的层,但 custom 类型除外。您可以拥有任意数量的 custom 类型。有关更多信息,请参阅 AWS OpsWorks Stacks API Reference 中的 CreateLayer

重要

如果更新需要更换层的属性,则必须指定新的类型,但 custom 类型除外。您可以拥有任意数量的 custom 类型。

Required: Yes

Type: String

更新要求替换

VolumeConfigurations

描述此层的 Amazon EBS 卷。

Required: No

类型AWS OpsWorks VolumeConfiguration 类型 的列表。

更新要求时而中断

返回值

Ref

当该资源的逻辑 ID 提供给 Ref内部函数时,Ref 将返回资源名称。 示例:

{ "Ref": "myLayer" }

对于 AWS OpsWorks 层 myLayerRef 将返回 AWS OpsWorks 层 ID。

有关使用 Ref 功能的更多信息,请参阅参考

模板示例

AWS OpsWorks PHP 层

以下代码段创建与 myStack AWS OpsWorks 堆栈关联的 AWS OpsWorks PHP 层。该层依赖于 myApp AWS OpsWorks 应用程序。

JSON

"myLayer": { "Type": "AWS::OpsWorks::Layer", "DependsOn": "myApp", "Properties": { "StackId": {"Ref": "myStack"}, "Type": "php-app", "Shortname" : "php-app", "EnableAutoHealing" : "true", "AutoAssignElasticIps" : "false", "AutoAssignPublicIps" : "true", "Name": "MyPHPApp" } }

YAML

myLayer: Type: "AWS::OpsWorks::Layer" DependsOn: "myApp" Properties: StackId: Ref: "myStack" Type: "php-app" Shortname: "php-app" EnableAutoHealing: "true" AutoAssignElasticIps: "false" AutoAssignPublicIps: "true" Name: "MyPHPApp"

基于负载的 Auto Scaling 层

以下代码段创建一个基于负载的自动扩展 AWS OpsWorks PHP 层,该层与 myStack AWS OpsWorks 堆栈关联。

JSON

"myLayer": { "Type": "AWS::OpsWorks::Layer", "DependsOn": "myApp", "Properties": { "StackId": {"Ref": "myStack"}, "Type": "php-app", "Shortname" : "php-app", "EnableAutoHealing" : "true", "AutoAssignElasticIps" : "false", "AutoAssignPublicIps" : "true", "Name": "MyPHPApp", "LoadBasedAutoScaling" : { "Enable" : "true", "UpScaling" : { "InstanceCount" : 1, "ThresholdsWaitTime" : 1, "IgnoreMetricsTime" : 1, "CpuThreshold" : 70.0, "MemoryThreshold" : 30.0, "LoadThreshold" : 0.7 }, "DownScaling" : { "InstanceCount" : 1, "ThresholdsWaitTime" : 1, "IgnoreMetricsTime" : 1, "CpuThreshold" : 30.0, "MemoryThreshold" : 70.0, "LoadThreshold" : 0.3 } } } }

YAML

myLayer: Type: "AWS::OpsWorks::Layer" DependsOn: "myApp" Properties: StackId: Ref: "myStack" Type: "php-app" Shortname: "php-app" EnableAutoHealing: "true" AutoAssignElasticIps: "false" AutoAssignPublicIps: "true" Name: "MyPHPApp" LoadBasedAutoScaling: Enable: "true" UpScaling: InstanceCount: 1 ThresholdsWaitTime: 1 IgnoreMetricsTime: 1 CpuThreshold: 70 MemoryThreshold: 30 LoadThreshold: 0.7 DownScaling: InstanceCount: 1 ThresholdsWaitTime: 1 IgnoreMetricsTime: 1 CpuThreshold: 30 MemoryThreshold: 70 LoadThreshold: 0.3

指定层和堆栈的标签

以下完整模板示例指定引用参数值的 AWS OpsWorks 层和堆栈的标签。

JSON

{ "Resources": { "ServiceRole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ { "Ref": "OpsServicePrincipal" } ] }, "Action": [ "sts:AssumeRole" ] } ] }, "Path": "/", "Policies": [ { "PolicyName": "opsworks-service", "PolicyDocument": { "Statement": [ { "Effect": "Allow", "Action": [ "ec2:*", "iam:PassRole", "cloudwatch:GetMetricStatistics", "elasticloadbalancing:*" ], "Resource": "*" } ] } } ] } }, "OpsWorksEC2Role": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ { "Ref": "Ec2ServicePrincipal" } ] }, "Action": [ "sts:AssumeRole" ] } ] }, "Path": "/" } }, "InstanceRole": { "Type": "AWS::IAM::InstanceProfile", "Properties": { "Path": "/", "Roles": [ { "Ref": "OpsWorksEC2Role" } ] } }, "myStack": { "Type": "AWS::OpsWorks::Stack", "Properties": { "Name": "TestStack", "ServiceRoleArn": { "Fn::GetAtt": [ "ServiceRole", "Arn" ] }, "DefaultInstanceProfileArn": { "Fn::GetAtt": [ "InstanceRole", "Arn" ] }, "Tags": [ { "Key": { "Ref": "StackKey" }, "Value": { "Ref": "StackValue" } } ] } }, "myLayer": { "Type": "AWS::OpsWorks::Layer", "Properties": { "EnableAutoHealing": "true", "AutoAssignElasticIps": "false", "AutoAssignPublicIps": "true", "StackId": { "Ref": "myStack" }, "Type": "custom", "Shortname": "shortname", "Name": "name", "Tags": [ { "Key": { "Ref": "LayerKey" }, "Value": { "Ref": "LayerValue" } } ] } } }, "Parameters": { "StackKey": { "Type": "String" }, "LayerKey": { "Type": "String" }, "StackValue": { "Type": "String" }, "LayerValue": { "Type": "String" }, "OpsServicePrincipal": { "Type": "String" }, "Ec2ServicePrincipal": { "Type": "String" } } }

YAML

Resources: ServiceRole: Type: 'AWS::IAM::Role' Properties: AssumeRolePolicyDocument: Statement: - Effect: Allow Principal: Service: - !Ref OpsServicePrincipal Action: - 'sts:AssumeRole' Path: / Policies: - PolicyName: opsworks-service PolicyDocument: Statement: - Effect: Allow Action: - 'ec2:*' - 'iam:PassRole' - 'cloudwatch:GetMetricStatistics' - 'elasticloadbalancing:*' Resource: '*' OpsWorksEC2Role: Type: 'AWS::IAM::Role' Properties: AssumeRolePolicyDocument: Statement: - Effect: Allow Principal: Service: - !Ref Ec2ServicePrincipal Action: - 'sts:AssumeRole' Path: / InstanceRole: Type: 'AWS::IAM::InstanceProfile' Properties: Path: / Roles: - !Ref OpsWorksEC2Role myStack: Type: 'AWS::OpsWorks::Stack' Properties: Name: TestStack ServiceRoleArn: !GetAtt - ServiceRole - Arn DefaultInstanceProfileArn: !GetAtt - InstanceRole - Arn Tags: - Key: !Ref StackKey Value: !Ref StackValue myLayer: Type: 'AWS::OpsWorks::Layer' Properties: EnableAutoHealing: 'true' AutoAssignElasticIps: 'false' AutoAssignPublicIps: 'true' StackId: !Ref myStack Type: custom Shortname: shortname Name: name Tags: - Key: !Ref LayerKey Value: !Ref LayerValue Parameters: StackKey: Type: String LayerKey: Type: String StackValue: Type: String LayerValue: Type: String OpsServicePrincipal: Type: String Ec2ServicePrincipal: Type: String

另请参阅