CDK - CodePipeline notification rule - Resource handler returned message: "Invalid request provided: AWS::CodeStarNotifications::NotificationRule"

0

We have a helper method in our CDK library (based on Amazon.CDK.Lib 2.28.1) to establish a CodePipeline notification rule to SNS topic that delivers events to a Microsoft Teams channel via Lambda function.

internal static void ToMicrosoftTeams(CodePipelineNotifierProps props)
{
	var topic = EstablishEventsTopic(props);
	props.Pipeline.NotifyOnExecutionStateChange("NotifyOnExecutionStateChange", topic);

	// Pull the lamdda function python code embedded in assembly.
	using var fileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("CdkLibrary.Lambda.CodePipeline_events_MicrosoftTeams.py");
	using var streamReader = new StreamReader(fileStream);
	var lambdaCode = streamReader.ReadToEnd();

	var funcName = $"{props.ProductName}-{props.PipelineName}-events-to-teams-{props.Environment}";
	var lambdaFunc = new Function(props.Pipeline, funcName,
		new FunctionProps
		{
			FunctionName = funcName,
			Runtime = Runtime.PYTHON_3_9,
			// Inserting code as raw string; resulting code file will default as index.py.
			// Function lambda_hanlder()
			Handler = "index.lambda_handler",
			Code = Code.FromInline(lambdaCode),
			Environment = new Dictionary<string, string>
			{
				{ "TeamsChannelUrl", props.TeamsChannelUrl}
			}
		});

	topic.AddSubscription(new LambdaSubscription(lambdaFunc));
}

private static Topic EstablishEventsTopic(CodePipelineNotifierProps props)
{
	string topicName = $"{props.ProductName}-{props.PipelineName}-events-{props.Environment}";
	return new Topic(props.Pipeline, topicName, new TopicProps
	{
		DisplayName = props.PipelineName + " events",
		TopicName = topicName
	});
}

This setup fine in our testing. However today in deploying a new environment, there seem to be a new error encountered on creating the notification rule.

AppService-stack | 3/10 | 2:59:02 pm | CREATE_FAILED | AWS::CodeStarNotifications::NotificationRule | AppService-pipeline-dev/AppService-pipeline-dev/NotifyOnExecutionStateChange (AppServicepipelinedevNotifyOnExecutionStateChangeE355A12F) Resource handler returned message: "Invalid request provided: AWS::CodeStarNotifications::NotificationRule" (RequestToken: <GUID>, HandlerErrorCode: InvalidRequest)

AppService-stack | 3/10 | 2:59:03 pm | CREATE_FAILED | AWS::IAM::Role | AppService-pipeline-dev/AppService-pipeline-dev/AppService-pipeline-events-to-teams-dev/ServiceRole (AppServicepipelinedevAppServicepipelineeventstoteamsdevServiceRoleDE6A960E) Resource creation cancelled

Why has this been considered an invalid request?

2개 답변
0
수락된 답변

Don't know why, but after updating the local CDK runtime to 2.31.0, without changing our library reference version (2.28.1), the cdk deploy now succeeds for the notification rule and the other resources.

UPDATE (WORK AROUND)

Following further comment as per below, to work around this problem, either have to define the CodePipeline constructs in another stack or comment it out first, so that dependency resources can initially all succeed. Then let the CodePipeline deployment fail small and quick on first attempt, and deploy again which will be more likely to succeed.

icelava
답변함 2년 전
profile picture
전문가
검토됨 한 달 전
0

This seems to happen too often when deploying new stacks

App-stack | 159/212 | 4:52:22 pm | CREATE_FAILED | AWS::CodeStarNotifications::NotificationRule | App-stack/App-stack-pipeline/App-stack-pl/NotifyOnExecutionStateChange (AppstackpipelineNotifyOnExecutionStateChange5933C726) Resource handler returned message: "Invalid request provided: AWS::CodeStarNotifications::NotificationRule" (RequestToken: GUID, HandlerErrorCode: InvalidRequest)

It has a very nasty side effect of breaking and stalling the deployment-destruction of resources, just because of this random error.

icelava
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠