AWS::OpsWorks::Layer - AWS CloudFormation

AWS::OpsWorks::Layer

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

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

Properties

Attributes

One or more user-defined key-value pairs to be added to the stack attributes.

To create a cluster layer, set the EcsClusterArn attribute to the cluster's ARN.

Required: No

Type: Object of String

Pattern: [a-zA-Z0-9]+

Update requires: No interruption

AutoAssignElasticIps

Whether to automatically assign an Elastic IP address to the layer's instances. For more information, see How to Edit a Layer.

Required: Yes

Type: Boolean

Update requires: No interruption

AutoAssignPublicIps

For stacks that are running in a VPC, whether to automatically assign a public IP address to the layer's instances. For more information, see How to Edit a Layer.

Required: Yes

Type: Boolean

Update requires: No interruption

CustomInstanceProfileArn

The ARN of an IAM profile to be used for the layer's EC2 instances. For more information about IAM ARNs, see Using Identifiers.

Required: No

Type: String

Update requires: No interruption

CustomJson

A JSON-formatted string containing custom stack configuration and deployment attributes to be installed on the layer's instances. For more information, see Using Custom JSON. This feature is supported as of version 1.7.42 of the AWS CLI.

Required: No

Type: Json

Update requires: No interruption

CustomRecipes

A LayerCustomRecipes object that specifies the layer custom recipes.

Required: No

Type: Recipes

Update requires: No interruption

CustomSecurityGroupIds

An array containing the layer custom security group IDs.

Required: No

Type: Array of String

Update requires: No interruption

EnableAutoHealing

Whether to disable auto healing for the layer.

Required: Yes

Type: Boolean

Update requires: No interruption

InstallUpdatesOnBoot

Whether to install operating system and package updates when the instance boots. The default value is true. To control when updates are installed, set this value to false. You must then update your instances manually by using CreateDeployment to run the update_dependencies stack command or by manually running yum (Amazon Linux) or apt-get (Ubuntu) on the instances.

Note

To ensure that your instances have the latest security updates, we strongly recommend using the default value of true.

Required: No

Type: Boolean

Update requires: No interruption

LifecycleEventConfiguration

A LifeCycleEventConfiguration object that you can use to configure the Shutdown event to specify an execution timeout and enable or disable Elastic Load Balancer connection draining.

Required: No

Type: LifecycleEventConfiguration

Update requires: No interruption

LoadBasedAutoScaling

The load-based scaling configuration for the AWS OpsWorks layer.

Required: No

Type: LoadBasedAutoScaling

Update requires: No interruption

Name

The layer name, which is used by the console. Layer names can be a maximum of 32 characters.

Required: Yes

Type: String

Update requires: No interruption

Packages

An array of Package objects that describes the layer packages.

Required: No

Type: Array of String

Update requires: No interruption

Shortname

For custom layers only, use this parameter to specify the layer's short name, which is used internally by AWS OpsWorks Stacks and by Chef recipes. The short name is also used as the name for the directory where your app files are installed. It can have a maximum of 32 characters, which are limited to the alphanumeric characters, '-', '_', and '.'.

Built-in layer short names are defined by AWS OpsWorks Stacks. For more information, see the Layer Reference.

Required: Yes

Type: String

Update requires: No interruption

StackId

The layer stack ID.

Required: Yes

Type: String

Update requires: Replacement

Tags

Specifies one or more sets of tags (key–value pairs) to associate with this AWS OpsWorks layer. Use tags to manage your resources.

Required: No

Type: Array of Tag

Update requires: No interruption

Type

The layer type. A stack cannot have more than one built-in layer of the same type. It can have any number of custom layers. Built-in layers are not available in Chef 12 stacks.

Required: Yes

Type: String

Allowed values: aws-flow-ruby | ecs-cluster | java-app | lb | web | php-app | rails-app | nodejs-app | memcached | db-master | monitoring-master | custom

Update requires: Replacement

UseEbsOptimizedInstances

Whether to use Amazon EBS-optimized instances.

Required: No

Type: Boolean

Update requires: No interruption

VolumeConfigurations

A VolumeConfigurations object that describes the layer's Amazon EBS volumes.

Required: No

Type: Array of VolumeConfiguration

Update requires: No interruption

Return values

Ref

When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the resource name. For example:

{ "Ref": "myLayer" }

For the AWS OpsWorks layer myLayer, Ref returns the AWS OpsWorks layer ID.

For more information about using the Ref function, see Ref.

Fn::GetAtt

Examples

OpsWorks PHP Layer

The following snippet creates an AWS OpsWorks PHP layer that is associated with the myStack AWS OpsWorks stack. The layer is dependent on the myApp AWS OpsWorks application.

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"

Load-based Auto Scaling Layer

The following snippet creates a load-based automatic scaling AWS OpsWorks PHP layer that is associated with the myStack AWS OpsWorks stack.

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

Specify tags for layers and stacks

The following complete template example specifies tags for an AWS OpsWorks layer and stack that reference parameter values.

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

See also