AWS CloudFormation
User Guide (API Version 2010-05-15)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

AWS::ElasticBeanstalk::Environment

创建或更新 AWS Elastic Beanstalk 环境。

语法

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

JSON

Copy
{ "Type" : "AWS::ElasticBeanstalk::Environment", "Properties" : { "ApplicationName" : String, "CNAMEPrefix" : String, "Description" : String, "EnvironmentName" : String, "OptionSettings" : [ OptionSettings, ... ], "PlatformArn" : String, "SolutionStackName" : String, "Tags" : [ Resource Tag, ... ], "TemplateName" : String, "Tier" : Environment Tier, "VersionLabel" : String } }

YAML

Copy
Type: "AWS::ElasticBeanstalk::Environment" Properties: ApplicationName: String CNAMEPrefix: String Description: String EnvironmentName: String OptionSettings: - OptionSettings PlatformArn: String SolutionStackName: String Tags: - Resource Tag, ... TemplateName: String Tier: Environment Tier VersionLabel: String

属性

有关更多信息,请参阅 AWS Elastic Beanstalk API 参考中的 CreateEnvironment

ApplicationName

与该环境关联的应用程序的名称。

Required: Yes

Type: String

更新要求替换

CNAMEPrefix

Elastic Beanstalk 环境 URL 的前缀。

Required: No

Type: String

更新要求替换

Description

帮助您对该环境进行标识的描述。

Required: No

Type: String

更新要求无需中断

EnvironmentName

Elastic Beanstalk 环境的名称。如果不指定名称,则 AWS CloudFormation 生成一个唯一的物理 ID 并将该 ID 用作环境名称。有关更多信息,请参阅 名称类型

重要

如果指定一个名称,您将无法执行需要替换此资源的更新。您可以执行不需要或者只需要部分中断的更新。如果必须替换资源,请指定新名称。

Required: No

Type: String

更新要求替换

OptionSettings

用于定义此环境中的配置选项的键值对,如实例类型。这些选项会覆盖解决方案堆栈或配置模板中定义的值。如果您在堆栈更新期间删除任何选项,则被删除的选项会恢复为默认值。

必需:是. IamInstanceProfileServiceRole 为必需选项。

Type: OptionSetting 列表

更新要求时而中断

PlatformArn

与该环境配合使用的自定义平台的 Amazon 资源名称 (ARN)。有关更多信息,请参阅 AWS Elastic Beanstalk 开发人员指南中的自定义平台

注意

如果指定 PlatformArn,则不要指定 SolutionStackName

必需:否

类型:字符串

更新要求无需中断

示例: "PlatformArn": "arn:aws:elasticbeanstalk:us-east-1::platform/PHP 5.4 running on 64bit Amazon Linux/2.4.4"

SolutionStackName

此配置将使用的 Elastic Beanstalk 解决方案堆栈的名称。有关更多信息,请参阅 AWS Elastic Beanstalk 开发人员指南 中的支持的平台

注意

如果指定 SolutionStackName,则不要指定 PlatformArnTemplateName

Required: No

Type: String

更新要求替换

Tags

此环境的任意标签组(键–值对)。

Required: No

Type: AWS CloudFormation 资源标签

更新要求:仅当您更新其他需要更换环境的属性(如 ApplicationName 属性)时,才能更新标签。

TemplateName

与该环境配合使用的 Elastic Beanstalk 配置模板的名称。

注意

如果指定 TemplateName,则不要指定 SolutionStackName

Required: No

Type: String

更新要求时而中断

Tier

指定要用于创建环境的层。您选择的环境层可确定 Elastic Beanstalk 配置资源是支持处理 HTTP(S) 请求的 Web 应用程序还是支持处理后台处理任务的 Web 应用程序。

Required: No

类型Elastic Beanstalk 环境层属性类型

更新要求:请参阅 Elastic Beanstalk 环境层属性类型

VersionLabel

要与环境关联的版本。

Required: No

Type: String

更新要求时而中断

返回值

Ref

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

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

Fn::GetAtt

Fn::GetAtt 返回一个此类型指定属性的值。以下为可用属性和示例返回值。

EndpointURL

此环境的负载均衡器的 URL。

例如:

awseb-myst-myen-132MQC4KRLAMD-1371280482.us-east-2.elb.amazonaws.com

有关使用 Fn::GetAtt 的更多信息,请参见 Fn::GetAtt

示例

简单环境

JSON

Copy
{ "Type" : "AWS::ElasticBeanstalk::Environment", "Properties" : { "ApplicationName" : { "Ref" : "sampleApplication" }, "Description" : "AWS Elastic Beanstalk Environment running PHP Sample Application", "EnvironmentName" : "SamplePHPEnvironment", "TemplateName" : "DefaultConfiguration", "VersionLabel" : "Initial Version" } }

YAML

Copy
Type: "AWS::ElasticBeanstalk::Environment" Properties: ApplicationName: Ref: sampleApplication Description: "AWS Elastic Beanstalk Environment running PHP Sample Application" EnvironmentName: SamplePHPEnvironment TemplateName: DefaultConfiguration VersionLabel: "Initial Version"

具有嵌入式选项设置的环境

JSON

Copy
{ "Type" : "AWS::ElasticBeanstalk::Environment", "Properties" : { "ApplicationName" : { "Ref" : "sampleApplication" }, "Description" : "AWS Elastic Beanstalk Environment running Python Sample Application", "EnvironmentName" : "SamplePythonEnvironment", "SolutionStackName" : "64bit Amazon Linux 2017.03 v2.5.0 running Python 2.7", "OptionSettings" : [ { "Namespace" : "aws:autoscaling:launchconfiguration", "OptionName" : "EC2KeyName", "Value" : { "Ref" : "KeyName" } } ], "VersionLabel" : "Initial Version" } }

YAML

Copy
Type: "AWS::ElasticBeanstalk::Environment" Properties: ApplicationName: Ref: sampleApplication Description: "AWS Elastic Beanstalk Environment running Python Sample Application" EnvironmentName: SamplePythonEnvironment SolutionStackName: "64bit Amazon Linux 2017.03 v2.5.0 running Python 2.7" OptionSettings: - Namespace: "aws:autoscaling:launchconfiguration" OptionName: EC2KeyName Value: Ref: KeyName VersionLabel: "Initial Version"

自定义平台或支持的平台

以下示例中包含的参数可在创建堆栈时为自定义平台指定 PlatformArn 或为支持的平台指定 SolutionStackName

JSON

Copy
{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "Elasticbeanstalk test template", "Parameters": { "BeanstalkService": { "Type": "String" }, "Ec2Service": { "Type": "String" }, "Partition":{ "Type": "String" }, "SolutionStackName": { "Type": "String" }, "PlatformArn": { "Type": "String" } }, "Resources": { "Application": { "Properties": { "ApplicationVersions": [ { "Description": "Version 1.0", "SourceBundle": { "S3Bucket": { "Fn::Join": ["", ["elasticbeanstalk-samples-", {"Ref": "AWS::Region"}]] }, "S3Key": "python-sample-20150402.zip" }, "VersionLabel": "Initial Version" } ], "Description": "AWS Elastic Beanstalk Python Sample Application" }, "Type": "AWS::ElasticBeanstalk::Application" }, "Environment": { "Properties": { "ApplicationName": { "Ref": "Application" }, "Description": "AWS Elastic Beanstalk Environment running Python Sample Application", "PlatformArn": { "Ref" : "PlatformArn"}, "SolutionStackName": { "Ref": "SolutionStackName" }, "VersionLabel": "Initial Version", "OptionSettings": [ { "Namespace": "aws:autoscaling:launchconfiguration", "OptionName": "IamInstanceProfile", "Value": { "Ref": "InstanceProfile" } }, { "Namespace": "aws:elasticbeanstalk:environment", "OptionName": "ServiceRole", "Value": { "Ref": "ServiceRole" } } ] }, "Type": "AWS::ElasticBeanstalk::Environment" }, "ServiceRole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "Service": {"Ref": "BeanstalkService"} }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "sts:ExternalId": "elasticbeanstalk" } } } ] }, "Policies": [ { "PolicyName": "root", "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "elasticloadbalancing:DescribeInstanceHealth", "ec2:DescribeInstances", "ec2:DescribeInstanceStatus", "ec2:GetConsoleOutput", "ec2:AssociateAddress", "ec2:DescribeAddresses", "ec2:DescribeSecurityGroups", "sqs:GetQueueAttributes", "sqs:GetQueueUrl", "autoscaling:DescribeAutoScalingGroups", "autoscaling:DescribeAutoScalingInstances", "autoscaling:DescribeScalingActivities", "autoscaling:DescribeNotificationConfigurations" ], "Resource": [ "*" ] } ] } } ], "Path": "/" } }, "InstanceProfile": { "Type": "AWS::IAM::InstanceProfile", "Properties": { "Path": "/", "Roles": [ { "Ref": "InstanceProfileRole" } ] } }, "InstanceProfileRole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ {"Ref": "Ec2Service"} ] }, "Action": [ "sts:AssumeRole" ] } ] }, "Policies": [ { "PolicyName": "root", "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Sid": "BucketAccess", "Action": [ "s3:Get*", "s3:List*", "s3:PutObject" ], "Effect": "Allow", "Resource": [ { "Fn::Join": [ "", [ "arn:", { "Ref": "Partition" }, ":s3:::elasticbeanstalk-*-", { "Ref": "AWS::AccountId" } ] ] }, { "Fn::Join": [ "", [ "arn:", { "Ref": "Partition" }, ":s3:::elasticbeanstalk-*-", { "Ref": "AWS::AccountId" }, "/*" ] ] }, { "Fn::Join": [ "", [ "arn:", { "Ref": "Partition" }, ":s3:::elasticbeanstalk-*-", { "Ref": "AWS::AccountId" }, "-*" ] ] }, { "Fn::Join": [ "", [ "arn:", { "Ref": "Partition" }, ":s3:::elasticbeanstalk-*-", { "Ref": "AWS::AccountId" }, "-*/*" ] ] } ] }, { "Sid": "ECSAccess", "Effect": "Allow", "Action": [ "ecs:StartTask", "ecs:StopTask", "ecs:RegisterContainerInstance", "ecs:DeregisterContainerInstance", "ecs:DescribeContainerInstances", "ecs:DiscoverPollEndpoint", "ecs:Submit*", "ecs:Poll" ], "Resource": "*" }, { "Sid": "QueueAccess", "Action": [ "sqs:ChangeMessageVisibility", "sqs:DeleteMessage", "sqs:ReceiveMessage", "sqs:SendMessage" ], "Effect": "Allow", "Resource": "*" }, { "Sid": "DynamoPeriodicTasks", "Action": [ "dynamodb:BatchGetItem", "dynamodb:BatchWriteItem", "dynamodb:DeleteItem", "dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:Query", "dynamodb:Scan", "dynamodb:UpdateItem" ], "Effect": "Allow", "Resource": [ { "Fn::Join": [ "", [ "arn:", { "Ref": "Partition" }, ":dynamodb:*:", { "Ref": "AWS::AccountId" }, ":table/*-stack-AWSEBWorkerCronLeaderRegistry*" ] ] } ] }, { "Sid": "MetricsAccess", "Action": [ "cloudwatch:PutMetricData" ], "Effect": "Allow", "Resource": "*" } ] } } ], "Path": "/" } } } }

YAML

Copy
AWSTemplateFormatVersion: 2010-09-09 Description: Elasticbeanstalk test template Parameters: BeanstalkService: Type: String Ec2Service: Type: String Partition: Type: String SolutionStackName: Type: String PlatformArn: Type: String Resources: Application: Properties: ApplicationVersions: - Description: Version 1.0 SourceBundle: S3Bucket: !Join - '' - - elasticbeanstalk-samples- - !Ref 'AWS::Region' S3Key: python-sample-20150402.zip VersionLabel: Initial Version Description: AWS Elastic Beanstalk Python Sample Application Type: 'AWS::ElasticBeanstalk::Application' Environment: Properties: ApplicationName: !Ref Application Description: AWS Elastic Beanstalk Environment running Python Sample Application PlatformArn: !Ref PlatformArn SolutionStackName: !Ref SolutionStackName VersionLabel: Initial Version OptionSettings: - Namespace: 'aws:autoscaling:launchconfiguration' OptionName: IamInstanceProfile Value: !Ref InstanceProfile - Namespace: 'aws:elasticbeanstalk:environment' OptionName: ServiceRole Value: !Ref ServiceRole Type: 'AWS::ElasticBeanstalk::Environment' ServiceRole: Type: 'AWS::IAM::Role' Properties: AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Sid: '' Effect: Allow Principal: Service: !Ref BeanstalkService Action: 'sts:AssumeRole' Condition: StringEquals: 'sts:ExternalId': elasticbeanstalk Policies: - PolicyName: root PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: - 'elasticloadbalancing:DescribeInstanceHealth' - 'ec2:DescribeInstances' - 'ec2:DescribeInstanceStatus' - 'ec2:GetConsoleOutput' - 'ec2:AssociateAddress' - 'ec2:DescribeAddresses' - 'ec2:DescribeSecurityGroups' - 'sqs:GetQueueAttributes' - 'sqs:GetQueueUrl' - 'autoscaling:DescribeAutoScalingGroups' - 'autoscaling:DescribeAutoScalingInstances' - 'autoscaling:DescribeScalingActivities' - 'autoscaling:DescribeNotificationConfigurations' Resource: - '*' Path: / InstanceProfile: Type: 'AWS::IAM::InstanceProfile' Properties: Path: / Roles: - !Ref InstanceProfileRole InstanceProfileRole: Type: 'AWS::IAM::Role' Properties: AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: Service: - !Ref Ec2Service Action: - 'sts:AssumeRole' Policies: - PolicyName: root PolicyDocument: Version: 2012-10-17 Statement: - Sid: BucketAccess Action: - 's3:Get*' - 's3:List*' - 's3:PutObject' Effect: Allow Resource: - !Join - '' - - 'arn:' - !Ref Partition - ':s3:::elasticbeanstalk-*-' - !Ref 'AWS::AccountId' - !Join - '' - - 'arn:' - !Ref Partition - ':s3:::elasticbeanstalk-*-' - !Ref 'AWS::AccountId' - /* - !Join - '' - - 'arn:' - !Ref Partition - ':s3:::elasticbeanstalk-*-' - !Ref 'AWS::AccountId' - '-*' - !Join - '' - - 'arn:' - !Ref Partition - ':s3:::elasticbeanstalk-*-' - !Ref 'AWS::AccountId' - '-*/*' - Sid: ECSAccess Effect: Allow Action: - 'ecs:StartTask' - 'ecs:StopTask' - 'ecs:RegisterContainerInstance' - 'ecs:DeregisterContainerInstance' - 'ecs:DescribeContainerInstances' - 'ecs:DiscoverPollEndpoint' - 'ecs:Submit*' - 'ecs:Poll' Resource: '*' - Sid: QueueAccess Action: - 'sqs:ChangeMessageVisibility' - 'sqs:DeleteMessage' - 'sqs:ReceiveMessage' - 'sqs:SendMessage' Effect: Allow Resource: '*' - Sid: DynamoPeriodicTasks Action: - 'dynamodb:BatchGetItem' - 'dynamodb:BatchWriteItem' - 'dynamodb:DeleteItem' - 'dynamodb:GetItem' - 'dynamodb:PutItem' - 'dynamodb:Query' - 'dynamodb:Scan' - 'dynamodb:UpdateItem' Effect: Allow Resource: - !Join - '' - - 'arn:' - !Ref Partition - ':dynamodb:*:' - !Ref 'AWS::AccountId' - ':table/*-stack-AWSEBWorkerCronLeaderRegistry*' - Sid: MetricsAccess Action: - 'cloudwatch:PutMetricData' Effect: Allow Resource: '*' Path: /

另请参阅