Skip to content

Commit 505ea69

Browse files
committed
Add inline log group support to LambdaFunctions
Allow a log group to be configured directly on a lambda function via the new optional `log` field, avoiding the need to declare a separate CloudWatch log group resource. The log group name defaults to the conventional /aws/lambda/{function_name} path when not explicitly set.
1 parent 6b9f3c8 commit 505ea69

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

core/tf-aws/src/composites/lambda/LambdaFunctions.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { DataArchiveFile, Output, useArchiveFile } from '@dinghy/tf-common'
1616
import { IamRole } from '../iam/IamRole.tsx'
1717
import { extendStyle } from '@dinghy/base-components'
1818
import { LAMBDA_FUNCTION } from '@dinghy/diagrams/entitiesAws18Compute'
19+
import { LogGroups } from '../cloudwatch/LogGroups.tsx'
1920

2021
export function LambdaFunctions(
2122
{ _components, children, ...props }: NodeProps,
@@ -65,6 +66,9 @@ export function LambdaFunctions(
6566
)}
6667
{_lambda.archiveDir && <SourceFile />}
6768
{_lambda.functionUrl && <FunctionUrl />}
69+
{_lambda.log && (
70+
<LogGroups logGroups={{ [_lambda.log.name]: _lambda.log }} />
71+
)}
6872
</LambdaFunctionComponent>
6973
)
7074

core/tf-aws/src/composites/lambda/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { z } from 'zod'
99
import { AwsLambdaFunctionInputSchema } from '../../services/lambda/AwsLambdaFunction.tsx'
1010
import { existsSync } from '@std/fs/exists'
11+
import { LogGroupSchema } from '../cloudwatch/types.ts'
1112

1213
const LambdaFunctionUrlSchema = z.object({
1314
authorization_type: z.enum(['NONE', 'AWS_IAM']).default('NONE'),
@@ -42,6 +43,7 @@ const LambdaFunctionSchema = AwsLambdaFunctionInputSchema.extend({
4243
// discover the URL through other means (resource_for_each, the AWS
4344
// console) and outputs leak from the stack's root.
4445
outputRecord: z.boolean().default(false),
46+
log: LogGroupSchema.optional(),
4547
})
4648

4749
const LambdaFunctionsSchema = z.record(
@@ -74,6 +76,9 @@ export function parseLambdaFunctions(
7476
) {
7577
lambda.function_name ??= name
7678
lambda._title ??= lambda.function_name
79+
if (lambda.log) {
80+
lambda.log.name ??= `/aws/lambda/${lambda.function_name}`
81+
}
7782
if (!lambda.image_uri && !lambda.s3_bucket && !lambda.archiveDir) {
7883
if (lambda.prepareSourceScript) {
7984
const outputFolder =

0 commit comments

Comments
 (0)