Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
michaelsatish opened this issue Aug 29, 2022 · 5 comments
Closed
Labels
@aws-cdk/aws-events Related to CloudWatch Events bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1

Comments

@michaelsatish
Copy link

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

@michaelsatish michaelsatish added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 29, 2022
@github-actions github-actions bot added the @aws-cdk/aws-events Related to CloudWatch Events label Aug 29, 2022
@rix0rrr rix0rrr added effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1 and removed needs-triage This issue or PR still needs to be triaged. labels Sep 2, 2022
@rix0rrr rix0rrr removed their assignment Sep 2, 2022
@rix0rrr
Copy link
Contributor

rix0rrr commented Sep 2, 2022

We should truncate fields that are too long.

@sreenath-tm
Copy link

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
Copy link

Can I contribute for this issue ?

@Naumel
Copy link
Contributor

Naumel commented Sep 9, 2022

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!

mergify bot pushed a commit that referenced this issue Oct 29, 2022
Fixes #22120, #21808.

Current setup does not allow deployment of the EventBus support stack due to StatementId being larger than 64 characters.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Nov 1, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-events Related to CloudWatch Events bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1
Projects
None yet
6 participants