Skip to content

aws-events: eventSourceName does not accept parameters #20718

@keetonian

Description

@keetonian

Describe the bug

I am trying to use a parameter for the eventSourceName part of an AWS EventBus resource, but it is failing in validation. I can set up the event bus if I give the string directly, but any method of referencing a parameter in this field fails. I haven't tried doing this in pure CFN, but I assume parameters would work in this field in pure CFN.

Expected Behavior

Code should work and accept parameters for the EventSourceName.

Current Behavior

I get the following validation error:

Error: 'eventSourceName' must satisfy: /^aws\.partner(\/[\.\-_A-Za-z0-9]+){2,}$/

from the following code:

eventSourceName: partnerEventName.valueAsString

Reproduction Steps

Add the following snippet of code to any stack:

    const partnerEventName = new CfnParameter(this, "MongoPartnerEventName", {
      type: "String",
      description: "Event name for Mongo partner event. This can be found on the console after setting up this event in Mongo.",
      default: "aws.partner/mongodb.com/stitch.trigger/123abc"
    })


    const bus = new events.EventBus(this, "mongo-event-bus", {
      eventSourceName: partnerEventName.valueAsString //cdk.Fn.ref("MongoPartnerEventName")
    })

Possible Solution

Fix validation to allow tokens or CFN functions. It looks like this was fixed for EventBusName in #10772 but not for this field.

Additional Information/Context

I'm trying to use parameters so I can deploy this to multiple different environments.

CDK CLI Version

2.23.0

Framework Version

No response

Node.js Version

v17.6.0

OS

OSX

Language

Typescript

Language Version

ts-node 10.7.0

Other information

/Users/keeton/workplace/leland-ops-slack-backend/node_modules/aws-cdk-lib/aws-events/lib/event-bus.ts:275
        throw new Error(
              ^
Error: 'eventSourceName' must satisfy: /^aws\.partner(\/[\.\-_A-Za-z0-9]+){2,}$/
    at Function.eventBusProps (/Users/keeton/workplace/leland-ops-slack-backend/node_modules/aws-cdk-lib/aws-events/lib/event-bus.ts:275:15)
    at new EventBus (/Users/keeton/workplace/leland-ops-slack-backend/node_modules/aws-cdk-lib/aws-events/lib/event-bus.ts:311:56)
    at new LelandOpsSlackBackendStack (/Users/keeton/workplace/leland-ops-slack-backend/lib/leland-ops-slack-backend-stack.ts:35:17)
    at Object.<anonymous> (/Users/keeton/workplace/leland-ops-slack-backend/bin/leland-ops-slack-backend.ts:7:1)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Module.m._compile (/Users/keeton/workplace/leland-ops-slack-backend/node_modules/ts-node/src/index.ts:1597:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/keeton/workplace/leland-ops-slack-backend/node_modules/ts-node/src/index.ts:1600:12)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)

Metadata

Metadata

Labels

@aws-cdk/aws-eventsRelated to CloudWatch EventsbugThis issue is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions