Incorrect `$.detail.commitId` in codecommit EventBridge Rule using CDK

0

I'm trying to send the commitId to my lambda function when someone created a tag with a certain prefix by setting up an event rule in a stack, the sending part is working but the commitId is incorrect and doesn't exist anywhere in the repo.

sample code below

    const rule = new events.Rule(this, 'PipelineTrigger', {
      eventPattern: {
        source: ['aws.codecommit'],
        resources: [repo.repositoryArn],
        detailType: ['CodeCommit Repository State Change'],
        detail: {
          event: ['referenceCreated'],
          repositoryName: ['my-repo'],
          referenceType: ['tag'],
          referenceName: [
            {
              prefix: `release-`
            }
          ]
        }
      }
    });

    rule.addTarget(
      new aws_events_targets.LambdaFunction(fn, {
        event: cdk.aws_events.RuleTargetInput.fromObject({
          commitId: events.EventField.fromPath('$.detail.commitId')
        })
      })
    );

I also checked the $.detail.referenceName and it has the correct git tag name.

where does the AWS get the $.detail.commitId? is it different from the commitId of the git tag?

1 Answer
1

To help you with your query, I created one similar EventBridge rule and target using the code you provided(with modifications to deploy it in my account).

Once the rule got created, I created a commit into one of my CodeCommit repositories and then created one git tag

I used below mentioned commands to create the git tag

$ git tag release-test cf488685
$ git push origin release-test

Here, cf488685 is the shorter version of the full commitId (cf488685bfd6f8d4f6def8e985a3648b18333d3e)

Once the git tag was created, I checked the lambda function logs and it received the commitId cf488685bfd6f8d4f6def8e985a3648b18333d3e. So, the configuration that you've used in CDK is correct. To be specific, here $.detail.commitId is the full commitId of the commitId that we used while creating git tag (if we specified shorter version). Therefore, please check if the commitId that you're noticing is the full version of the id that you specified while creating git tag.

If you have a support plan with your account, then you can reach out to us creating a support case from the Support Center as well.

AWS
SUPPORT ENGINEER
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions