Skip to content

(aws-chatbot): SlackChannelConfiguration.slackChannelConfigurationArn not returning a valid ARN #15842

@aragevorkian

Description

@aragevorkian

I have a setup with two stacks A and B, where B depends on A. I created a SlackChannelConfiguration resource in stack A and I export the ARN for this resource via slackChannel.slackChannelConfigurationArn.

In Stack B I import this ARN and when I call SlackChannelConfiguration.fromSlackChannelConfigurationArn I get the error:
The ARN of a Slack integration must be in the form: arn:aws:chatbot:{region}:{account}:chat-configuration/slack-channel/{slackChannelName}

I spent some time trying to fix this in the module, at first thinking that there was a bug on this line https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-chatbot/lib/slack-channel-configuration.ts#L295 and that this.slackChannelConfigurationArn = configuration.ref; should have been this.slackChannelConfigurationArn = configuration.attrArn;. However, after making that change my integration tests and unit tests were still breaking. After looking into it more I realized that CloudFormation doesn't support returning the ARN for AWS::Chatbot::SlackChannelConfiguration as noted here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-chatbot-slackchannelconfiguration.html#aws-resource-chatbot-slackchannelconfiguration-return-values

If this is correct, should the slackChannelConfigurationArn property be marked as deprecated until CloudFormation adds support for this?

Reproduction Steps

UNIT TEST
Add this test to aws-cdk/packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts:

test('should retrieve slack channel configuration ARN', () => {
    const slackChannelName = 'Test';

    const slackChannel = new chatbot.SlackChannelConfiguration(stack, 'MySlackChannel', {
      slackWorkspaceId: 'ABC123',
      slackChannelId: 'DEF456',
      slackChannelConfigurationName: slackChannelName,
    });

    const slackChannelFromArn = chatbot.SlackChannelConfiguration.fromSlackChannelConfigurationArn(stack, 'MySlackChannel2', slackChannel.slackChannelConfigurationArn);

    expect(slackChannel.slackChannelConfigurationArn).toEqual(slackChannelFromArn.slackChannelConfigurationArn);
  });

INTEGRATION TEST
Add this test to a new aws-cdk/packages/@aws-cdk/aws-chatbot/test/integ.chatbot-fromarn.ts file:

import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import * as chatbot from '../lib';

class ChatbotFromArnInteg extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const slackChannel = new chatbot.SlackChannelConfiguration(this, 'MySlackChannel', {
      slackChannelConfigurationName: 'test-channel',
      slackWorkspaceId: 'ABC123', // modify to your slack workspace id
      slackChannelId: 'DEF456', // modify to your slack channel id
      loggingLevel: chatbot.LoggingLevel.NONE,
    });

    const slackChannelFromArn = chatbot.SlackChannelConfiguration.fromSlackChannelConfigurationArn(this, 'MySlackChannel2', slackChannel.slackChannelConfigurationArn);

    slackChannelFromArn.addToRolePolicy(new iam.PolicyStatement({
      effect: iam.Effect.ALLOW,
      actions: [
        's3:GetObject',
      ],
      resources: ['arn:aws:s3:::abc/xyz/123.txt'],
    }));
  }
}

const app = new cdk.App();

new ChatbotFromArnInteg(app, 'ChatbotFromArnInteg');

app.synth();

What did you expect to happen?

Expected to get a ISlackChannelConfiguration object to use as a notification target.

What actually happened?

Got the error The ARN of a Slack integration must be in the form: arn:aws:chatbot:{region}:{account}:chat-configuration/slack-channel/{slackChannelName}

Environment

  • CDK CLI Version : 1.115.0 (build f0ca40f)
  • Framework Version:
  • Node.js Version: v12.16.1
  • OS : macOs Big Sur 11.5
  • Language (Version): C# in my envrionment and TypeScript in the aws-cdk codebase

Other


This is 🐛 Bug Report

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-chatbotRelated to AWS ChatbotbugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions