aws-cdk - AWS CDK 如何处理假设返回列表而不是字符串的 Fn.getAtt
问题描述
我有一个 AWS::EC2::VPCEndpoint 资源类型,我想根据https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpcendpoint 获取它的 DnsEntries 值。 html#aws-resource-ec2-vpcendpoint-return-values是 DNS 条目的列表。我希望能够从列表中选择第一项,所以我尝试了这样的事情:
const vpcEndpoint = new ec2.CfnVPCEndpoint(this, "vpcendpoint", {
serviceName: "com.amazonaws.vpce.us-west-2.vpce-svc-xxxxxx",
vpcId: "vpc-123",
privateDnsEnabled: false,
subnetIds: ["subnet-123"],
vpcEndpointType: "Interface",
});
const fisrtDnsEntry = cdk.Fn.select(0, cdk.Fn.getAtt(vpcEndpoint.logicalId, "DnsEntries"))
这不起作用,因为Fn.select
需要一个字符串数组但Fn.getAtt
返回IResolvable
并且只有toString()
方法。
知道我还能做什么吗?
解决方案
关于这个有一个未解决的问题 - https://github.com/aws/aws-cdk/issues/3627。
目前,您可以使用以下代码片段:
const firstEntry = cdk.Fn.select(0, vpcEndpoint.attrDnsEntries);
const entryParts = cdk.Fn.split(':', firstEntry);
const primaryDNSName = cdk.Fn.select(1, entryParts);
new cdk.CfnOutput(this, 'primaryDNSName', { value: primaryDNSName });
CDK 输出:
用户界面输出:
推荐阅读
- database - ClickHouse 函数中的第二个参数 toDateTime64 是什么意思?
- python - 如何使用 python reduce 函数填充 NaN 值
- java - 将 ZonedDatetime 转换为字符串
- git - 尝试初始化合并请求源时,Repo init 失败
- python - 如何比较字典值和熊猫数据框?
- android - 如何处理android单活动设计模式中的片段?
- date - 在 oracle 中为选择查询结果日期添加天数
- c - scanf("%d/%d%c%d/%d", &num1, &denom1, &sign, &num2, &denom2); 继续在控制台扫描用户输入
- flutter - 如何获得未来的权利
>> 在颤振中? - java - Java - 字符串拆分