Hello i am trying to add eventbridge rule as trigg...
# typescript
r
Hello i am trying to add eventbridge rule as trigger to lambda function using this example https://www.pulumi.com/registry/packages/aws/api-docs/lambda/permission/#example-usage but trigger is not added to lambda shorturl.at/dgxBP Thanks
r
bump
r
@rough-intern-34947 sorry i dint get that should i bump verison
current version
Copy code
pulumi version
v3.7.0
m
Here is an example of how I use an EventBridge EventRule to invoke my lambda EventTarget
Copy code
const eventBridgeRuleCloudTrailAction = new aws.cloudwatch.EventRule(`${appName}-cloudtrail-s3-action`, {
  description: "CloudTrail event filtered down to S3 on the asset-input bucket",
  eventPattern: assetInputBucket.id.apply(assetInputBucketName =>
    JSON.stringify({
      source: ["aws.s3"],
      "detail-type": ["AWS API Call via CloudTrail"],
      detail: {
        eventSource: ["<http://s3.amazonaws.com|s3.amazonaws.com>"],
        eventName: [
          "CompleteMultipartUpload",
          "CopyObject",
          "DeleteObject",
          "DeleteObjects",
          "PutObject",
          "UpdateObject",
        ],
        requestParameters: {
          bucketName: [assetInputBucketName],
        },
      },
    }),
  ),
});

new aws.cloudwatch.EventTarget(`${appName}-ebt-cloudtrail-action-lambda`, {
  rule: eventBridgeRuleCloudTrailAction.name,
  arn: lambdaFunctionEvent.arn,
  inputTransformer: {
    inputPaths: {
      detailType: "$.detail-type",
      eventName: "$.detail.eventName",
      id: "$.id",
      requestParameters: "$.detail.requestParameters",
      source: "$.source",
    },
    inputTemplate: `{
      "detail": {\
        "eventId": <id>,\
        "eventName": <eventName>,\
        "eventSource": <source>,\
        "messageType": "Event",\
        "requestParameters": <requestParameters>,\
        "version": "0"\
      },
      "detail-type": <detailType>,
      "id": <id>,
      "source": <source>
    }`,
  },
});

new aws.lambda.Permission(`${appName}-ebr-cloudtrail-action`, {
  principal: "<http://events.amazonaws.com|events.amazonaws.com>",
  action: "lambda:invokeFunction",
  function: lambdaFunctionEvent.arn,
  sourceArn: eventBridgeRuleCloudTrailAction.arn,
});
1
r
@*catmeme* thanks a lot this worked so i was missing EventTarget configuration its working as expected now
👍 1
r
@refined-terabyte-65361 nah, I just wanted to follow the thread sorry 🙂