首页 > 解决方案 > 为参数“instanceProfileName”提供的值无效

问题描述

运行cdk deploy我收到以下错误消息:

CREATE_FAILED | AWS::ImageBuilder::InfrastructureConfiguration | TestInfrastructureConfiguration 为参数“instanceProfileName”提供的值无效。提供的实例配置文件不存在。请指定不同的实例配置文件,然后重试。(服务:Imagebuilder,状态码:400,请求 ID:41f431d7-8544-48e9-9faf-a870b83b0100,扩展请求 ID:null)

C# 代码如下所示:

var instanceProfile = new CfnInstanceProfile(this, "TestInstanceProfile", new CfnInstanceProfileProps {
  InstanceProfileName = "test-instance-profile",
  Roles = new string[] { "TestServiceRoleForImageBuilder" }
});

var infrastructureConfiguration = new CfnInfrastructureConfiguration(this, "TestInfrastructureConfiguration", new CfnInfrastructureConfigurationProps {
  Name = "test-infrastructure-configuration",
  InstanceProfileName = instanceProfile.InstanceProfileName,
  InstanceTypes = new string[] { "t2.medium" },
  Logging = new CfnInfrastructureConfiguration.LoggingProperty {
    S3Logs = new CfnInfrastructureConfiguration.S3LogsProperty {
      S3BucketName = "s3-test-assets",
      S3KeyPrefix = "ImageBuilder/Logs"
    }
  },
  SubnetId = "subnet-12f3456f",
  SecurityGroupIds = new string[] { "sg-12b3e4e5b67f8900f" }
});

TestServiceRoleForImageBuilder存在并且以前工作过。大约一个月前,相同的代码已成功运行。有什么建议么?

如果我删除CfninfrastructureConfiguration创建部分,部署将成功运行:但至少需要 2 分钟才能完成。

AwsImageBuilderStack:正在部署... AwsImageBuilderStack:创建 CloudFormation 变更集... 0/3 | 14:24:37 | REVIEW_IN_PROGRESS | AWS::CloudFormation::Stack | AwsImageBuilderStack 用户启动 0/3 | 14:24:43 | CREATE_IN_PROGRESS | AWS::CloudFormation::Stack | AwsImageBuilderStack 用户启动 0/3 | 14:24:47 | CREATE_IN_PROGRESS | AWS::CDK::元数据 | CDK元数据/默认 (CDK元数据) 0/3 | 14:24:47 | CREATE_IN_PROGRESS | AWS::IAM::InstanceProfile | 测试实例配置文件 0/3 | 14:24:47 | CREATE_IN_PROGRESS | AWS::IAM::InstanceProfile | TestInstanceProfile 资源创建已启动 1/3 | 14:24:48 | CREATE_IN_PROGRESS | AWS::CDK::元数据 | CDKMetadata/Default (CDKMetadata) 资源创建已启动 1/3 | 14:24:48 | 创建_完成 | AWS::CDK:: 元数据 | CDKMetadata/Default (CDKMetadata) 1/3 当前进行中:AwsImageBuilderStack、TestInstanceProfile 3/3 | 14:26:48 | 创建_完成 | AWS::IAM::InstanceProfile | TestInstanceProfile 3/3 | 14:26:49 | 创建_完成 | AWS::CloudFormation::Stack | AwsImageBuilderStack

可能是某种比赛条件?我应该使用多个堆栈来实现我的目标吗?

是否可以使用等待条件(AWS::CloudFormation::WaitCondition)来绕过 2 分钟的创建时间(AWS::IAM::InstanceProfile 资源总是需要 2 分钟才能创建)

环境

更新

由于原因似乎是 AWS 内部的,因此我使用预先创建的实例配置文件作为解决方法。可以通过 IAM 管理控制台或 CLI 创建配置文件。但是,有一个适当的解决方案会很好。

标签: amazon-cloudformationamazon-iamaws-cdk

解决方案


您必须在两个构造之间创建依赖关系。CDK 在使用可选名称参数时不会推断它,而不是逻辑 id(在这种情况下似乎不起作用)。

infrastructureConfiguration.node.addDependency(instanceProfile)

以下是相关文档:https ://docs.aws.amazon.com/cdk/api/latest/docs/core-readme.html#construct-dependencies


推荐阅读