【问题标题】:How to get ARN of ALB如何获取 ALB 的 ARN
【发布时间】:2021-02-16 21:28:50
【问题描述】:

我尝试在 TypeScript 中通过 CDK 创建一个 alb。但是当执行“cdk deploy”时,我遇到以下代码错误。如何获取 ALB 的 ARN?

AlbStack failed: Error [ValidationError]: Template error: resource alb does not support attribute type Arn in Fn::GetAtt
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const target_group = new elbv2.CfnTargetGroup(this, 'targetgroup', {
    ~
    });
    
    const alb = new elbv2.CfnLoadBalancer(this, 'alb', {
    ~
    });

    new elbv2.CfnListener(this, 'alblistener80', {
      defaultActions: xxx,
      loadBalancerArn: cdk.Fn.getAtt(alb.logicalId, 'Arn').toString(), // <----- Here
      port: 80,
      protocol: 'HTTP',
    });
  }

【问题讨论】:

  • 进展如何?获取 ARN 仍有问题?

标签: amazon-web-services amazon-cloudformation aws-cdk


【解决方案1】:

基于 CloudFormation docsRef 返回 Arn,而不是 GetAtt。因此,如果你想使用cdk.Fn,你应该使用CDK的ref

Ref 内部函数返回指定参数或资源的值。

因此,您可以尝试:

cdk.Fn.ref(alb.logicalId)

【讨论】:

  • 部署成功。谢谢!
猜你喜欢
  • 2022-01-15
  • 2018-07-18
  • 2020-05-12
  • 2021-04-24
  • 2020-03-13
  • 2022-09-27
  • 2021-12-18
  • 2020-04-09
  • 1970-01-01
相关资源
最近更新 更多