Is it normal that aws-eventbridge-lambda does not generate a Lambda function?

I've been experimenting with the AWS CDK (Typescript) to enhance my knowledge. I'm interested in setting up a lambda function to run daily at a specific time or at intervals of N minutes. Since I anticipate having multiple functions, it would be beneficial to use a construct that bundles a lambda function, an EventBridge rule, and other necessary utilities.

Instead of creating my own construct, I discovered aws-eventbridge-lambda and decided to give it a try. In my project, I have a lambda directory containing a simple hello.py file with a basic lambda_handler definition. My stack setup is as follows:

import { Stack, StackProps, Duration } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { EventbridgeToLambdaProps, EventbridgeToLambda } from '@aws-solutions-constructs/aws-eventbridge-lambda';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as events from 'aws-cdk-lib/aws-events';

export class TimedLambdaStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const constructProps: EventbridgeToLambdaProps = {
      lambdaFunctionProps: {
        code: lambda.Code.fromAsset('lambda'),
        runtime: lambda.Runtime.PYTHON_3_9,
        handler: 'hello.lambda_handler'
      },
      eventRuleProps: {
        schedule: events.Schedule.rate(Duration.minutes(5))
      }
    };
    
    new EventbridgeToLambda(this, 'test-eventbridge-lambda', constructProps);
  }
}

My CDK deployment process is working fine through a pipeline that I set up following instructions from the CDK Workshop:

import * as cdk from 'aws-cdk-lib';
import * as codecommit from 'aws-cdk-lib/aws-codecommit';
import { Construct } from 'constructs';
import {CodeBuildStep, CodePipeline, CodePipelineSource} from "aws-cdk-lib/pipelines";

export class TimedPipelineStack extends cdk.Stack {
    constructor(scope: Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        const repo = new codecommit.Repository(this, 'TimedRepo', {
            repositoryName: "TimedRepo"
        });

        const pipeline = new CodePipeline(this, 'Pipeline', {
            pipelineName: 'TimedLambdaPipeline',
            synth: new CodeBuildStep('SynthStep', {
                input: CodePipelineSource.codeCommit(repo, 'master'),
                installCommands: [
                    'npm install -g aws-cdk'
                    #'npm install -s @aws-solutions-constructs/aws-eventbridge-lambda'
                ],
                commands: [
                    'npm ci',
                    'npm run build',
                    'npx cdk synth'
                ]
            }
        )
    });
    }
}

After examining the resulting CloudFormation stack, I am puzzled. Although I see an EventBridge rule, there seems to be no provision for the Lambda function.

Could it be that I have misconceived the purpose of the construct, or perhaps made an oversight somewhere?

Answer №1

Your Pipeline is currently not set up to deploy any resources. To enable deployment, it is essential to include stages within your pipeline.

The CDK Workshop you referenced provides detailed information about the code snippet you used:

Currently, your CDK pipeline automatically updates on each commit, but it lacks the functionality to deploy applications. To achieve this, you must integrate a deployment stage into your pipeline.

Here's an example of a basic stage implementation extracted from the workshop. You may need to adjust the stack import based on your specific setup:

import { TimedLambdaStack } from './timed-lambda-stack';
import { Stage, StageProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';

export class WorkshopPipelineStage extends Stage {
    constructor(scope: Construct, id: string, props?: StageProps) {
        super(scope, id, props);

        new TimedLambdaStack(this, 'TimedLambdaStack');
    }
}

To integrate this stage into your pipeline, follow the steps outlined in the workshop:

import * as cdk from 'aws-cdk-lib';
import * as codecommit from 'aws-cdk-lib/aws-codecommit';
import { Construct } from 'constructs';
import {WorkshopPipelineStage} from './pipeline-stage';
import {CodeBuildStep, CodePipeline, CodePipelineSource} from "aws-cdk-lib/pipelines";

export class TimedPipelineStack extends cdk.Stack {
    constructor(scope: Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        // Create a new CodeCommit repository named 'TimedRepo'
        const repo = new codecommit.Repository(this, 'TimedRepo', {
            repositoryName: "TimedRepo"
        });

       // Define the initial structure of our pipeline
       const pipeline = new CodePipeline(this, 'Pipeline', {
            pipelineName: 'TimedLambdaPipeline',
            synth: new CodeBuildStep('SynthStep', {
                    input: CodePipelineSource.codeCommit(repo, 'master'),
                    installCommands: [
                        'npm install -g aws-cdk'
                    ],
                    commands: [
                        'npm ci',
                        'npm run build',
                        'npx cdk synth'
                    ]
                }
            )
        });

        const deploy = new WorkshopPipelineStage(this, 'Deploy');
        const deployStage = pipeline.addStage(deploy);
    }
}

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

What is the best way to bring in a file or subfolder from a folder that has been

Currently, I am facing a situation where I need to specify to TSC in the tsconfig file that I want to include specific files or subfolders from a folder while ignoring others. How can I achieve this? For instance: /. |-folder 1 |->file2.ts |-& ...

Retrieving values from an array in a JSON response using Angular 4

How can I access the SubjectCode field in an array at a table using Angular 4? When trying to do so, I receive the error message: "[Error trying to diff '[object Object]'. Only arrays and iterables are allowed]". Here is the Json Response: { ...

Issue with DynamoDB.putItem function not persisting data when executed within a serverless command

I am currently facing an issue with my Lambda function using the Serverless framework, specifically related to saving data into DynamoDB. Despite running sls invoke local -f scrape -d 'the-last-bookstore-los-angeles', I do not receive any error m ...

Tips for effectively overriding a method in typescript

Why is this.fullName appearing empty in the show() method? class Person { protected name: string = ""; constructor(name: string) { this.makeSir(name); } makeSir(name: string) { this.name = "sir" + name; } } class M ...

How can I adjust the column width in OfficeGen?

Currently, I am utilizing officeGen for the purpose of generating word documents. <sup> let table = [ [ { val: "TT", fontFamily: "Times New Roman", }, { val: "Ten hang", ...

Converting and Casting Enums in TypeScript

Is there a way to convert one enum into another when they have the same values? enum Enum1 { Value = 'example' } enum Enum2 { Value = 'example' } const value = Enum1.Value const value2 = value as Enum2 ...

Guide on developing a custom object type, with keys that are derived from the values in the original object

I'm attempting to transform an object into a dynamically created type, but I'm having difficulty getting it to work correctly. Imagine I have the following object: const constants = { filter: 'flr', color: 'col' } Is ...

Error: The value of the expression has been altered after it was already checked. Initial value was 'undefined'. An exception has occurred

Although this question has been asked multiple times, I have read similar issues and still struggle to organize my code to resolve this particular exception. Within my component, there is a property that dynamically changes based on a condition: public e ...

What sets apart TypeScript's indexed types from function signatures?

I am curious about the distinction between indexed type and function signatures in TypeScript. type A = { _(num: number): void; }['_']; type B = { _(ten: 10): void; }['_']; let a: A = (num) => { console.log(num); }; let b: B ...

Enhancing RTK Query: Efficiently Filtering Query Results in Separate Components

I am currently working on a Todo application using Nextjs 13 with various tools such as app directory, prisma, redux toolkit, shadcnui, and clerk. Within my app, I have implemented two key components - TodoList and Filter. The TodoList component is respons ...

Tips for sending just the updated section of the form

I am working with a form group where I map the values from the form to an object type in order to make a request to edit the item. This is my form structure: public companyForm = new FormGroup( { generalInfo: new FormGroup({ name: new ...

developed a website utilizing ASP MVC in combination with Angular 2 framework

When it comes to developing the front end, I prefer using Angular 2. For the back end, I stick with Asp MVC (not ASP CORE)... In a typical Asp MVC application, these are the steps usually taken to publish the app: Begin by right-clicking on the project ...

Can we leverage Angular service styles in scss?

I am working on a change-color.service.ts file that contains the following code snippet: public defaultStyles = { firstDesignBackgroundColor: '#a31329', firstDesignFontColor: '#ffffff', secondDesignBackgroundColor: '#d1 ...

Function type guards in Typescript do not support type inference

When checking for null in alpha, I validate the result and use throw new Error if needed. However, even after doing so, the compiler still indicates a compilation error: const obj = { objMethod: function (): string | null { return 'always a str ...

Module for importing text without verifying types using wildcards

Here is a unique module definition using the wildcard character: declare module 'custom!*' { const data: string; export default data; } Check out how it's imported: import * as myData from 'custom!./myCustomData.txt'; B ...

Issue: Incorrect hook usage. Hooks are designed to be used within the body of a function component. This error may occur due to one of the following reasons: 1

I've reviewed similar questions and attempted to apply the solutions provided, but it seems I'm missing something specific to my situation. My goal is to streamline my code by importing headers from a utils file and using them across different AP ...

Exploring the creation of an Angular service that utilizes HttpClient for making GET requests, with a focus on the different

I've been diving into Angular lately and I'm facing some challenges with handling get requests. If you're interested, you can check out my code on Angular Stackblitz import { HttpClient} from '@angular/common/http'; import { Inject ...

Distribute SNS alerts to every member who has subscribed to the topic via Lambda

I have developed an E-Commerce iOS application with a backend in nodejs (AWS Lambda). The app subscribes to an SNS Topic I created when a user signs in or logs in, storing their push token and device ARN in the DB to send notifications. Now, I aim to send ...

Having trouble triggering a change event within a React component?

I'm working on a straightforward react-component that consists of a form. Within this form, the user can search for other users. To ensure the form is valid, there needs to be between 3 and 6 users added. To achieve this, I've included a hidden ...

Error encountered while utilizing Array.find with a specific data type

I am trying to locate the user's browser language from a list of supported languages. Here is the code snippet I am using: const userLanguage = browserLanguages.find(language => !!supported[language]); But unfortunately, I'm encountering thi ...