@@ -71,6 +71,11 @@ export class LambdaStack extends cdk.Stack {
7171 */
7272 public readonly updateTaskFunction : NodejsFunction ;
7373
74+ /**
75+ * The delete task Lambda function.
76+ */
77+ public readonly deleteTaskFunction : NodejsFunction ;
78+
7479 constructor ( scope : Construct , id : string , props : LambdaStackProps ) {
7580 super ( scope , id , props ) ;
7681
@@ -198,6 +203,37 @@ export class LambdaStack extends cdk.Stack {
198203 // Grant the Lambda function read and write access to the DynamoDB table
199204 props . taskTable . grantReadWriteData ( this . updateTaskFunction ) ;
200205
206+ // Create the delete task Lambda function
207+ this . deleteTaskFunction = new NodejsFunction ( this , 'DeleteTaskFunction' , {
208+ functionName : `${ props . appName } -delete-task-${ props . envName } ` ,
209+ runtime : lambda . Runtime . NODEJS_24_X ,
210+ handler : 'handler' ,
211+ entry : path . join ( __dirname , '../../src/handlers/delete-task.ts' ) ,
212+ environment : {
213+ TASKS_TABLE : props . taskTable . tableName ,
214+ ENABLE_LOGGING : props . enableLogging . toString ( ) ,
215+ LOG_LEVEL : props . loggingLevel ,
216+ LOG_FORMAT : props . loggingFormat ,
217+ } ,
218+ timeout : cdk . Duration . seconds ( 10 ) ,
219+ memorySize : 256 ,
220+ bundling : {
221+ minify : true ,
222+ sourceMap : true ,
223+ } ,
224+ loggingFormat : lambda . LoggingFormat . JSON ,
225+ applicationLogLevelV2 : lambda . ApplicationLogLevel . INFO ,
226+ systemLogLevelV2 : lambda . SystemLogLevel . INFO ,
227+ logGroup : new logs . LogGroup ( this , 'DeleteTaskFunctionLogGroup' , {
228+ logGroupName : `/aws/lambda/${ props . appName } -delete-task-${ props . envName } ` ,
229+ retention : props . envName === 'prd' ? logs . RetentionDays . ONE_MONTH : logs . RetentionDays . ONE_WEEK ,
230+ removalPolicy : props . envName === 'prd' ? cdk . RemovalPolicy . RETAIN : cdk . RemovalPolicy . DESTROY ,
231+ } ) ,
232+ } ) ;
233+
234+ // Grant the Lambda function read and write access to the DynamoDB table
235+ props . taskTable . grantReadWriteData ( this . deleteTaskFunction ) ;
236+
201237 // Create API Gateway REST API
202238 this . api = new apigateway . RestApi ( this , 'LambdaStarterApi' , {
203239 restApiName : `${ props . appName } -api-${ props . envName } ` ,
@@ -232,6 +268,9 @@ export class LambdaStack extends cdk.Stack {
232268 // Add PUT method to /tasks/{taskId}
233269 taskResource . addMethod ( 'PUT' , new apigateway . LambdaIntegration ( this . updateTaskFunction ) ) ;
234270
271+ // Add DELETE method to /tasks/{taskId}
272+ taskResource . addMethod ( 'DELETE' , new apigateway . LambdaIntegration ( this . deleteTaskFunction ) ) ;
273+
235274 // Output the API URL
236275 new cdk . CfnOutput ( this , 'ApiUrl' , {
237276 value : this . api . url ,
@@ -273,5 +312,12 @@ export class LambdaStack extends cdk.Stack {
273312 description : 'ARN of the update task Lambda function' ,
274313 exportName : `${ props . appName } -update-task-function-arn-${ props . envName } ` ,
275314 } ) ;
315+
316+ // Output the delete task function ARN
317+ new cdk . CfnOutput ( this , 'DeleteTaskFunctionArn' , {
318+ value : this . deleteTaskFunction . functionArn ,
319+ description : 'ARN of the delete task Lambda function' ,
320+ exportName : `${ props . appName } -delete-task-function-arn-${ props . envName } ` ,
321+ } ) ;
276322 }
277323}
0 commit comments