阅读背景:

CloudFormation模板-任何方式来获取一个点-快速请求ID?

来源:互联网 

I'm attempting to create a single template that creates the following:

我正在尝试创建一个模板来创建以下内容:

AWS::EC2::SpotFleet resource 2 AWS::ApplicationAutoScaling::ScalingPolicy resources (scale up, scale down)

AWS:::EC2: SpotFleet资源2 AWS:: application autoscale:::ScalingPolicy资源(按比例增加,按比例减少)

Initially, my template included only the SpotFleet resource, and I confirmed that the stack would create without issue. Once I added the ScalingPolicy resources, the stack would rollback because there was "No scalable target registered for namespace..." So, I added an additional resource.

最初,我的模板只包含SpotFleet资源,并且我确认该堆栈将毫无问题地创建。一旦我添加了ScalingPolicy资源,堆栈就会回滚,因为“没有为名称空间注册的可伸缩目标……”因此,我添加了一个额外的资源。

AWS::ApplicationAutoScaling::ScalableTarget resource. (From https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-applicationautoscaling-scalabletarget.html#cfn-applicationautoscaling-scalabletarget-resourceid)

AWS:ApplicationAutoScaling:ScalableTarget资源。(来自https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-applicationautoscaling-scalabletarget.html cfn-applicationautoscaling-scalabletarget-resourceid)

{
  "Type" : "AWS::ApplicationAutoScaling::ScalableTarget",
  "Properties" : {
    "MaxCapacity" : Integer,
    "MinCapacity" : Integer,
    "ResourceId" : String,
    "RoleARN" : String,
    "ScalableDimension" : String,
    "ServiceNamespace" : String
  }
}

The ResourceID is a required property. I have the data for all the other properties, but when researching what data is needed for the ResourceID property, I have found that the data I need is the spot-fleet-request ID, (something like this: "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE").

ResourceID是必需的属性。我有所有其他属性的数据,但是在研究ResourceID属性需要什么数据时,我发现我需要的数据是spot- fleetrequestid(类似于“SpotFleetRequestId”:“swiss -73fbd2ce-aa30-494c- 8788-1cee4example”)。

So here's the problem: Since I am creating the spot fleet request in the same template as the scaling policy, I can't put the SpotFleetRequestId in manually, since to my knowledge this is created when the resource is and there's no way to anticipate what the request ID will be. In other templates, with other kinds of resources, I've simply used "Ref" or "Fn::GetAtt" to pass in the arn of a resource without having to manually input this. However--there seems to be no way to do this with a SpotFleetRequestID. All the research I've done has turned up nothing, not even a single template example that uses a method like I'm describing - the only examples available assume that the scalable target resource already exists and the SpotFleetRequestID is known prior to creating the ScalingPolicy.

因此,这里有一个问题:由于我在与伸缩策略相同的模板中创建spot舰队请求,所以我无法手动地将SpotFleetRequestId放入,因为据我所知,这是在资源存在时创建的,而且无法预测请求ID将是什么。在其他模板中,对于其他类型的资源,我只是使用了“Ref”或“Fn::GetAtt”来传入资源的arn,而无需手动输入。然而,似乎没有办法用SpotFleetRequestID来实现这一点。我所做的所有研究都没有发现任何东西,甚至没有一个模板示例使用我所描述的方法——惟一可用的示例假设可伸缩目标资源已经存在,SpotFleetRequestID在创建ScalingPolicy之前是已知的。

Does anyone have any idea if referring to the SpotFleetRequestID of an AWS::EC2::SpotFleet initialized in the same template is even possible? Or am I just missing something REALLY obvious?

如果引用AWS的SpotFleetRequestID::EC2:::SpotFleet在同一个模板中初始化是可能的,有人知道吗?或者我只是错过了一些很明显的东西?

-KungFuBilly

-KungFuBilly

1 个解决方案

#1


1  

Turns out that if you "Ref" the logical name of the AWS::EC2::SpotFleet it will return the request ID. Then, it's a matter of using "Fn::Join" to get the right data for the ResourceID. Should look something like this:

事实证明,如果您“Ref”了AWS的逻辑名称::EC2::SpotFleet它将返回请求ID,那么,这是一个使用“Fn: Join”来获取ResourceID的正确数据的问题。应该是这样的:

"ResourceId":  {
                "Fn::Join": [
                    "/",
                    [
                        "spot-fleet-request",
                        {
                            "Ref": "SpotFleet"
                        }
                    ]
                ]
            },

That will output: spot-fleet-request/"SpotFleetRequestID"

输出:spot-fleet-request /“SpotFleetRequestID”


分享到: