AWS::ElasticBeanstalk::Environment - AWS CloudFormation
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

AWS::ElasticBeanstalk::Environment

AWS::ElasticBeanstalk::Environment 资源是指定 Elastic Beanstalk 环境的 AWS Elastic Beanstalk 资源类型。

语法

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

JSON

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

YAML

Type: AWS::ElasticBeanstalk::Environment Properties: ApplicationName: String CNAMEPrefix: String Description: String EnvironmentName: String OptionSettings: - OptionSetting PlatformArn: String SolutionStackName: String Tags: - Tag TemplateName: String Tier: Tier VersionLabel: String

属性

ApplicationName

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

必需:是

类型:字符串

最低1

最高100

Update requires: Replacement

CNAMEPrefix

如果已指定,则环境会尝试将此值用作 Elastic Beanstalk 环境 URL 中 CNAME 的前缀。如果未指定,则通过将随机字母数字字符串附加到环境名称来自动生成 CNAME。

必需:否

类型:字符串

最低4

最高63

Update requires: Replacement

Description

此环境的描述。

必需:否

类型:字符串

最高200

Update requires: No interruption

EnvironmentName

环境的唯一名称。

约束:长度必须在 4 到 40 个字符之间。名称只能包含字母、数字和连字符。它不能以连字符开头或结尾。此名称在您账户中的某个区域内必须是唯一的。

如果未指定 CNAMEPrefix 参数,环境变量会成为别名记录的一部分,因此它也会成为应用程序的可见 URL 的一部分。

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

重要

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

必需:否

类型:字符串

最低4

最高40

Update requires: Replacement

OptionSettings

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

必需:否

类型OptionSetting 的列表

Update requires: No interruption

PlatformArn

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

注意

如果您指定 PlatformArn,请不要指定 SolutionStackName

必需:否

类型:字符串

Update requires: No interruption

SolutionStackName

要用于环境的 Elastic Beanstalk 解决方案堆栈的名称(平台版本)。如已指定,Elastic Beanstalk 会将配置值设置为与指定的解决方案堆栈相关联的默认值。有关当前解决方案堆栈的列表,请参阅 AWS Elastic Beanstalk 平台 指南中的 Elastic Beanstalk 支持的平台

注意

如果您指定 SolutionStackName,请不要指定 PlatformArnTemplateName

必需:否

类型:字符串

Update requires: Replacement

Tags

指定应用于环境中的资源的标签。

必需:否

类型Tag 的列表

Update requires: No interruption

TemplateName

要用于环境的 Elastic Beanstalk 配置模板的名称。

注意

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

必需:否

类型:字符串

最低1

最高100

Update requires: No interruption

Tier

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

必需:否

类型Tier

Update requires: Some interruptions

VersionLabel

要部署的应用程序版本的名称。

默认:如果未指定,Elastic Beanstalk 将尝试部署示例应用程序。

必需:否

类型:字符串

最低1

最高100

Update requires: No interruption

返回值

Ref

When the logical ID of this resource is provided to the Ref intrinsic function, Ref returns the resource name.

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

Fn::GetAtt

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

有关使用 Fn::GetAtt 内部函数的更多信息,请参阅 Fn::GetAtt

EndpointURL

对于负载均衡的 Auto Scaling 环境,则为指向负载均衡器的 URL。对于单实例环境,则为实例的 IP 地址。

示例负载均衡器 URL:

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

示例实例 IP 地址:

192.0.2.0

示例

简单环境

JSON

{ "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

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

{ "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

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

{ "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

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: /

另请参阅