2

我正在尝试使用 CloudFormation 创建一个聊天框。通过在 Notifaction Topi 中创建消息来测试它时,没有任何内容发布到 slack。

通知.yml

AWSTemplateFormatVersion: 2010-09-09
Transform:
  - AWS::Serverless-2016-10-31

Parameters:
  Team:
    Type: String
  Environment:
    Type: String
  Domain:
    Type: String
  Channel:
    Type: String
  Workspace:
    Type: String

Resources:
  PipelineNotificationTopic:
    Type: AWS::SNS::Topic
    Properties:
      Tags:
        - Key: Domain
          Value: "CICD"
        - Key: Team
          Value: "Engineering"
      TopicName: "PipelineStatus"

  PipelineEventRule:
    Type: AWS::Events::Rule
    Properties:
      Description: "PipelineEventRule"
      EventPattern:
        source:
          - "aws.codepipeline"
        detail-type:
          - "CodePipeline Pipeline Execution State Change"
        detail:
          state:
            - STARTED
            - CANCELED
            - FAILED
            - SUCCEEDED
      State: "ENABLED"
      Targets:
        - Arn:
            Ref: PipelineNotificationTopic
          Id: "PipelineNotificationTopic"

  SlackBot:
    Type: AWS::Chatbot::SlackChannelConfiguration
    Properties:
      ConfigurationName: !Sub ${Team}-${Environment}-${Domain}
      IamRoleArn: !GetAtt Role.Arn
      SlackChannelId: !Ref Channel
      SlackWorkspaceId: !Ref Workspace
      SnsTopicArns: 
        - !Ref PipelineNotificationTopic

  Role:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service: chatbot.amazonaws.com
            Action: sts:AssumeRole
      Policies:
        - PolicyName: Events
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Effect: Allow
                Action:
                  - "events:*"
                Resource:
                  - "*"
4

1 回答 1

2

您需要授权 slack 频道收听已发布的 SNS 通知。有关分步操作的更多信息,请参阅链接 [1] 。此外,我会听取他们的建议并使用 Amazon 的预定义角色开放 IAM 权限。(如 AWS-Chatbot-NotificationsOnly-Policy、AWS-Chatbot-LambdaInvoke-Policy、AWS-Chatbot-ReadOnly-Commands-Policy - 如果您认为它们过于宽松,您可以在使用后使用自定义策略回拨) . 链接 [2]上的更多信息。

1 https://docs.aws.amazon.com/chatbot/latest/adminguide/getting-started.html

2 https://docs.aws.amazon.com/chatbot/latest/adminguide/getting-started.html#editing-iam-roles-for-chatbot

于 2021-07-04T19:15:00.067 回答