You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用CDK(Python)的Arn类生成有效的CodePipeline ARN?

CDK生成CodePipeline ARN格式错误问题解决

我参考相关资料后编写了以下Python代码片段:

vm_pipeline_qa = Stack.of(self).format_arn(
    region="us-east-1",
    service="codepipeline",
    resource="pipeline",
    account="111122223333",
    resource_name="vm_pipeline_qa"
)

当前现象

上述代码生成的CodePipeline ARN为:arn:aws:codepipeline:us-east-1:111122223333:pipeline/vm_pipeline-

预期结果

控制台中有效CodePipeline ARN的正确格式应为:arn:aws:codepipeline:us-east-1:111122223333:vm_pipeline-

解决方法

问题出在format_arn方法的参数设置上:CodePipeline的ARN结构里并不包含pipeline/前缀,而当resource参数不为空时,CDK会自动在resource和resource_name之间添加斜杠。只需将resource参数设为空字符串即可生成正确格式的ARN:

vm_pipeline_qa = Stack.of(self).format_arn(
    region="us-east-1",
    service="codepipeline",
    resource="",
    account="111122223333",
    resource_name="vm_pipeline_qa"
)

内容的提问来源于stack exchange,提问作者aksyuma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 20:30:56