AWS::OpsWorks::Layer
Creates an AWS OpsWorks layer. A layer defines, for example, which packages and applications are installed and how they are configured.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
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:StringAutoAssignElasticIps:BooleanAutoAssignPublicIps:BooleanCustomInstanceProfileArn:StringCustomRecipes:RecipesCustomJson:JSON objectCustomSecurityGroupIds: -StringEnableAutoHealing:BooleanInstallUpdatesOnBoot:BooleanLifecycleEventConfiguration:LifeCycleEventConfigurationLoadBasedAutoScaling:LoadBasedAutoScalingName:StringPackages: -StringShortname:StringStackId:StringTags: -TagsType:StringVolumeConfigurations: -VolumeConfiguration
Properties
Attributes-
One or more user-defined key-value pairs to be added to the stack attributes bag.
Required: No
Type: A list of key-value pairs
Update requires: No interruption
AutoAssignElasticIps-
Whether to automatically assign an Elastic IP address to Amazon EC2 instances in this layer.
Required: Yes
Type: Boolean
Update requires: No interruption
AutoAssignPublicIps-
For AWS OpsWorks stacks that are running in a VPC, whether to automatically assign a public IP address to Amazon EC2 instances in this layer.
Required: Yes
Type: Boolean
Update requires: No interruption
CustomInstanceProfileArn-
The Amazon Resource Name (ARN) of an IAM instance profile that is to be used for the Amazon EC2 instances in this layer.
Required: No
Type: String
Update requires: No interruption
CustomJson-
A custom stack configuration and deployment attributes that AWS OpsWorks installs on the layer's instances. For more information, see the
CustomJsonparameter for the CreateLayer action in the AWS OpsWorks Stacks API Reference.Required: No
Type: JSON object
CustomRecipes-
Custom event recipes for this layer.
Required: No
Type: AWS OpsWorks Recipes Type
Update requires: No interruption
CustomSecurityGroupIds-
Custom security group IDs for this layer.
Required: No
Type: List of String values
Update requires: No interruption
EnableAutoHealing-
Whether to automatically heal Amazon EC2 instances that have become disconnected or timed out.
Required: Yes
Type: Boolean
Update requires: No interruption
InstallUpdatesOnBoot-
Whether to install operating system and package updates when the instance boots.
Required: No
Type: Boolean
Update requires: No interruption
LifecycleEventConfiguration-
The lifecycle events for the AWS OpsWorks layer.
Required: No
Type: AWS OpsWorks Layer LifeCycleConfiguration
Update requires: No interruption
LoadBasedAutoScaling-
The load-based scaling configuration for the AWS OpsWorks layer.
Required: No
Type: AWS OpsWorks LoadBasedAutoScaling Type
Update requires: No interruption
Name-
The AWS OpsWorks layer name.
Required: Yes
Type: String
Update requires: No interruption
Packages-
The packages for this layer.
Required: No
Type: List of String values
Update requires: No interruption
Shortname-
The layer short name, which is used internally by AWS OpsWorks and by Chef recipes. The short name is also used as the name for the directory where your app files are installed.
The name can have a maximum of 200 characters, which are limited to the alphanumeric characters, '-', '_', and '.'.
Important
If you update a property that requires the layer to be replaced, you must specify a new short name. You cannot have multiple layers with the same short name.
Required: Yes
Type: String
Update requires: No interruption
StackId-
The ID of the AWS OpsWorks stack that this layer will be associated with.
Required: Yes
Type: String
Update requires: Replacement
Tags-
Specifies an arbitrary set of tags (key–value pairs) to associate with this AWS OpsWorks layer. Use tags to manage your resources.
Required: No
Type: Resource Tag
Update requires: No interruption
Type-
The layer type. A stack cannot have more than one layer of the same type, except for the
customtype. You can have any number ofcustomtypes. For more information, see CreateLayer in the AWS OpsWorks Stacks API Reference.Important
If you update a property that requires the layer to be replaced, you must specify a new type unless you have a
customtype. You can have any number ofcustomtypes.Required: Yes
Type: String
Update requires: Replacement
VolumeConfigurations-
Describes the Amazon EBS volumes for this layer.
Required: No
Type: A list of AWS OpsWorks VolumeConfiguration
Update requires: Some interruptions
Return Values
Ref
When the logical ID of this resource is provided to the Ref intrinsic
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.
Template Examples
AWS 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
