Cloudformation Template error: Resource handler returned message: "Invalid request provided: AWS::CodeStarNotifications::NotificationRule" (RequestToken: , HandlerErrorCode: InvalidRequest)

0

Getting error while creating stack using the below template through aws console in us-east-2 region error is: Resource handler returned message: "Invalid request provided: AWS::CodeStarNotifications::NotificationRule" (RequestToken: , HandlerErrorCode: InvalidRequest)

AWSTemplateFormatVersion: '2010-09-09'
Description: Create an AWS CodePipeline, IAM Role, and Notification Rule with a zip file source in S3 and deploy using AWS CodeDeploy.

Parameters:
  SourceS3Bucket:
    Description: S3 bucket name where the source zip file is located
    Type: String
  SourceS3ObjectKey:
    Description: S3 object key for the source zip file
    Type: String
  CodeDeployApplicationName:
    Description: Name of the AWS CodeDeploy application
    Type: String
  CodeDeployDeploymentGroupName:
    Description: Name of the AWS CodeDeploy deployment group
    Type: String
  SlackChannel:
    Description: Slack channel to receive notifications
    Type: String

Resources:
  PipelineRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: CodePipelineRole
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - codepipeline.amazonaws.com
            Action:
              - sts:AssumeRole
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/AWSCodePipeline_FullAccess
        - arn:aws:iam::aws:policy/AmazonS3FullAccess
        - arn:aws:iam::aws:policy/AmazonSSMFullAccess

  MyPipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:
      Name: MyPipeline
      RoleArn: !GetAtt PipelineRole.Arn
      ArtifactStore:
        Type: S3
        Location: <YOUR_ARTIFACT_BUCKET_NAME>  # Replace with your existing ArtifactBucket
      Stages:
        - Name: Source
          Actions:
            - Name: SourceAction
              ActionTypeId:
                Category: Source
                Owner: AWS
                Version: 1
                Provider: S3
              Configuration:
                S3Bucket: !Ref SourceS3Bucket
                S3ObjectKey: !Ref SourceS3ObjectKey
              OutputArtifacts:
                - Name: SourceOutput
              RunOrder: 1
        - Name: Deploy
          Actions:
            - Name: DeployAction
              ActionTypeId:
                Category: Deploy
                Owner: AWS
                Version: 1
                Provider: CodeDeploy
              Configuration:
                ApplicationName: !Ref CodeDeployApplicationName
                DeploymentGroupName: !Ref CodeDeployDeploymentGroupName
              InputArtifacts:
                - Name: SourceOutput
              RunOrder: 1

  NotificationRule:
    Type: AWS::CodeStarNotifications::NotificationRule
    Properties:
      Name: MyPipelineNotificationRule
      DetailType: BASIC
      EventTypeIds:
        - codepipeline.PipelineExecutionStateChange
      Resource: !Sub 'arn:${AWS::Partition}:codepipeline:${AWS::Region}:${AWS::AccountId}:${MyPipeline}'
      Targets:
        - TargetAddress: !Ref SlackChannel
          TargetType: AWSChatbotSlack

Outputs:
  PipelineName:
    Description: Name of the created AWS CodePipeline
    Value: !Ref MyPipeline
Chandra
asked 7 months ago1268 views
1 Answer
1
Accepted Answer

Hi Chandra, I'll be happy to help you with this issue. Basically there are 2 things I would like to isolate from your error, as I was able to successfully reproduce and fix it using your template.

  1. Make sure your template contains the right configuration for AWS::CodeStarNotifications::NotificationRule
  2. Make sure you are providing the right input in the SlackChannel parameter

Lets start with the first one. I noticed that there is one incorrect value in this part of your template

NotificationRule:
    Type: AWS::CodeStarNotifications::NotificationRule
    Properties:
      Name: MyPipelineNotificationRule
      DetailType: BASIC
      EventTypeIds:
        - codepipeline.PipelineExecutionStateChange

Where codepipeline.PipelineExecutionStateChange it is not an allowed value for NotificationRules, please try one of the allowed values from this documentation [1]

Something like this worked for me

NotificationRule:
    Type: AWS::CodeStarNotifications::NotificationRule
    Properties:
      Name: MyPipelineNotificationRule
      DetailType: BASIC
      EventTypeIds:
        - codepipeline-pipeline-stage-execution-started
      Resource: !Sub 'arn:${AWS::Partition}:codepipeline:${AWS::Region}:${AWS::AccountId}:${MyPipeline}'

About the second point. I would like to make sure that you are setting the right value for the Slack Channel. The template might suggest that the right value for that parameter is the Slack Channel ID or URL.

Before deploying your template, you will need to configure AWS Chatbot for a Slack Channel integration following the steps in the following documentation [2]

Finally to successfully troubleshoot CloudFormation deployments, you can use CloudTrail logs [3]. From there you can identify what was the API call triggered by CloudFormation and what was the bad input.

Here I'll paste a piece of my error which helped me to identify what your issue was.

"requestParameters": {
        "EventTypeIds": [
            "codepipeline.PipelineExecutionStateChange"
        ],
        "ClientRequestToken": "***",
        "DetailType": "BASIC",
        "Resource": "arn:aws:codepipeline:us-east-1:***:MyPipeline",
        "Targets": [
            {
                "TargetType": "AWSChatbotSlack",
                "TargetAddress": "***"
            }
        ],
        "Name": "***"
    },
    "responseElements": {
        "Message": "The notification rule cannot be created or modified because the following notification event type ID is not valid: codepipeline.PipelineExecutionStateChange. For more information, see the AWS CodeStar Notifications API Reference."
    }

I hope this information was useful.

Events for notification rules on pipelines

[1] https://docs.aws.amazon.com/dtconsole/latest/userguide/concepts.html#events-ref-pipeline

AWS Chatbot - Get started with Slack

[2] https://docs.aws.amazon.com/chatbot/latest/adminguide/slack-setup.html

Viewing recent CloudTrail management events in the CloudTrail console

[3] https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events-console.html

profile pictureAWS
EXPERT
Sercast
answered 7 months ago
profile picture
EXPERT
reviewed a month ago
  • Again the same error, I tried to create stack after the corrections you suggested

    1. EventTypeIds: This time I passed as below
    2. SlackChannel: Passing slack channel id
      NotificationRule:
        Type: AWS::CodeStarNotifications::NotificationRule
        Properties:
          Name: MyPipelineNotificationRule
          DetailType: BASIC
          EventTypeIds:
            - codepipeline-pipeline-pipeline-execution-failed
            - codepipeline-pipeline-pipeline-execution-canceled
            - codepipeline-pipeline-pipeline-execution-started
            - codepipeline-pipeline-pipeline-execution-resumed
            - codepipeline-pipeline-pipeline-execution-succeeded
            - codepipeline-pipeline-pipeline-execution-superseded
          Resource: !Sub 'arn:${AWS::Partition}:codepipeline:${AWS::Region}:${AWS::AccountId}:${MyPipeline}'
          Targets:
            - TargetAddress: !Ref SlackChannel
              TargetType: AWSChatbotSlack
    
  • cloudtrail helped me in this, I was using slack channel id, instead target address needs arn

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions

Relevant content