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개 답변
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
지원 엔지니어
답변함 5달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠