ALIYUN::OSS::Bucket

ALIYUN::OSS::Bucket类型用于创建OSS存储空间。

语法

{
  "Type": "ALIYUN::OSS::Bucket",
  "Properties": {
    "AccessControl": String,
    "RefererConfiguration": Map,
    "ServerSideEncryptionConfiguration": Map,
    "CORSConfiguration": Map,
    "Tags": Map,
    "LoggingConfiguration": Map,
    "LifecycleConfiguration": Map,
    "StorageClass": String,
    "DeletionForce": Boolean,
    "Policy": Map,
    "BucketName": String,
    "RedundancyType": String,
    "VersioningConfiguration": Map,
    "ResourceGroupId": String,
    "EnableOssHdfsService": Boolean,
    "WebsiteConfigurationV2": Map,
    "BlockPublicAccess": Boolean
  }
}

属性

属性名称

类型

必须

允许更新

描述

约束

BucketName

String

存储空间名称。

长度为3~63个字符。必须以小写英文字母或数字开头和结尾,可包含小写英文字母、数字和短划线(-)。

说明

此名称要求全局唯一,可以通过使用AssociationProperty中的AutoCompleteInput自动生成随机字符串。更多信息,请参见如何控制随机字符串的长度?

AccessControl

String

访问权限。

取值:

  • private(默认值):私有。

  • public-read:公共读。

  • public-read-write:公共读写。

CORSConfiguration

Map

跨域访问配置。

更多信息,请参见CORSConfiguration属性

DeletionForce

Boolean

是否强制删除OSS中的文件。

取值:

  • true:强制删除。

  • false(默认值):不强制删除。

EnableOssHdfsService

Boolean

是否开启OSS-HDFS服务。

取值:

  • true:开启OSS-HDFS服务。

    说明

    一旦启用,它不能再被禁用。

  • false:不开启OSS-HDFS服务。 

BlockPublicAccess

Boolean

是否为指定Bucket开启阻止公共访问。

取值:

  • true:开启阻止公共访问。

  • false(默认值):关闭阻止公共访问。

LifecycleConfiguration

Map

文件生命周期配置。

更多信息,请参见LifecycleConfiguration属性

LoggingConfiguration

Map

日志存储配置。

更多信息,请参见LoggingConfiguration属性

Policy

Map

存储空间策略。

更多信息,请参见Bucket Policy常见示例

RedundancyType

String

Bucket的数据容灾类型。

取值:

  • LRS(默认) :本地冗余LRS,将您的数据冗余存储在同一个可用区的不同存储设备上,可支持两个存储设备并发损坏时,仍维持数据不丢失,可正常访问。

  • ZRS:同城冗余ZRS,采用多可用区(AZ)机制,将您的数据冗余存储在同一地域(Region)的3个可用区。可支持单个可用区(机房)整体故障时(例如断电、火灾等),仍然能够保障数据的正常访问。

RefererConfiguration

Map

防盗链配置。

更多信息,请参见RefererConfiguration属性

ResourceGroupId

String

资源组ID。

ServerSideEncryptionConfiguration

Map

服务端加密规则配置。

更多信息,请参见ServerSideEncryptionConfiguration属性

StorageClass

String

存储空间类型。

取值:

  • Standard(默认值):标准存储。

  • IA:低频访问。

  • Archive:归档存储。

Tags

Map

存储空间标签。Key-Value形式的键值对。

最多设置20个标签。

Key长度为1~64个字符,不能以http://https://Aliyun开头。

Value长度为0~128个字符,必须为UTF-8编码。

VersioningConfiguration

Map

保存版本控制状态的容器。

更多信息,请参见VersioningConfiguration属性

WebsiteConfigurationV2

Map

网站配置。

更多信息,请参见WebsiteConfigurationV2属性

CORSConfiguration语法

"CORSConfiguration": {
  "CORSRule": List,
  "ResponseVary": Boolean
}

CORSConfiguration属性

属性名称

类型

必须

允许更新

描述

约束

CORSRule

List

跨域访问规则。

更多信息,请参见CORSRule属性

ResponseVary

Boolean

是否返回Vary: Origin头部。

其取值范围如下:

  • true:无论是否发送了跨域请求,或者跨域请求是否成功,都返回Vary: Origin头部。

  • false(默认):在任何情况下都不返回Vary: Origin头部。

说明

注意:此字段不能单独配置;必须至少配置一条跨域规则才能生效。

CORSRule语法

"CORSRule": [
  {
    "MaxAgeSeconds": Number,
    "AllowedMethod": List,
    "ExposeHeader": List,
    "AllowedOrigin": List,
    "AllowedHeader": List
  }
]

CORSRule属性

属性名称

类型

必须

允许更新

描述

约束

AllowedHeader

List

允许的跨域请求Header。

取值:

  • *

  • Cache-Control

  • Content-Language

  • Content-Type

  • Expires

  • Last-Modified

  • Pragma

AllowedMethod

List

允许的跨域请求的方法。

取值:

  • *

  • GET

  • PUT

  • POST

  • DELETE

  • HEAD

AllowedOrigin

List

允许的跨域请求的来源。

ExposeHeader

List

允许用户从应用程序中访问的响应头。

不允许使用星号(*)。

MaxAgeSeconds

Number

浏览器对特定资源的OPTIONS请求返回结果的缓存时间。

LifecycleConfiguration语法

"LifecycleConfiguration": {
  "Rule": List
}

LifecycleConfiguration属性

属性名称

类型

必须

允许更新

描述

约束

Rule

List

生命周期规则。

更多信息,请参见Rule属性

Rule语法

"Rule": [
  {
    "Status": String,
    "AbortMultipartUpload": Map,
    "Expiration": Map,
    "Prefix": String,
    "ID": String,
    "Filter": Map,
    "Transition": List
  }
]

Rule属性

属性名称

类型

必须

允许更新

描述

约束

Prefix

String

规则所适用的前缀。

只有匹配前缀的对象才可能被该规则所影响。

AbortMultipartUpload

Map

未完成分片上传的过期属性。

更多信息,请参见AbortMultipartUpload属性

Expiration

Map

对象规则的过期属性。

更多信息,请参见Expiration属性

ID

String

规则的唯一ID。

最长为255字符。当没有指定ID或者ID为空时,OSS会自动生成一个唯一值。

Status

String

启用或停用规则。

取值:

  • Enabled:启用规则。

  • Disabled:停用规则。

Filter

Map

这条排除规则最多只有一个条件规则。

更多信息,请参见Filter属性

Transition

List

存储冗余转换任务列表

更多信息,请参考Transition属性

Transition语法

"Transition": [
    {
      "CreatedBeforeDate": String,
      "Days": Integer,
      "IsAccessTime": Boolean,
      "ReturnToStdWhenVisit": Boolean,
      "AllowSmallFile": Boolean,
      "StorageClass": String
    }
 ]

Transition属性

属性名称

类型

必须

允许更新

描述

约束

CreatedBeforeDate

String

指定一个日期;OSS 将对最后修改时间早于该日期的数据应用生命周期规则。

该日期必须符合 ISO8601 格式,且必须为 UTC 时间的午夜(即 00:00:00)。
示例值:2002-10-11T00:00:00.000Z

Days

Integer

指定对象最后一次更新后多少天生效生命周期规则。

取值范围:正整数(例如:30、90、180 等)。

IsAccessTime

Boolean

指定生命周期规则是否基于对象的最后访问时间来应用。

  • true:表示规则根据对象的最后访问时间生效。

  • false:表示规则不基于最后访问时间,而是基于其他条件(如创建时间或修改时间)。

ReturnToStdWhenVisit

Boolean

指定是否在非标准类型对象被访问后,将其存储类别恢复为标准类型。

此选项仅在将 IsAccessTime 元素设置为 true 时生效。

AllowSmallFile

Boolean

指定是否根据对象的最后访问时间。

将其存储类别更改为 IA、归档(Archive)或冷归档(Cold Archive),前提是对象大小小于 64 KB。

StorageClass

String

对象被更改后的存储类别。

取值:

  • IA

  • Archive

  • ColdArchive

  • DeepColdArchive

Filter语法

"Filter":{
  "Not": Map
}

Filter属性

属性名称

类型

必须

允许更新

描述

约束

Not

Map

排除规则

更多信息,请参见Not属性

Not语法

"Not":{
  "Tag": List,
  "Prefix": String
}

Not属性

属性名称

类型

必须

允许更新

描述

约束

Tag

List

排除规则的标签。

这条排除规则最多适用于一个对象标签。

Prefix

String

规则前缀。

此排除规则所适用的对象前缀条件如下:

  • 如果在规则(Rule)节点下配置了前缀(Prefix),那么在非(Not)节点下的前缀必须以规则节点下配置的前缀为开头。例如,如果在规则节点下配置的前缀是dir,则非节点下配置的前缀必须以dir开头,如dir1dir2等。

  • 如果在非(Not)节点下没有配置标签(Tag),那么非节点下配置的前缀不能与规则节点下配置的前缀相同。

简而言之,这条规则说明了在设置排除规则时,如果上级规则定义了一个前缀,那么下属的非规则内的前缀必须是上级前缀的子集或具体化,且不能完全相同(除非使用了标签配置)。这样设计是为了实现更细致和灵活的文件或对象筛选逻辑,特别是在云存储、数据备份或内容过滤等场景中。

Expiration语法

"Expiration":{
  "Days": Number,
  "CreatedBeforeDate": String,
  "ExpiredObjectDeleteMarker": Boolean
}

Expiration属性

属性名称

类型

必须

允许更新

描述

约束

CreatedBeforeDate

String

指定一个日期,OSS会对最后更新日期早于该日期的数据执行规则。

日期必须服从ISO8601的格式,且要求是UTC的零点。例如:2002-10-11T00:00:00.000Z

Days

Number

对象最后修改后,规则将在多少天后生效。

以文件最后修改时间为起点开始计算,超过设定天数时即执行规则,则将对象删除。如果设置时间为30天,则最后修改日期为20160101日的对象会在20160131日被后端程序删除。

ExpiredObjectDeleteMarker

Boolean

指定是否应自动删除过期的删除标签。

有效值如下:

  • true:这意味着过期删除标记将自动被移除。当设置为true时,指定DaysCreatedBeforeDate是不被支持的。

  • false:这表示过期删除标记不会被自动移除。当设为false时,必须指定DaysCreatedBeforeDate中的一个。

AbortMultipartUpload语法

"AbortMultipartUpload": {
  "CreatedBeforeDate": String,
  "Days": Number
}

AbortMultipartUpload属性

属性名称

类型

必须

允许更新

描述

约束

CreatedBeforeDate

String

规则在何时之前生效。

日期为ISO8601的格式,并且值为UTC的零点。例如:2002-10-11T00:00:00.000Z

Days

Number

对象最后修改后,规则会在多少天后生效。

以文件最后修改时间为起点开始计算,超过设定天数时即执行规则,则将对象删除。如果设置时间为30天,则最后修改日期为20160101日的对象会在20160131日被后端程序删除。

LoggingConfiguration语法

"LoggingConfiguration": {
  "TargetBucket": String,
  "TargetPrefix": String
}

LoggingConfiguration属性

属性名称

类型

必须

允许更新

描述

约束

TargetBucket

String

存放访问日志的存储空间。

TargetPrefix

String

最终被保存的访问日志文件前缀。

WebsiteConfigurationV2语法

"WebsiteConfiguration":{
  "RoutingRules": List,
  "IndexDocument": Map,
  "ErrorDocument": Map
}

WebsiteConfigurationV2属性

属性名称

类型

必须

允许更新

描述

约束

ErrorDocument

Map

托管的静态错误页。

IndexDocument

Map

托管的静态首页。

RoutingRules

List

路由规则列表。

最大长度20。

IndexDocument语法

"IndexDocument":{
  "Suffix": String,
  "Type": String,
  "SupportSubDir": String
}

IndexDocument属性

属性名称

类型

必须

允许更新

描述

约束

Suffix

String

默认首页。

设置默认首页后,如果您访问以正斜杠(/)结尾的对象,OSS将返回到此默认首页。

Type

String

当设置默认首页后,尝试访问以非正斜杠(/)结尾且不存在的对象时的行为如下。

此规则仅在SupportSubDir设置为true时生效,并且在RoutingRule之后、ErrorFile之前生效。假设默认首页文件为index.html,当访问的文件路径为bucket.oss-cn-hangzhou.aliyuncs.com/abc,且对象ABC不存在时,针对Type不同值的行为如下:

  • 0(默认):检查abc/index.html是否存在(对象加上正斜杠(/)再加上首页名称),如果存在,则返回302重定向状态码,并在Location头部中设置URL代码为/abc/(正斜杠(/)加上对象名再加正斜杠(/))。如果不存在,则返回404错误,并继续检查ErrorFile。

  • 1:直接返回404错误,错误类型为NoSuchKey,然后继续检查ErrorFile。

  • 2:检查abc/index.html是否存在,如果存在则直接返回该对象的内容。如果不存在,则返回404错误,并继续检查ErrorFile。

SupportSubDir

String

当访问一个子目录时,是否跳转到该子目录的默认主页。

可选范围如下:

  • true:跳转到子目录下的默认主页。

  • false(默认):不跳转到子目录下的默认主页,而是前往根目录下的默认主页。假设默认主页为index.html,如果访问bucket.oss-cn-hangzhou.aliyuncs.com/subdir/时,将SupportSubDir设置为false,则会重定向到bucket.oss-cn-hangzhou.aliyuncs.com/index.html;如果将SupportSubDir设置为true,则会重定向到bucket.oss-cn-hangzhou.aliyuncs.com/subdir/index.html。

RoutingRules语法

"RoutingRules":[{
  "Redirect": Map,
  "Condition": Map,
  "RuleNumber": Integer
}]

RoutingRules属性

属性名称

类型

必须

允许更新

描述

约束

Redirect

Map

指定当此规则被匹配时要执行的操作。

更多信息,请参见Redirect属性

Condition

Map

匹配条件。

此规则仅在满足指定的所有项目时执行。只有当此容器下的每个节点的所有条件都得到满足时,才视为匹配成功。更多信息,请参见Condition属性

RuleNumber

Integer

匹配并执行RoutingRule的序列号,OSS将根据此序列号顺序匹配规则。

如果匹配成功,则执行此规则并且不再执行后续规则。

Condition语法

"Condition":{
  "KeyPrefixEquals": String,
  "HttpErrorCodeReturnedEquals": String,
  "IncludeHeaders": List,
  "KeySuffixEquals": String
}

Condition属性

属性名称

类型

必须

允许更新

描述

约束

KeyPrefixEquals

String

要匹配的对象名称的前缀。

无。

HttpErrorCodeReturnedEquals

String

当访问指定的对象时,为了符合此规则,必须返回此状态。

当跳转规则镜像回源类型时,此字段必须为404。

IncludeHeaders

List

此规则仅当请求中包含指定的头部且其值为指定的值时才会匹配。

最多可设置10个这样的条件。更多信息,请参见IncludeHeaders属性

KeySuffixEquals

String

要匹配的对象名称的后缀。

无。

IncludeHeaders语法

"IncludeHeaders": [
  {
    "Equals": String,
    "Key": String
  }
]

IncludeHeaders属性

属性名称

类型

必须

允许更新

描述

约束

Equals

String

头部的值。

Key

String

头标的名称。

RefererConfiguration语法

"RefererConfiguration":{
  "AllowEmptyReferer": String,
  "RefererList": List
}

RefererConfiguration属性

属性名称

类型

必须

允许更新

描述

约束

AllowEmptyReferer

Boolean

是否允许referer字段为空的请求访问。

取值:

  • true(默认值):允许。

  • false:不允许。

RefererList

List

允许referer字段的白名单。

Redirect语法

"Redirect":{
  "MirrorFollowRedirect": Boolean,
  "MirrorURL": String,
  "PassQueryString": Boolean,
  "MirrorPassQueryString": Boolean,
  "ReplaceKeyWith": String,
  "Protocol": String,
  "HttpRedirectCode": String,
  "ReplaceKeyPrefixWith": String,
  "RedirectType": String,
  "MirrorHeaders": Map,
  "MirrorCheckMd5": Boolean,
  "EnableReplacePrefix": Boolean,
  "HostName": String
}

Redirect属性

属性名称

类型

必须

允许更新

描述

约束

MirrorFollowRedirect

Boolean

当镜像回源后得到的结果是3xx状态码时,是否继续跳转到指定的Location以获取数据。

此设置仅在RedirectType设置为Mirror时生效。例如,当我们镜像请求回到源站时,源站返回了一个带有Location信息的302状态码。

  • 如果设置为true,OSS将继续请求该Location指向的地址。这个过程最多可以跳转10次,超过10次后,镜像回源将失败并返回错误。

  • 如果设置为false,OSS将直接返回302状态码,并将Location信息透传给客户端,由客户端决定是否继续跳转。

    默认值为:true。

MirrorURL

String

镜像回源站地址。

此设置仅在RedirectType配置为Mirror时生效。起源网址必须以http://或https://开头,并以正斜杠(/)结尾,OSS会在此基础上拼接上对象名称来构成返回的URL。例如,若要访问的对象名为myobject,当您将其设置为http://example.com/时,回源URL将会是http://example.com/myobject;如果设置为http://example.com/dir1/,则回源URL将会是http://example.com/dir1/myobject。

PassQueryString

Boolean

当执行跳转或回源镜像时,是否携带请求参数。

即用户以请求参数a=b&c=d的形式访问OSS,并设置PassQueryStringtrue时,若规则类型为302跳转,则此请求参数会附加在跳转的Location头部中,例如Location:example.com?a=b&c=d;若规则类型为镜像回源,则此请求参数也会被携带在发起的回源请求中。有效值:true、false(默认)。

MirrorPassQueryString

Boolean

PassQueryString相同,但优先于PassQueryString。此设置仅在RedirectType设置为Mirror时有效。

默认值:false。

ReplaceKeyWith

String

使用Redirect规则时,对象名称将被ReplaceKeyWith指定的值替换,这使得您可以设置变量。

目前支持的变量是{key},它代表请求中的对象名称。假设要访问名为test的对象,如果将ReplaceKeyWith设置为prefix/{key}。那么,后缀将指向http://example.com/prefix/test.suffixLocation头部。

这意味着,当客户端请求原始对象(例如,test)时,服务器会通过Redirect规则将其重定向到一个新位置,该位置的路径由ReplaceKeyWith定义的模式动态生成。在这个例子中,新路径会在“prefix/”后面加上原始对象名(即test),最终重定向的URL变为"http://example.com/prefix/test.suffix"。这里的".suffix"是您提到的后缀部分,按照您的描述它似乎是固定不变的,而"${key}"则成功地被对象名“test”替换。

Protocol

String

当执行跳转时的协议规范。

该规则仅在RedirectType设置为ExternalAliCDN的情况下适用。假如您希望访问的文件是“test”,并且想要将其重定向至“example.com”,同时指定协议为https,那么在HTTP响应中的Location头部应设置为"https://example.com/test"。可选的协议值有:http, https。

HttpRedirectCode

String

当进行跳转时返回的状态码。

仅当RedirectType设置为ExternalAliCDN时适用。默认值为302。可选值:301、302、307。

ReplaceKeyPrefixWith

String

该值将替代重定向中对象名称的前缀。如果前缀为空,则此字符串将在对象名称之前插入。

说明

注意:仅允许使用ReplaceKeyWithReplaceKeyPrefixWith节点。假设要访问的对象为ABC/test.TXT,如果设置了KeyPrefixEqualsABC/,并且ReplaceKeyPrefixWithdef/,那么定位(Location)将指向http://example.com/def/test.txt。

RedirectType

String

指定跳转的类型。

可选范围如下:

  • 镜像(Mirror):回源镜像,即反射回源站。

  • 外部(External):外部分支,即OSS会返回一个3xx状态码的请求,指示将分支指向另一个地址。

  • 阿里云CDN(AliCDN):阿里云CDN跳转,主要用于阿里云的内容分发网络。与“外部”不同的是,OSS会添加一个额外的头部信息。阿里云CDN识别到这个头部后,会主动跳转到指定的地址,并将获取的数据返回给用户,而不是向用户返回3xx的跳转请求。

MirrorHeaders

Map

指定回传到源端时被镜像的头部。

此设置仅在RedirectType被设置为Mirror时生效。更多信息,请参见MirrorHeaders属性

MirrorCheckMd5

Boolean

是否回源检查MD5。

此配置仅在RedirectType设置为Mirror时生效。当MirrorCheckMd5设置为true时,如果源站返回的响应中包含Content-Md5头信息,OSS会检查拉取的数据MD5是否与该头信息匹配,如果不匹配,则不会将数据保存到OSS上。默认值:false。

EnableReplacePrefix

Boolean

如果将此字段设置为true,对象的前缀将被ReplaceKeyPrefixWith指定的值替换。如果未指定此字段或为空,则意味着对象的前缀将被截断。

注意:当ReplaceKeyWith字段不为空时,此字段不能设置为true。默认值:false。

HostName

String

跳转的域名。

该域名应遵循域名规范。如果要访问的文件名为test,并且协议设置为https,主机名设置为example.com,则Location头部应为https://example.com/test。

MirrorHeaders语法

"MirrorHeaders":{
  "Remove": List,
  "PassAll": Boolean,
  "Sets": List,
  "Pass": List
}

MirrorHeaders属性

属性名称

类型

必须

允许更新

描述

约束

Remove

List

禁用指定头部向源的透传。

这仅在将RedirectType设置为Mirror时有效。每个头部的长度最多为1,024字节,并且字符集包括0-9、a-z、A-Z和破折号(-)。此字段最多可以指定10个。

PassAll

Boolean

是否将除以下头部之外的其他头部传递给源。

这仅在将RedirectType设置为Mirror时有效。需要排除的头部包括:- content-length, authorization2, authorization, range, date以及其他的通用头部- 以oss-/x-oss-/x-drs-开头的特定头部

默认值为:false

这意味着,默认情况下,这些特定的头部会被传递到镜像源。如果需要修改此行为,可以将此设置调整为true,以不允许这些头部信息通过。

Sets

List

设置一个头部到源服务器,当请求被回传给源服务器时,该头部会被设置,无论指定的头部是否包含在请求中。

此功能仅在将RedirectType设置为Mirror时生效。此容器最多可以为10组头信息进行这样的设置。更多信息,请参见Sets属性

Pass

List

将指定的头部信息传递给源。

此操作仅在将RedirectType设置为镜像(Mirror)时有效。每个头部的最大长度为1,024字节,并且只能包含字符集0-9、a-z、A-Z和破折号(-)。此字段最多可以指定10个头部信息。

Sets语法

"Sets": [
  {
    "Value": String,
    "Key": String
  }
]

Sets属性

属性名称

类型

必须

允许更新

描述

约束

Value

String

将标头的值设置为最大1024字节,不包括\r\n。

此设置仅在RedirectType被设置为镜像(Mirror)时有效。

Key

String

将头部键设置为最大1024字节,使用的字符集与Pass相同。

此设置仅在RedirectType被设置为Mirror时有效。

ErrorDocument语法

"ErrorDocument":{
  "Key": String,
  "HttpStatus": String
}

ErrorDocument属性

属性名称

类型

必须

允许更新

描述

约束

Key

String

默认错误页面。

当指定了一个错误页面时,如果访问的对象不存在,将返回这个错误页面。

HttpStatus

String

错误页面的HTTP状态代码。

有效值:200、404(默认)。

ServerSideEncryptionConfiguration语法

"ServerSideEncryptionConfiguration":{
  "KMSMasterKeyID": String,
  "SSEAlgorithm": String
}

ServerSideEncryptionConfiguration属性

属性名称

类型

必须

允许更新

描述

约束

SSEAlgorithm

String

服务端默认加密方式。

取值:

  • KMS

  • AES256

KMSMasterKeyID

String

密钥ID。

只有当SSEAlgorithm值为KMS,且使用指定的密钥加密时,才需指定密钥ID。

VersioningConfiguration语法

"VersioningConfiguration":{
  "Status": String
}

VersioningConfiguration属性

属性名称

类型

必须

允许更新

描述

约束

Status

String

版本控制状态。

取值:

  • Enabled:开启版本控制状态

  • Suspended:暂停版本控制状态

返回值

Fn::GetAtt

  • Name:存储空间名称,全局唯一。

  • DomainName:通过公网访问存储空间的域名。

  • InternalDomainName:通过内网访问存储空间的域名。

  • Arn:阿里云资源名称。

示例

场景 1 :创建OSS存储空间(Bucket)。

ROSTemplateFormatVersion: '2015-09-01'
Description: Creates a simple oss bucket
Parameters:
  BucketName:
    AssociationProperty: AutoCompleteInput
    AssociationPropertyMetadata:
      Length: 5
      Prefix: simple-oss-bucket
      CharacterClasses:
        - Class: lowercase
          min: 1
    Type: String
    Label:
      en: Bucket Name
Outputs:
  BucketDomainName:
    Value:
      Fn::GetAtt:
        - MyBucket
        - DomainName
Resources:
  MyBucket:
    Type: ALIYUN::OSS::Bucket
    Properties:
      AccessControl: private
      BucketName:
        Ref: BucketName
Metadata: {}
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": "Creates a simple oss bucket",
  "Parameters": {
    "BucketName": {
      "Type": "String",
      "Label": {
        "en": "Bucket Name"
      },
      "AssociationProperty": "AutoCompleteInput",
      "AssociationPropertyMetadata": {
        "Length": 5 ,
        "Prefix": "simple-oss-bucket",
        "CharacterClasses": [
          {
            "Class": "lowercase",
            "min": 1
          }
        ]
      }
    }
  },
  "Metadata": {
  },
  "Resources": {
    "MyBucket": {
      "Type": "ALIYUN::OSS::Bucket",
      "Properties": {
        "AccessControl": "private",
        "BucketName": {
          "Ref": "BucketName"
        }
      }
    }
  },
  "Outputs": {
    "BucketDomainName": {
      "Value": {
        "Fn::GetAtt": [
          "MyBucket",
          "DomainName"
        ]
      }
    }
  }
}

场景 2 :创建OSS存储桶并启用CDN加速,配置域名解析与优化文件分发策略,支持全球访问与自定义缓存规则。

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 创建OSS存储桶并启用CDN加速,配置域名解析与优化文件分发策略,支持全球访问与自定义缓存规则。
  en: Create an OSS bucket and enable CDN acceleration, configure domain name resolution, and optimize file distribution strategies to support global access and custom caching rules.
Parameters:
  Scope:
    Type: String
    Label:
      zh-cn: 加速区域
      en: Acceleration area
    Description:
      zh-cn: 选择加速区域。加速区域为仅中国内地和全球时,服务域名必须备案。
      en: Select the acceleration area. When the acceleration region is only in mainland China and the world, the service domain name must be filed.
    Default: domestic
    AllowedValues:
      - domestic
      - overseas
      - global
  DomainName:
    Type: String
    Label:
      zh-cn: 加速域名
      en: Accelerated domain name
    Description:
      zh-cn: 加速域名是指接入CDN,用于加速源站的域名。请填写您账号下的域名。
      en: Accelerated domain name refers to the domain name of the access CDN used to accelerate the source site. Please fill in the domain name under your account.
  BucketName:
    Type: String
    Label:
      en: Bucket Name
      zh-cn: 存储空间名称
    Description:
      en: The name must be 3 to 63 bytes in length, The name must start and end with a lowercase letter or digit.The name can contain only lowercase letters, digits, and hyphens (-).;<br><b>note:<font color='blue'>A bucket name must be globally unique within OSS. Bucket names cannot be changed after the bucket is created.</b></font>
      zh-cn: 长度为3~63个字符,必须以小写字母或数字开头和结尾,可以包含小写字母、数字和连字符(-);<br><b>注:<font color='blue'>需要全网唯一性,已经存在的不能在创建。</b></font>
    AssociationProperty: AutoCompleteInput
    AssociationPropertyMetadata:
      Length: 6
      Prefix: image-example-
      CharacterClasses:
        - Class: lowercase
          min: 1
Resources:
  OssBucket:
    Type: ALIYUN::OSS::Bucket
    DependsOn: AutoEnableOSS
    Properties:
      BucketName:
        Ref: BucketName
      DeletionForce: true
  AutoEnableCDN:
    Type: ALIYUN::ROS::AutoEnableService
    Properties:
      ServiceName: CDN
  AutoEnableOSS:
    Type: ALIYUN::ROS::AutoEnableService
    Properties:
      ServiceName: OSS
  Domain:
    Type: ALIYUN::CDN::Domain
    Properties:
      Sources:
        Fn::Sub:
          - '[{"content":"${content}", "type":"oss", "priority":"20", "port":80, "weight":"10"}]'
          - content:
              Fn::GetAtt:
                - OssBucket
                - DomainName
      CdnType: web
      Scope:
        Ref: Scope
      DomainName:
        Ref: DomainName
    DependsOn: AutoEnableCDN
  DomainRecord:
    Type: ALIYUN::DNS::DomainRecord
    Properties:
      Type: CNAME
      RR:
        Fn::Select:
          - 0
          - Fn::Split:
              - .
              - Ref: DomainName
      Value:
        Fn::GetAtt:
          - Domain
          - Cname
      DomainName:
        Fn::Join:
          - .
          - Fn::Select:
              - '1:'
              - Fn::Split:
                  - .
                  - Ref: DomainName
    DependsOn: Domain
  DomainConfig:
    Type: ALIYUN::CDN::DomainConfig
    Properties:
      FunctionList:
        - FunctionArgs:
            - ArgName: file_type
              ArgValue: jpg,png,jpeg
            - ArgName: weight
              ArgValue: '99'
            - ArgName: ttl
              ArgValue: '7776000'
          FunctionName: filetype_based_ttl_set
        - FunctionArgs:
            - ArgName: private_oss_auth
              ArgValue: 'on'
            - ArgName: perm_private_oss_tbl
              ArgValue: ''
          FunctionName: l2_oss_key
        - FunctionArgs:
            - ArgName: filetype
              ArgValue: jpeg
            - ArgName: webp
              ArgValue: 'off'
            - ArgName: orient
              ArgValue: 'off'
            - ArgName: slim
              ArgValue: '90'
            - ArgName: enable
              ArgValue: 'on'
          FunctionName: image_transform
      DomainNames:
        Ref: Domain
    DependsOn: DomainRecord
Outputs:
  Cname:
    Description: CNAME
    Value:
      Fn::GetAtt:
        - Domain
        - Cname
  DomainName:
    Description: DomainName
    Value:
      Ref: Domain
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - Scope
          - DomainName
          - BucketName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "创建OSS存储桶并启用CDN加速,配置域名解析与优化文件分发策略,支持全球访问与自定义缓存规则。",
    "en": "Create an OSS bucket and enable CDN acceleration, configure domain name resolution, and optimize file distribution strategies to support global access and custom caching rules."
  },
  "Parameters": {
    "Scope": {
      "Type": "String",
      "Label": {
        "zh-cn": "加速区域",
        "en": "Acceleration area"
      },
      "Description": {
        "zh-cn": "选择加速区域。加速区域为仅中国内地和全球时,服务域名必须备案。",
        "en": "Select the acceleration area. When the acceleration region is only in mainland China and the world, the service domain name must be filed."
      },
      "Default": "domestic",
      "AllowedValues": [
        "domestic",
        "overseas",
        "global"
      ]
    },
    "DomainName": {
      "Type": "String",
      "Label": {
        "zh-cn": "加速域名",
        "en": "Accelerated domain name"
      },
      "Description": {
        "zh-cn": "加速域名是指接入CDN,用于加速源站的域名。请填写您账号下的域名。",
        "en": "Accelerated domain name refers to the domain name of the access CDN used to accelerate the source site. Please fill in the domain name under your account."
      }
    },
    "BucketName": {
      "Type": "String",
      "Label": {
        "en": "Bucket Name",
        "zh-cn": "存储空间名称"
      },
      "Description": {
        "en": "The name must be 3 to 63 bytes in length, The name must start and end with a lowercase letter or digit.The name can contain only lowercase letters, digits, and hyphens (-).;<br><b>note:<font color='blue'>A bucket name must be globally unique within OSS. Bucket names cannot be changed after the bucket is created.</b></font>",
        "zh-cn": "长度为3~63个字符,必须以小写字母或数字开头和结尾,可以包含小写字母、数字和连字符(-);<br><b>注:<font color='blue'>需要全网唯一性,已经存在的不能在创建。</b></font>"
      },
      "AssociationProperty": "AutoCompleteInput",
      "AssociationPropertyMetadata": {
        "Length": 6,
        "Prefix": "image-example-",
        "CharacterClasses": [
          {
            "Class": "lowercase",
            "min": 1
          }
        ]
      }
    }
  },
  "Resources": {
    "OssBucket": {
      "Type": "ALIYUN::OSS::Bucket",
      "DependsOn": "AutoEnableOSS",
      "Properties": {
        "BucketName": {
          "Ref": "BucketName"
        },
        "DeletionForce": true
      }
    },
    "AutoEnableCDN": {
      "Type": "ALIYUN::ROS::AutoEnableService",
      "Properties": {
        "ServiceName": "CDN"
      }
    },
    "AutoEnableOSS": {
      "Type": "ALIYUN::ROS::AutoEnableService",
      "Properties": {
        "ServiceName": "OSS"
      }
    },
    "Domain": {
      "Type": "ALIYUN::CDN::Domain",
      "Properties": {
        "Sources": {
          "Fn::Sub": [
            "[{\"content\":\"${content}\", \"type\":\"oss\", \"priority\":\"20\", \"port\":80, \"weight\":\"10\"}]",
            {
              "content": {
                "Fn::GetAtt": [
                  "OssBucket",
                  "DomainName"
                ]
              }
            }
          ]
        },
        "CdnType": "web",
        "Scope": {
          "Ref": "Scope"
        },
        "DomainName": {
          "Ref": "DomainName"
        }
      },
      "DependsOn": "AutoEnableCDN"
    },
    "DomainRecord": {
      "Type": "ALIYUN::DNS::DomainRecord",
      "Properties": {
        "Type": "CNAME",
        "RR": {
          "Fn::Select": [
            0,
            {
              "Fn::Split": [
                ".",
                {
                  "Ref": "DomainName"
                }
              ]
            }
          ]
        },
        "Value": {
          "Fn::GetAtt": [
            "Domain",
            "Cname"
          ]
        },
        "DomainName": {
          "Fn::Join": [
            ".",
            {
              "Fn::Select": [
                "1:",
                {
                  "Fn::Split": [
                    ".",
                    {
                      "Ref": "DomainName"
                    }
                  ]
                }
              ]
            }
          ]
        }
      },
      "DependsOn": "Domain"
    },
    "DomainConfig": {
      "Type": "ALIYUN::CDN::DomainConfig",
      "Properties": {
        "FunctionList": [
          {
            "FunctionArgs": [
              {
                "ArgName": "file_type",
                "ArgValue": "jpg,png,jpeg"
              },
              {
                "ArgName": "weight",
                "ArgValue": "99"
              },
              {
                "ArgName": "ttl",
                "ArgValue": "7776000"
              }
            ],
            "FunctionName": "filetype_based_ttl_set"
          },
          {
            "FunctionArgs": [
              {
                "ArgName": "private_oss_auth",
                "ArgValue": "on"
              },
              {
                "ArgName": "perm_private_oss_tbl",
                "ArgValue": ""
              }
            ],
            "FunctionName": "l2_oss_key"
          },
          {
            "FunctionArgs": [
              {
                "ArgName": "filetype",
                "ArgValue": "jpeg"
              },
              {
                "ArgName": "webp",
                "ArgValue": "off"
              },
              {
                "ArgName": "orient",
                "ArgValue": "off"
              },
              {
                "ArgName": "slim",
                "ArgValue": "90"
              },
              {
                "ArgName": "enable",
                "ArgValue": "on"
              }
            ],
            "FunctionName": "image_transform"
          }
        ],
        "DomainNames": {
          "Ref": "Domain"
        }
      },
      "DependsOn": "DomainRecord"
    }
  },
  "Outputs": {
    "Cname": {
      "Description": "CNAME",
      "Value": {
        "Fn::GetAtt": [
          "Domain",
          "Cname"
        ]
      }
    },
    "DomainName": {
      "Description": "DomainName",
      "Value": {
        "Ref": "Domain"
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "Scope",
            "DomainName",
            "BucketName"
          ]
        }
      ]
    }
  }
}

场景 3 :创建ECS实例、OSS存储桶,安装应用,实现文本绘图与人像美化服务。

ROSTemplateFormatVersion: '2015-09-01'
Mappings: {}
Parameters:
  DashScopeApiKey:
    NoEcho: true
    Label:
      zh-cn: DashScope API-KEY
      en: DashScope API-KEY
    Type: String
    Description:
      zh-cn: 开通灵积模型服务,并获得 API-KEY。请参考: <a href="https://help.aliyun.com/zh/dashscope/developer-reference/activate-dashscope-and-create-an-api-key"  target="_blank">开通DashScope并创建API-KEY</a>。
      en: 'Activate DashScope and obtain the API-KEY. Please refer to:  <a href="https://help.aliyun.com/zh/dashscope/developer-reference/activate-dashscope-and-create-an-api-key"  target="_blank">Activate DashScope and create API-KEY</a>.'
    AssociationProperty: ALIYUN::DashScope::ApiKey
  CommonName:
    Default: wanxiang
    Type: String
  InstancePassword:
    Description:
      zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
      en: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
    Default: Null
    Type: String
    Label:
      zh-cn: 实例密码
      en: Instance Password
    NoEcho: true
    AssociationProperty: ALIYUN::ECS::Instance::Password
    ConstraintDescription:
      zh-cn: 长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
      en: Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
  ZoneId:
    AssociationPropertyMetadata:
      AutoSelectFirst: true
    Default: Null
    Required: true
    Label:
      zh-cn: 可用区
      en: Availability Zone
    AssociationProperty: ALIYUN::ECS::Instance::ZoneId
    Type: String
  BucketName:
    AssociationPropertyMetadata:
      Length: 5
      Prefix: drawing-with-tongyi-wanxiang-
      CharacterClasses:
        - Class: lowercase
          min: 1
    Description:
      zh-cn: 3到63个字符,不以连字符(-)开头和结尾,可以包含小写字母、数字和连字符(-);<br>备注:<font color='blue'><b>需要保证整个网络的唯一性,已经存在的无法创建</b></font>
      en: '3 to 63 characters, not beginning and ending with a hyphen (-), can contain lowercase letters, Numbers and hyphens (-);<br>Note: <font color=''blue''><b>need whole network uniqueness, already existing can not be created.</b></font>'
    MinLength: 3
    Label:
      zh-cn: 存储空间名称
      en: Bucket Name
    AllowedPattern: ^[a-z0-9]+[a-z0-9\-]*[a-z0-9]+$
    Type: String
    MaxLength: 63
    AssociationProperty: AutoCompleteInput
    ConstraintDescription:
      zh-cn: 3 到 63 个字符,不以连字符 (-) 开头和结尾,可以包含小写字母、数字和连字符 (-)
      en: 3 to 63 characters, not beginning and ending with a hyphen (-), can contain lowercase letters, Numbers and hyphens (-)
  InstanceType:
    AssociationPropertyMetadata:
      SystemDiskCategory: cloud_essd
      InstanceChargeType: PostPaid
      ZoneId: ${ZoneId}
    Default: Null
    Required: true
    Label:
      zh-cn: 实例类型
      en: Instance Type
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    Type: String
Outputs:
  EcsLoginAddress:
    Description:
      zh-cn: ECS登录地址。
      en: Ecs login address.
    Value:
      Fn::Sub: https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs&regionId=${ALIYUN::Region}&instanceId=${EcsInstance}
  ExperienceAddress:
    Description:
      zh-cn: 体验地址。
      en: Experience address.
    Value:
      Fn::Sub:
        - http://${PublicIp}/wanx-demo
        - PublicIp:
            Fn::Select:
              - 0
              - Fn::GetAtt:
                  - EcsInstance
                  - PublicIps
Description:
  zh-cn: 创建VPC、ECS实例、OSS存储桶,配置安全组和RAM访问权限,安装Java与应用,实现文本绘图与人像美化服务。
  en: Create a Virtual Private Cloud (VPC), Elastic Compute Service (ECS) instances, Object Storage Service (OSS) buckets, configure Security Groups and Resource Access Management (RAM) permissions, install Java and applications, and implement text drawing and portrait beautification services.
Conditions: {}
Resources:
  CustomPolicy:
    Type: ALIYUN::RAM::ManagedPolicy
    Properties:
      PolicyName:
        Fn::Sub: create_by_solution-${ALIYUN::StackId}
      PolicyDocument:
        Version: '1'
        Statement:
          - Action:
              - oss:GetObject
              - oss:PutObject
            Resource:
              - Fn::Sub: acs:oss:oss-${ALIYUN::Region}:${ALIYUN::TenantId}:${BucketName}/*
            Effect: Allow
  InstallApp:
    Type: ALIYUN::ECS::RunCommand
    Properties:
      CommandContent:
        Fn::Sub: |-
          #!/bin/bash

          cat << EOF >> ~/.bash_profile
          export DASHSCOPE_API_KEY=${DashScopeApiKey}
          export OSS_ACCESS_KEY_ID=${AccessKey.AccessKeyId}
          export OSS_ACCESS_KEY_SECRET=${AccessKey.AccessKeySecret}
          export WANX_DEMO_OSS_BUCKET=${BucketName}
          export WANX_DEMO_OSS_ENDPOINT=https://oss-${ALIYUN::Region}.aliyuncs.com
          EOF

          source ~/.bash_profile 
          wget https://help-static-aliyun-doc.aliyuncs.com/demos/wanx-demo-0.0.1-SNAPSHOT.jar
          nohup java -jar wanx-demo-0.0.1-SNAPSHOT.jar > wanx-demo.log 2>&1 &
      Type: RunShellScript
      Sync: true
      InstanceIds:
        - Ref: EcsInstance
      Timeout: 3600
    DependsOn:
      - ModuleInstallJava.Install
  AccessKey:
    Type: ALIYUN::RAM::AccessKey
    Properties:
      UserName:
        Ref: User
  Bucket:
    Type: ALIYUN::OSS::Bucket
    Properties:
      BucketName:
        Ref: BucketName
      DeletionForce: true
  SecurityGroup:
    Type: ALIYUN::ECS::SecurityGroup
    Properties:
      SecurityGroupIngress:
        - PortRange: 80/80
          SourceCidrIp: 0.0.0.0/0
          IpProtocol: tcp
      VpcId:
        Ref: Vpc
      SecurityGroupName:
        Fn::Sub: ${CommonName}-sg
  ModuleInstallJava.Install:
    Type: ALIYUN::OOS::Execution
    Properties:
      SafetyCheck: Skip
      Parameters:
        action: install
        packageName: ACS-Extension-java-1853370294850618
        regionId:
          Ref: ALIYUN::Region
        targets:
          ResourceIds:
            - Ref: EcsInstance
          RegionId:
            Ref: ALIYUN::Region
          Type: ResourceIds
        parameters: Null
      TemplateName: ACS-ECS-BulkyConfigureOOSPackageWithTemporaryURL
    Metadata:
      ALIYUN::ROS::Module:
        LogicalIdHierarchy: ModuleInstallJava
        TypeHierarchy: MODULE::ACS::OOS::Extension
  User:
    Type: ALIYUN::RAM::User
    Properties:
      UserName:
        Fn::Sub: create_by_solution-${ALIYUN::StackId}
      PolicyAttachments:
        Custom:
          - Ref: CustomPolicy
  Vpc:
    Type: ALIYUN::ECS::VPC
    Properties:
      VpcName:
        Fn::Sub: ${CommonName}-vpc
      CidrBlock: 192.168.0.0/16
  VSwitch:
    Type: ALIYUN::ECS::VSwitch
    Properties:
      VSwitchName:
        Fn::Sub: ${CommonName}-vsw
      VpcId:
        Ref: Vpc
      CidrBlock: 192.168.0.0/24
      ZoneId:
        Ref: ZoneId
  EcsInstance:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      SystemDiskCategory: cloud_essd
      VpcId:
        Ref: Vpc
      SecurityGroupId:
        Ref: SecurityGroup
      ImageId: aliyun_3_9_x64_20G_alibase_
      InternetMaxBandwidthOut: 5
      VSwitchId:
        Ref: VSwitch
      Password:
        Ref: InstancePassword
      InstanceName:
        Fn::Sub: ${CommonName}-ecs
      InstanceType:
        Ref: InstanceType
      ZoneId:
        Ref: ZoneId
      MaxAmount: 1
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - DashScopeApiKey
          - BucketName
          - ZoneId
          - InstanceType
          - InstancePassword
    Hidden:
      - CommonName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Mappings": {},
  "Parameters": {
    "DashScopeApiKey": {
      "NoEcho": true,
      "Label": {
        "zh-cn": "DashScope API-KEY",
        "en": "DashScope API-KEY"
      },
      "Type": "String",
      "Description": {
        "zh-cn": "开通灵积模型服务,并获得 API-KEY。请参考: <a href=\"https://help.aliyun.com/zh/dashscope/developer-reference/activate-dashscope-and-create-an-api-key\"  target=\"_blank\">开通DashScope并创建API-KEY</a>。",
        "en": "Activate DashScope and obtain the API-KEY. Please refer to:  <a href=\"https://help.aliyun.com/zh/dashscope/developer-reference/activate-dashscope-and-create-an-api-key\"  target=\"_blank\">Activate DashScope and create API-KEY</a>."
      },
      "AssociationProperty": "ALIYUN::DashScope::ApiKey"
    },
    "CommonName": {
      "Default": "wanxiang",
      "Type": "String"
    },
    "InstancePassword": {
      "Description": {
        "zh-cn": "服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)",
        "en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)"
      },
      "Default": null,
      "Type": "String",
      "Label": {
        "zh-cn": "实例密码",
        "en": "Instance Password"
      },
      "NoEcho": true,
      "AssociationProperty": "ALIYUN::ECS::Instance::Password",
      "ConstraintDescription": {
        "zh-cn": "长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)",
        "en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)"
      }
    },
    "ZoneId": {
      "AssociationPropertyMetadata": {
        "AutoSelectFirst": true
      },
      "Default": null,
      "Required": true,
      "Label": {
        "zh-cn": "可用区",
        "en": "Availability Zone"
      },
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
      "Type": "String"
    },
    "BucketName": {
      "AssociationPropertyMetadata": {
        "Length": 5,
        "Prefix": "drawing-with-tongyi-wanxiang-",
        "CharacterClasses": [
          {
            "Class": "lowercase",
            "min": 1
          }
        ]
      },
      "Description": {
        "zh-cn": "3到63个字符,不以连字符(-)开头和结尾,可以包含小写字母、数字和连字符(-);<br>备注:<font color='blue'><b>需要保证整个网络的唯一性,已经存在的无法创建</b></font>",
        "en": "3 to 63 characters, not beginning and ending with a hyphen (-), can contain lowercase letters, Numbers and hyphens (-);<br>Note: <font color='blue'><b>need whole network uniqueness, already existing can not be created.</b></font>"
      },
      "MinLength": 3,
      "Label": {
        "zh-cn": "存储空间名称",
        "en": "Bucket Name"
      },
      "AllowedPattern": "^[a-z0-9]+[a-z0-9\\-]*[a-z0-9]+$",
      "Type": "String",
      "MaxLength": 63,
      "AssociationProperty": "AutoCompleteInput",
      "ConstraintDescription": {
        "zh-cn": "3 到 63 个字符,不以连字符 (-) 开头和结尾,可以包含小写字母、数字和连字符 (-)",
        "en": "3 to 63 characters, not beginning and ending with a hyphen (-), can contain lowercase letters, Numbers and hyphens (-)"
      }
    },
    "InstanceType": {
      "AssociationPropertyMetadata": {
        "SystemDiskCategory": "cloud_essd",
        "InstanceChargeType": "PostPaid",
        "ZoneId": "${ZoneId}"
      },
      "Default": null,
      "Required": true,
      "Label": {
        "zh-cn": "实例类型",
        "en": "Instance Type"
      },
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "Type": "String"
    }
  },
  "Outputs": {
    "EcsLoginAddress": {
      "Description": {
        "zh-cn": "ECS登录地址。",
        "en": "Ecs login address."
      },
      "Value": {
        "Fn::Sub": "https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs&regionId=${ALIYUN::Region}&instanceId=${EcsInstance}"
      }
    },
    "ExperienceAddress": {
      "Description": {
        "zh-cn": "体验地址。",
        "en": "Experience address."
      },
      "Value": {
        "Fn::Sub": [
          "http://${PublicIp}/wanx-demo",
          {
            "PublicIp": {
              "Fn::Select": [
                0,
                {
                  "Fn::GetAtt": [
                    "EcsInstance",
                    "PublicIps"
                  ]
                }
              ]
            }
          }
        ]
      }
    }
  },
  "Description": {
    "zh-cn": "创建VPC、ECS实例、OSS存储桶,配置安全组和RAM访问权限,安装Java与应用,实现文本绘图与人像美化服务。",
    "en": "Create a Virtual Private Cloud (VPC), Elastic Compute Service (ECS) instances, Object Storage Service (OSS) buckets, configure Security Groups and Resource Access Management (RAM) permissions, install Java and applications, and implement text drawing and portrait beautification services."
  },
  "Conditions": {},
  "Resources": {
    "CustomPolicy": {
      "Type": "ALIYUN::RAM::ManagedPolicy",
      "Properties": {
        "PolicyName": {
          "Fn::Sub": "create_by_solution-${ALIYUN::StackId}"
        },
        "PolicyDocument": {
          "Version": "1",
          "Statement": [
            {
              "Action": [
                "oss:GetObject",
                "oss:PutObject"
              ],
              "Resource": [
                {
                  "Fn::Sub": "acs:oss:oss-${ALIYUN::Region}:${ALIYUN::TenantId}:${BucketName}/*"
                }
              ],
              "Effect": "Allow"
            }
          ]
        }
      }
    },
    "InstallApp": {
      "Type": "ALIYUN::ECS::RunCommand",
      "Properties": {
        "CommandContent": {
          "Fn::Sub": "#!/bin/bash\n\ncat << EOF >> ~/.bash_profile\nexport DASHSCOPE_API_KEY=${DashScopeApiKey}\nexport OSS_ACCESS_KEY_ID=${AccessKey.AccessKeyId}\nexport OSS_ACCESS_KEY_SECRET=${AccessKey.AccessKeySecret}\nexport WANX_DEMO_OSS_BUCKET=${BucketName}\nexport WANX_DEMO_OSS_ENDPOINT=https://oss-${ALIYUN::Region}.aliyuncs.com\nEOF\n\nsource ~/.bash_profile \nwget https://help-static-aliyun-doc.aliyuncs.com/demos/wanx-demo-0.0.1-SNAPSHOT.jar\nnohup java -jar wanx-demo-0.0.1-SNAPSHOT.jar > wanx-demo.log 2>&1 &"
        },
        "Type": "RunShellScript",
        "Sync": true,
        "InstanceIds": [
          {
            "Ref": "EcsInstance"
          }
        ],
        "Timeout": 3600
      },
      "DependsOn": [
        "ModuleInstallJava.Install"
      ]
    },
    "AccessKey": {
      "Type": "ALIYUN::RAM::AccessKey",
      "Properties": {
        "UserName": {
          "Ref": "User"
        }
      }
    },
    "Bucket": {
      "Type": "ALIYUN::OSS::Bucket",
      "Properties": {
        "BucketName": {
          "Ref": "BucketName"
        },
        "DeletionForce": true
      }
    },
    "SecurityGroup": {
      "Type": "ALIYUN::ECS::SecurityGroup",
      "Properties": {
        "SecurityGroupIngress": [
          {
            "PortRange": "80/80",
            "SourceCidrIp": "0.0.0.0/0",
            "IpProtocol": "tcp"
          }
        ],
        "VpcId": {
          "Ref": "Vpc"
        },
        "SecurityGroupName": {
          "Fn::Sub": "${CommonName}-sg"
        }
      }
    },
    "ModuleInstallJava.Install": {
      "Type": "ALIYUN::OOS::Execution",
      "Properties": {
        "SafetyCheck": "Skip",
        "Parameters": {
          "action": "install",
          "packageName": "ACS-Extension-java-1853370294850618",
          "regionId": {
            "Ref": "ALIYUN::Region"
          },
          "targets": {
            "ResourceIds": [
              {
                "Ref": "EcsInstance"
              }
            ],
            "RegionId": {
              "Ref": "ALIYUN::Region"
            },
            "Type": "ResourceIds"
          },
          "parameters": null
        },
        "TemplateName": "ACS-ECS-BulkyConfigureOOSPackageWithTemporaryURL"
      },
      "Metadata": {
        "ALIYUN::ROS::Module": {
          "LogicalIdHierarchy": "ModuleInstallJava",
          "TypeHierarchy": "MODULE::ACS::OOS::Extension"
        }
      }
    },
    "User": {
      "Type": "ALIYUN::RAM::User",
      "Properties": {
        "UserName": {
          "Fn::Sub": "create_by_solution-${ALIYUN::StackId}"
        },
        "PolicyAttachments": {
          "Custom": [
            {
              "Ref": "CustomPolicy"
            }
          ]
        }
      }
    },
    "Vpc": {
      "Type": "ALIYUN::ECS::VPC",
      "Properties": {
        "VpcName": {
          "Fn::Sub": "${CommonName}-vpc"
        },
        "CidrBlock": "192.168.0.0/16"
      }
    },
    "VSwitch": {
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VSwitchName": {
          "Fn::Sub": "${CommonName}-vsw"
        },
        "VpcId": {
          "Ref": "Vpc"
        },
        "CidrBlock": "192.168.0.0/24",
        "ZoneId": {
          "Ref": "ZoneId"
        }
      }
    },
    "EcsInstance": {
      "Type": "ALIYUN::ECS::InstanceGroup",
      "Properties": {
        "SystemDiskCategory": "cloud_essd",
        "VpcId": {
          "Ref": "Vpc"
        },
        "SecurityGroupId": {
          "Ref": "SecurityGroup"
        },
        "ImageId": "aliyun_3_9_x64_20G_alibase_",
        "InternetMaxBandwidthOut": 5,
        "VSwitchId": {
          "Ref": "VSwitch"
        },
        "Password": {
          "Ref": "InstancePassword"
        },
        "InstanceName": {
          "Fn::Sub": "${CommonName}-ecs"
        },
        "InstanceType": {
          "Ref": "InstanceType"
        },
        "ZoneId": {
          "Ref": "ZoneId"
        },
        "MaxAmount": 1
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "DashScopeApiKey",
            "BucketName",
            "ZoneId",
            "InstanceType",
            "InstancePassword"
          ]
        }
      ],
      "Hidden": [
        "CommonName"
      ]
    }
  }
}