Skip to content

Commit

Permalink
fix: eventType for Cloudwatch doesnt work
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavio Stutz committed Jan 11, 2024
1 parent 9bf5597 commit d7995fb
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ SHELL := /bin/bash

build: install
rm -rf dist
pnpm exec esbuild src/index.ts --bundle --platform=node --minify --outfile=dist/index.js
@# TODO add --minify later
pnpm exec esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js
pnpm exec tsc --emitDeclarationOnly --outDir dist

lint:
pnpm exec eslint . --ext .ts
pnpm exec eslint ./src --ext .ts
pnpm exec tsc -noEmit --skipLibCheck
pnpm audit

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@stoplight/spectral-cli": "^6.11.0",
"@types/npm-which": "^3.0.3",
"@types/tmp": "^0.2.6",
"aws-cdk-lib": "^2.118.0",
"aws-cdk-lib": "^2.117.0",
"constructs": "^10.3.0",
"fs": "0.0.1-security",
"npm-which": "^3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/lambda/lambda-base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('lambda-base', () => {

const f = (): void => {
// eslint-disable-next-line no-new
new BaseNodeJsFunction(stack, 'test-lambda', {
new BaseNodeJsFunction(stack, 'test-lambda1', {
stage: 'dev',
eventType: EventType.Http,
baseCodePath: 'src/lambda/__tests__',
Expand All @@ -142,6 +142,17 @@ describe('lambda-base', () => {

expect(func.nodeJsFunction.isBoundToVpc).toBe(false);

const f2 = (): void => {
// eslint-disable-next-line no-new
new BaseNodeJsFunction(stack, 'test-lambda', {
stage: 'dev',
baseCodePath: 'src/lambda/__tests__',
});
};
expect(f2).toThrow('eventType is required if entry is not defined');

expect(func.nodeJsFunction.isBoundToVpc).toBe(false);

// execute synth and test results
const template = Template.fromStack(stack);
// console.log(JSON.stringify(template.toJSON(), null, 2));
Expand Down
4 changes: 2 additions & 2 deletions src/lambda/lambda-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ServicePrincipal } from 'aws-cdk-lib/aws-iam';

import { vpcFromConfig } from '../utils';

import { EventType, BaseNodeJsProps, LambdaConfig } from './types';
import { BaseNodeJsProps, LambdaConfig } from './types';

// CDK L2 constructs
// Docs: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs.NodejsFunction.html#entry
Expand Down Expand Up @@ -95,7 +95,7 @@ export const getPropsWithDefaults = (
if (!props.eventType) {
throw new Error('eventType is required if entry is not defined');
}
const eventTypeStr = EventType[props.eventType].toLowerCase();
const eventTypeStr = props.eventType.toLowerCase();
entry = `${props.baseCodePath || 'handlers'}/${eventTypeStr}/${id}/index.ts`;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lambda/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export type LambdaConfig = NodejsFunctionProps & {
};

export enum EventType {
Cloudwatch,
Http,
Cloudwatch = 'cloudwatch',
Http = 'http',
}

export type BaseNodeJsProps = LambdaConfig & {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"sourceMap": true,
"declaration": true
},
"include": ["**/*"],
"include": ["src/**/*", ".eslintrc.js", "jest.config.js"],
"exclude": ["node_modules", "**/*.spec.ts"]
}

0 comments on commit d7995fb

Please sign in to comment.