Skip to content

Events: validation error (Member must have length less than or equal to 64) #21808

Closed
@michaelsatish

Description

@michaelsatish

Describe the bug

Hi,

I am getting a validation error when deploying a CDK application with cross-account targets.

Context: The webhook stack creates a lambda function. I loop through a list of repositories and attach a lambda target to be invoked in the event of a PR merge. The lambda targets are in different AWS accounts.

# app.py
import aws_cdk as cdk
from aws_cdk import aws_events as events
from aws_cdk import aws_events_targets as targets
from aws_cdk import aws_codecommit as codecommit

from stacks.webhook import WebhookStack

# Cdk app.
app = cdk.App()

dev = cdk.Environment(account=dev_config["account"], region=dev_config["region"])
staging = cdk.Environment(account=staging_config["account"], region=staging_config["region"])

dev_stack =  WebhookStack(app, "DevWebhookStack", env=dev)
staging_stack =  WebhookStack(app, "StagingWebhookStack", env=staging)

for repository in config["repositories"]:
    repo = codecommit.Repository.from_repository_name(
        dev_stack, slugify(f"{repository}-repo"), repository_name=repository
    )

    # Dev event.
    repo.on_pull_request_state_change(
        slugify(f"{repository}-dev-ref"),
        target=targets.LambdaFunction(dev_stack.fn),
        event_pattern=events.EventPattern(
            detail={
                "pullRequestStatus": ["Closed"],
                "isMerged": ["True"],
                "destinationReference": dev_config["reference"],
            },
        ),
    )

    # Staging event.
    repo.on_pull_request_state_change(
        slugify(f"{repository}-staging-ref"),
        target=targets.LambdaFunction(staging_stack.fn),
        event_pattern=events.EventPattern(
            detail={
                "pullRequestStatus": ["Closed"],
                "isMerged": ["True"],
                "destinationReference": staging_config["reference"],
            },
        ),
    )

Expected Behavior

I am able to synthesize the stacks and deploy without any errors.

Current Behavior

I am able to synthesize the stacks, but run into a validation error when deploying.

❯ cdk synth
Successfully synthesized to /<path-to-project>/cdk.out
❯ cdk deploy --all
2:04:00 PM | CREATE_FAILED        | AWS::Events::EventBusPolicy | GivePermToOtherAccount
1 validation error detected: Value 'Allow-account-<account-id>-c8daf2d8d8230ad461355af0e66021255a041e2a72' at 'statementId' failed to satisfy constraint: Member must have length less than or equal to 64 (Service: AWSEvents; Status Code: 400; Error Code: ValidationException; Reque
st ID: fb67f056-1e1d-4202-8d7d-7348e4f6cfb6; Proxy: null)

Reproduction Steps

  1. Create a similar stack from Describe the bug section.
  2. Run cdk synth
  3. Run cdk deploy --all

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.39.0 (build e36bfe5)

Framework Version

No response

Node.js Version

v16.17.0

OS

macos

Language

Python

Language Version

No response

Other information

No response

Activity

added
bugThis issue is a bug.
needs-triageThis issue or PR still needs to be triaged.
on Aug 29, 2022
added
effort/smallSmall work item – less than a day of effort
good first issueRelated to contributions. See CONTRIBUTING.md
and removed
needs-triageThis issue or PR still needs to be triaged.
on Sep 2, 2022
removed their assignment
on Sep 2, 2022
rix0rrr

rix0rrr commented on Sep 2, 2022

@rix0rrr
Contributor

We should truncate fields that are too long.

sreenath-tm

sreenath-tm commented on Sep 4, 2022

@sreenath-tm

I'm interested in contributing to this issue, so before I start working it, would you mind sparing your time explaining what the fix will be like and pointing me to some resources to get started.

2021H1030044G

2021H1030044G commented on Sep 8, 2022

@2021H1030044G

Can I contribute for this issue ?

Naumel

Naumel commented on Sep 9, 2022

@Naumel
Contributor

Hello,

Thank you for those interested in contributing.

If have not already, read CONTRIBUTING
Setup the provided example locally and check if you can replicate the issue.
The module for AWS Events is what is present in the exception, with EventPattern.

From there, check where the validation should be added, update or add the required tests, and that should be the work summary, successfully build your changes, submit a PR.

Happy coding!

3 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-eventsRelated to CloudWatch EventsbugThis issue is a bug.effort/smallSmall work item – less than a day of effortgood first issueRelated to contributions. See CONTRIBUTING.mdp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @rix0rrr@michaelsatish@sreenath-tm@TheRealAmazonKendra@2021H1030044G

      Issue actions

        Events: validation error (Member must have length less than or equal to 64) · Issue #21808 · aws/aws-cdk