Closed
Description
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
- Create a similar stack from Describe the bug section.
- Run cdk synth
- 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
rix0rrr commentedon Sep 2, 2022
We should truncate fields that are too long.
sreenath-tm commentedon Sep 4, 2022
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 commentedon Sep 8, 2022
Can I contribute for this issue ?
Naumel commentedon 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!
3 remaining items