AWS

Format Lambda invocation input from EventBridge using AWS CDK

Amazon EventBridge can be customized to transform input parameters using an “input transformer.” The transformer allows the input parameter to be defined the same way as a direct invocation or API Gateway input. To define the input transformer, the AWS CDK can be used with the appropriate code. The input parameter format can be defined as text using RuleTargetInput.fromText instead. The input transformer is useful for obtaining the input parameter the way you want it instead of the default parameter provided by EventBridge.

広告ここから
広告ここまで

By default, Amazon EventBridge will wrap the event parameter like this.

{
   .../* EventBridge execution parameters */
   detail: {
    /* input payload */
   }
}

But sometime we want to get the input parameter same as dirctory invocation or API Gateway input.

{
  /* input payload */
}

Define input transformer by using AWS CDK

We can customize the input parameter using “input transformer“.

And we can define it by using AWS CDK

import { EventBus, Rule, RuleTargetInput, EventField } from '@aws-cdk/aws-events';
import {
LambdaFunction,
} from '@aws-cdk/aws-events-targets'

    const bus = new EventBus(this, 'EventBus', {
      eventBusName: 'ExampleBusName1'
    })
    const eventRule = new Rule(this, 'EventRule', {
      description: 'example event rule',
      enabled: true,
      eventBus: bus,
      eventPattern: {
        detailType: [
          "customer.created",
          "customer.updated"
        ],
        source: [
          "Stripe"
        ]
      },
      ruleName: 'ExampleRule1',
      targets: [
        new LambdaFunction(Lambda, {
          event: RuleTargetInput.fromObject({
            name: EventField.fromPath('$.detail.name'),
            detail: EventField.fromPath('$.detail.detail')
          })
        })
      ]
    })

If you want to put as a text, we can use RuleTargetInput.fromText instead.

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts