AWS Scheduler: ActionAfterCompletion

0

I am trying to create an AWS Schedule from a lambda function. It works in general, but I am not able to set the "ActionAfterCompletion" to DELETE. For some reason, this value is not set with the following SDK Code:

import { SchedulerClient, CreateScheduleCommand, CreateScheduleCommandInput } from '@aws-sdk/client-scheduler';

export async function createSchedule(targetTime: Date, setValue: boolean) {
  const client = new SchedulerClient({ region: 'my-region' });

  const functionName = 'myFunctionName';
  const lambdaFunctionArn = `myArn:${functionName}`;

  const payload = {
    key: setValue
  };

  const scheduleName = `myScheduleName-${targetTime.getTime()}-${setValue}`;

  const scheduleParams: CreateScheduleCommandInput = {
    Name: scheduleName,
    Description: 'My description',
    ScheduleExpression: `at(${targetTime.toISOString().split('.')[0]})`,
    Target: {
      Arn: lambdaFunctionArn,
      RoleArn: 'myRoleArn',
      Input: JSON.stringify(payload),
    },

    FlexibleTimeWindow: {
      Mode: 'OFF',
    },
   ActionAfterCompletion: 'DELETE', // HERE
  };

  const createScheduleCommand = new CreateScheduleCommand(scheduleParams);

  try {
    const response = await client.send(createScheduleCommand);
    console.log('Schedule created:', response);
  } catch (err) {
    console.error('Error:', err);
  }
}

The lambda function calls this method and it works in general, but it just ignores the ActionAfterCompletion: 'DELETE'

Thank you for any help!

nico
질문됨 6달 전186회 조회
1개 답변
0
수락된 답변

The Lambda service doesn't update the included SDK version very often, so it may be that the included SDK still doesn't support that parameter. If this is the case, you will need to include the correct SDK version with your Lambda and not rely on the included one.

profile pictureAWS
전문가
Uri
답변함 6달 전
profile picture
전문가
검토됨 한 달 전
  • Hey Uri, thanks a lot for your answer! Do you know how I can explicitly include a SDK version? And is there a way to find out, what version is included?

  • Just like any other dependency, you need to include it in the zip file/docker image. Look at this for printing the version.

  • Thanks! I'll have a try on that!

    Btw I found out, that indeed this parameter was added just recently, so lambda may not use the current version: https://github.com/aws/aws-sdk-js-v3/commit/a1403dd72102be8055c959a8ae7140acf4f81de2

  • Thanks a lot, Uri. Including the (current) SDK in the lambda solved the problem!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠