Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen2: Scheduled Lambdas are not possible anymore #1491

Open
3 tasks done
jgo80 opened this issue May 10, 2024 · 4 comments · May be fixed by #1527
Open
3 tasks done

Gen2: Scheduled Lambdas are not possible anymore #1491

jgo80 opened this issue May 10, 2024 · 4 comments · May be fixed by #1527
Labels
feature-request New feature or request function Issue pertaining to Amplify Function p4

Comments

@jgo80
Copy link

jgo80 commented May 10, 2024

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

Not applicable

Amplify Version

v6

Amplify Categories

function

Backend

Amplify Gen 2 (Preview)

Environment information

# Put output below this line


Describe the bug

In Gen 2 "Scheduled Lambdas" are not possible anymore. How do do it?

The Documentation introduces Functions to be capable of Scheduled jobs, but there is no hint how to achieve it.

The situation feels very unpleasant. The documentation clearly recommends switching from Gen 1 to Gen 2 and raises fears that Gen 1 will not be available forever. At the same time, fundamental functions are missing (for the moment?) in Gen 2.

Expected behavior

I would love to see something like this:

import { defineFunction } from '@aws-amplify/backend';
import * as events from '@aws-cdk/aws-events';

export const myScheduleFunction = defineFunction({
  name: 'schedule-function',
  schedule: events.Schedule.rate(cdk.Duration.hours(1)),
});

Reproduction steps

Feature is missing, no reproduction

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@jgo80 jgo80 added the pending-triage Incoming issues that need categorization label May 10, 2024
@jgo80
Copy link
Author

jgo80 commented May 10, 2024

I managed it through CDK. Maybe you can adopt my suggested API for configuring Functions anyway 🙏?

import { defineBackend } from '@aws-amplify/backend';
import * as cdk from 'aws-cdk-lib';
import * as events from 'aws-cdk-lib/aws-events';
import * as targets from 'aws-cdk-lib/aws-events-targets';
import { auth } from './auth/resource';
import { data } from './data/resource';
import { scheduledfunction } from './functions/scheduled-function/resource';

const backend = defineBackend({
  auth,
  data,
  scheduledfunction,
});

// Create a new EventBridge rule that is triggered every hour
const rule = new events.Rule(
  backend.scheduledfunction.resources.lambda,
  'Rule',
  {
    description: 'Rule that triggers the lambda function every hour',
    schedule: events.Schedule.rate(cdk.Duration.hours(1)),
  },
);

// Add the lambda function as a target for the rule
rule.addTarget(
  new targets.LambdaFunction(backend.scheduledfunction.resources.lambda),
);

@israx israx transferred this issue from aws-amplify/amplify-js May 10, 2024
@ykethan ykethan transferred this issue from aws-amplify/amplify-cli May 10, 2024
@ykethan ykethan added the function Issue pertaining to Amplify Function label May 10, 2024
@ykethan
Copy link
Contributor

ykethan commented May 10, 2024

Hey @jgo80, thank you for reaching out. Marking this as feature request.

@ykethan ykethan added feature-request New feature or request and removed pending-triage Incoming issues that need categorization labels May 10, 2024
@MarlonJD
Copy link

I managed it through CDK. Maybe you can adopt my suggested API for configuring Functions anyway 🙏?

import { defineBackend } from '@aws-amplify/backend';
import * as cdk from 'aws-cdk-lib';
import * as events from 'aws-cdk-lib/aws-events';
import * as targets from 'aws-cdk-lib/aws-events-targets';
import { auth } from './auth/resource';
import { data } from './data/resource';
import { scheduledfunction } from './functions/scheduled-function/resource';

const backend = defineBackend({
  auth,
  data,
  scheduledfunction,
});

// Create a new EventBridge rule that is triggered every hour
const rule = new events.Rule(
  backend.scheduledfunction.resources.lambda,
  'Rule',
  {
    description: 'Rule that triggers the lambda function every hour',
    schedule: events.Schedule.rate(cdk.Duration.hours(1)),
  },
);

// Add the lambda function as a target for the rule
rule.addTarget(
  new targets.LambdaFunction(backend.scheduledfunction.resources.lambda),
);

That's what I exactly what I was looking into. Thank you so much for sharing this.
BTW. This feature request would be very helpful in future.

@mtliendo
Copy link

Worth noting that gen1 used Cloudwatch Events. This feature has been sunset by AWS. Trying to create a Cloudwatch event in the AWS console will now redirect customers to create an EventBridge rule. As such, if just wanting a way to mirror the behavior found in gen1, the answer provided by the OP is the solution.

For a more feature rich experience in creating scheduled tasks, either one time or recurring, EventBridge Scheduler is a better solution. This blog posts explains the differences: https://aws.amazon.com/blogs/compute/introducing-amazon-eventbridge-scheduler/

@josefaidt josefaidt linked a pull request May 19, 2024 that will close this issue
4 tasks
@josefaidt josefaidt added the p4 label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request function Issue pertaining to Amplify Function p4
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants