Real Example/Docs Setting Up Job Trigger on AWS ELB?

Trying to figure out how to “actually” setup a cloud job trigger in AWS ELB.

I have a job setup that works when triggered manually but trying to follow the so called docs on setting up the AWS ELB trigger is pretty much worthless (as expected).

I put a cron.yaml file in the project root. I added:
version: 1

cron:
- name: “deleteMessagesJob”
url: “/jobs/deleteMessagesJob”
schedule: “*/1 * * * *”

To the file. I’ve tried both /jobs/deleteMessagesJob & /parse/jobs/deleteMessagesJob.

I have no idea if I’m putting the file in the right place, no idea of I’m putting the correct path, no idea if there’s more info I need to pass somehow such as header info, nothing.

Docs are pretty worthless when they leave 90% of what you have to do up to guessing and voodoo magic. Surely we can do better than “refer to AWS’s worthless docs” for something as popular as AWS ELB.

I’m pretty sure putting the file in the root of the project files is the correct place since if I mess with the format it breaks on deploy.

I’m about 99% sure at this point that it comes down to passing header info which there doesn’t seem to be a way to do through the yaml file.

I’m guessing I have to setup a lambda function to do this.

Will hit it again tomorrow and see if I can beat it into submission. If so I’ll post the solution on here so hopefully someone else doesn’t have to beat their head against the desk for hours on end trying to solve this thing.

A solution could be to use AWS Event Bridge and create a job that invokes a AWS Lambda function which calls the Parse Server job endpoint. It allows you to pass arguments in the request to Parse Server.

I am not 100% sure what you are trying to achieve, but I use the following code in my index.js (main express app) to do daily maintenance tasks in my server:

var schedule = require('node-schedule');

//Do my task every day at 7:00 GMT - Server Time
schedule.scheduleJob('0 7 * * *', function() {
    var options = {
        url: process.env.SERVER_URL + '/functions/doMyTask',
        headers: {
            'X-Parse-Application-Id': process.env.APP_ID,
            'X-Parse-Master-Key': process.env.MASTER_KEY,
            'Content-Type': 'application/json'
        }
    };
    request.post(options, function (error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log(body);
        }
    });
});

I was able to create an eventbridge scheduler and lambda function and it works!

Super easy once you know what to do. I didn’t even know eventbridge scheduler was a thing until yesterday lol.

HERE’S HOW MY LAMBDA FUNCTION LOOKS:

import http from 'https';

export const handler = (event, context) => {
    httprequest().then((data) => {
        const response = {
            statusCode: 200,
            body: JSON.stringify(data),
        };
        return response;
    });

    function httprequest() {
        return new Promise((resolve, reject) => {
            const headers = {
                'Content-Type': 'application/json',
                'X-Parse-Application-Id': process.env.APP_ID,
                'X-Parse-Master-Key': process.env.MASTER_KEY
            };

            const options = {
                host: 'mydomain.com',
                path: '/pathtoparse/jobs/myJob',
                port: 443,
                method: 'POST',
                headers: headers
            };

            const req = http.request(options, (res) => {
                if (res.statusCode < 200 || res.statusCode >= 300) {
                    return reject(new Error('statusCode=' + res.statusCode));
                }
                var body = [];
                res.on('data', function(chunk) {
                    body.push(chunk);
                });
                res.on('end', function() {
                    try {
                        body = JSON.parse(Buffer.concat(body).toString());
                    } catch(e) {
                        reject(e);
                    }
                    resolve(body);
                });
            });
            req.on('error', (e) => {
                reject(e.message);
            });
            // send the request
            req.end();
        });
    }
};