Is it necessary to transmit rule specifics to Stepfunctions?

Is it feasible to achieve what I'm attempting, or am I starting with an impossible task?

When a Event Bridge Rule is triggered by an added event pattern, like shown below, should the detailed information be included in the step input?

const rule = new Rule(this, 'Rule', {
  schedule: Schedule.expression('cron(0 18 ? * SUN-WED *)'),
}

rule.addEventPattern({
  detail: {
    example: [
      'hello-world',
    ],
  },
});

rule.addTarget(new SfnStateMachine(stateMachine));

Currently, only limited step input is displayed. What could be missing if this doesn't work as expected?

{
  "version": "0",
  "id": "590c8f79-8bb5-d50b-30f7-1234567890",
  "detail-type": "Scheduled Event",
  "source": "aws.events",
  "account": "1234567890",
  "time": "2022-01-14T19:33:47Z",
  "region": "eu-west-1",
  "resources": [
    "arn:aws:events:eu-west-1:1234567890:rule/Example-Rule4C995B7F-UJ68BG8LJK54"
  ],
  "detail": {}
}

Update: Thanks to Fedonev's guidance, I was able to make it work as follows;

rule.addTarget(new SfnStateMachine(stateMachine, {
  input: RuleTargetInput.fromObject({
    'version': 'custom',
    'id': EventField.fromPath('$.id'),
    'detail-type': EventField.fromPath('$.detail-type'),
    'source': EventField.fromPath('$.source'),
    'account': EventField.fromPath('$.account'),
    'time': EventField.fromPath('$.time'),
    'region': EventField.fromPath('$.region'),
    'resources': EventField.fromPath('$.resources'),
    'detail': {
      example: [
        'hello-world',
      ],
    },
  }),
}));

Answer №1

To apply filters to events, utilize the rule.addEventPattern method. If you wish to add custom data to scheduled event payloads, make use of the input:RuleTargetInput property of the target:

rule.addTarget(
  new targets.SfnStateMachine(stateMachine, {
    input: events.RuleTargetInput.fromObject({ example: ['hello-world'] }),
  })
);

By following this approach, your Step Function executions will exclusively receive the input you specify, instead of the default event payload originally displayed in the OP:

// Step Function input
{
  "example": [
    "hello-world"
  ]
}

If you require additional fields from the default event payload, you can incorporate them in your input using JSONPath reference with events.EventField.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error in React Router when using TypeScript

Encountering errors while trying to set up router with React and TypeScript. https://i.sstatic.net/muSZU.png I have already attempted to install npm install @types/history However, the issue persists. Your assistance would be greatly appreciated. Thank y ...

Issue with Angular 17 button click functionality not functioning as expected

Having trouble with a button that should trigger the function fun(). Here's the code snippet I'm using. In my TS file: fun(): void { this.test = 'You are my hero!'; alert('hello') } Here is the respective HTML: &l ...

What is the best way to divide a string into an array containing both linked and non-linked elements?

I'm struggling to find the right solution to my problem. I need to create a view that is enclosed in a clickable div. The content will consist of plain text mixed with clickable URLs - the issue arises when clicking on a link also triggers the method ...

Error Connecting to Database with Node.JS MySQL Module - ECONNRESET Issue

Attempting to establish a connection with my database using the mysql module has been quite the challenge. Each time I try, an error seems to pop up: read eCONNRESET There is problem. (The final part is from my console log, as seen below.) I've ruled ...

What's the simplest method for updating a single value within a nested JSON object using TypeScript?

Using TypeScript version ^3.5.3 Consider the following JSON data: const config = { id: 1, title: "A good day", body: "Very detailed stories" publishedAt: "2021-01-20 12:21:12" } To update the title using spread synta ...

Guide on creating a Typescript function with a strongly typed argument

I am looking to develop a function that accepts a type created using export class and imported in the traditional manner as an extension of a particular type. With a base Page class and various derived classes, I aim to have this function capable of receiv ...

How can I display every index from my JSON Fetched Files?

In the picture shown here, I have a series of Tables being displayed: https://i.sstatic.net/YUZD1.png The issue highlighted in red is that I want to show the Index of each JSON array as the Table number. Below is the code snippet: function getExternal( ...

Steps to revert table data back to its original state after editing in Angular 12 template-driven form

Currently, I have implemented a feature in my web application where users can edit table data by clicking on an edit hyperlink. Once clicked, cancel and submit buttons appear to either discard or save the changes made. The issue I'm facing is related ...

How can I ensure that all the text is always in lowercase in my Angular project?

Is there a way to ensure that when a user enters text into an input field to search for a chip, the text is always converted to lowercase before being processed? Currently, it seems possible for a user to create multiple chips with variations in capitaliza ...

Instructions for utilizing ObjectId with a string _id on the client side

Is there a way to retrieve a document using the _id in string format? Here is an example of the code on the client side: 'use client' ... const Page(){ ... fetch("api/get_data", { method: 'POST', ...

AWS-ECS Deployment encountered a 404 error: Resource Not Found

I am encountering an issue while deploying a microservice to my ECS cluster. Here is the breakdown of the services running on my cluster: 6 Java services (ECS services) 2 Python services 1 React service I have configured ALB for routing my requests based ...

Obtain non-numeric parameters from the URL in Angular 2 by subscribing to

How do I handle subscribing to a non-numeric parameter from a URL? Can the local variable inside my lambda function params => {} only be a number? Here's my code: getRecordDetail() { this.sub = this.activatedRoute.params.subscribe( ...

Regex struggles to identify words containing foreign characters

Here is a method I have created to check if a user-input term matches any blacklisted terms: static checkAgainstBlacklist(blacklistTerms, term) { return blacklistTerms.some(word => (new RegExp(`\\b${word}\\b`, 'i&ap ...

What kind of error should be expected in a Next.js API route handler?

Recently, I encountered an issue with my API route handler: import { NextRequest, NextResponse } from "next/server"; import dbConnect from "@/lib/dbConnect"; import User from "@/models/User"; interface ErrorMessage { mess ...

undefined event typescript this reactjs

I have come across the following TypeScript-written component. The type definitions are from definitelytyped.org. I have bound the onWheel event to a function, but every time it is triggered, this becomes undefined. So, how can I access the referenced el ...

Select the implied type from a resolved Promise type in Typescript

I am working with a function called getStaticProps in Next.js that returns a Promise, resolving to an Object with the following structure: type StaticProps<P> = { props: P; revalidate?: number | boolean; } To generically "unwrap" the type o ...

Combining Repetitive Elements in an Array

Trying to combine an array of products with the same order_id while also including all objects from a second products array. Below are some sample orders: const orders = [ { "order_details": { }, "order_id": "1", ...

Jaydata is a powerful open source library for interacting with databases

I rely on jaysvcutil for compiling OData $metadata and generating JayDataContext.js, which is truly impressive. However, I prefer to work with Typescript without using import/export syntax or other third-party tools like requirejs or systemjs. Even thoug ...

What is the method for comparing a value in TypeScript that does not match a given value?

I am new to scripting languages and encountered an issue while using enums with if-else statements in TypeScript. To work around this problem, I have decided to use switch-case instead of if-else conditions. Despite trying !== and !===, they do not seem t ...

I'm encountering an issue when attempting to send a parameter to a function within a typescript code

Recently, I started using Typescript and encountered an issue with passing arguments to a function in Typescript. This particular function is triggered when rendering a form modal. However, I keep receiving two errors: "Argument of type 'Promise& ...