Description
Describe the bug
When setting up notifications for Codepipeline rule on a Codepipeline where SNS is used as a target,
a codestar notifications service linked role needs to be available in the account otherwise the notification rule will fail to be created.
If the service linked role is not present (usually the case if notifications on a pipeline is being set up for the first time on an account) the service linked role is created automatically by Cloudformation which usually takes a bit of time. However before the service linked role has been created, Cloudformation goes off and attempts to create the Notification rule which fails as the service linked role is not yet present.
When I check the CreateNotificationRule
event in Cloudtrail, I see the following error message in the responseElement
"AWS CodeStar Notifications could not create the AWS CloudWatch Events managed rule in your AWS account. If this is your first time creating a notification rule, the service-linked role for AWS CodeStar Notifications might not yet exist. Creation of this role might take up to 15 minutes. Until it exists, notification rule creation will fail. Wait 15 minutes, and then try again.
If this is is not the first time you are creating a notification rule, there might be a problem with a network connection, or one or more AWS services might be experiencing issues.
Verify your network connection and check to see if there are any issues with AWS services in your AWS Region before trying again."
There has been previous reports of this issue where it was assumed that adding a dependency on the topic role
would fix the issue but the actual root of the problem is that the service linked role needs to be created first. (#29484)
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
Deployment is successful
Current Behavior
Deployment fails and get the following error in Cloudformation:
Invalid request provided: AWS::CodeStarNotifications::NotificationRule
Reproduction Steps
- Ensure there is no codestar notifications service linked role in the aws account (if there is one delete it)
- Attempt to deploy a pipeline with a notification rule where an SNS topic is set as the target e.g
const pipeline = new codepipeline.Pipeline(this, 'Pipeline', {
pipelineName: 'MyPipeline',
...
});
const topic = new sns.Topic(this, 'Topic');
const rule = new NotificationRule(this, 'NotificationRule', {
...,
targets: [topic]
});
- Deployment should fail and when you check the CreateNotificationRule event in Cloudtrail you should see the error message in the responseElement that it failed to create the CloudWatch Events managed rule
Possible Solution
A possible way round this is to have a custom resource that goes off and creates the service linked role and
add a dependency on the notification rule so that the service linked role is created before creating the notification rule.
However, it would be nice if there is a much simpler solution to this issue and open to suggestions. (is it possible to add a dependency on a service link role without using a custom resource?)
(I'm also happy to create attempt to PR to fix this issue once a solution is agreed upon)
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
2.189.0
AWS CDK CLI version
2.1007.0
Node.js Version
20
OS
MacOS
Language
TypeScript
Language Version
No response
Other information
No response