[英]AWS CDK Creating an aws_codestarnotifications.CfnNotificationRule and setting the targets
我正在嘗試使用 CDK 創建一個簡單的堆棧,其中代碼管道觸發 lambda。
我在嘗試設置 CfnNotificationRule 的目標時碰壁了:
THE_PIPELINE_ARN = "arn:aws:codepipeline:eu-west-2:121212121212:the-pipeline"
class ExampleStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
notification_topic = aws_sns.Topic(self, "TheNotificationTopic")
notification_rule = aws_codestarnotifications.CfnNotificationRule(
self,
"StackStatusChangeNotificationRule",
detail_type="FULL",
event_type_ids=[
"codepipeline-pipeline-action-execution-succeeded",
"codepipeline-pipeline-action-execution-failed",
],
name="TheStackCodeStarNotificationsNotificationRule",
resource=THE_PIPELINE_ARN,
targets= # what goes here?
)
我想要通知 go 到由 notification_topic 定義的 SNS 主題。
I think this should be a aws_cdk.aws_codestarnotifications.TargetProperty based on https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-codestarnotifications.CfnNotificationRule.TargetProperty.html but the type doesn' Python 似乎不存在。
好的,終於弄清楚了,TargetProperty 是 CfnNotificationRule 的嵌套 class,而不是模塊中的 class(與文檔相反)。 所以正確的代碼如下:
THE_PIPELINE_ARN = "arn:aws:codepipeline:eu-west-2:121212121212:the-pipeline"
class ExampleStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
notification_topic = aws_sns.Topic(self, "TheNotificationTopic")
notification_rule = aws_codestarnotifications.CfnNotificationRule(
self,
"StackStatusChangeNotificationRule",
detail_type="FULL",
event_type_ids=[
"codepipeline-pipeline-action-execution-succeeded",
"codepipeline-pipeline-action-execution-failed",
],
name="TheStackCodeStarNotificationsNotificationRule",
resource=THE_PIPELINE_ARN,
targets= [aws_codestarnotifications.CfnNotificationRule.TargetProperty(
target_type="SNS",
target_address=notification_topic.topic_arn),
]
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.