This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // based on https://gist.github.com/tony-gutierrez/de5b304fd042f6140eb61a31d0ff92d5 | |
| async function isLeader() { | |
| try { | |
| // get APIs | |
| var elasticbeanstalk = new AWS.ElasticBeanstalk(); | |
| var ec2 = new AWS.EC2(); | |
| var metadata = new AWS.MetadataService(); | |
| // get ec2 instance id | |
| const request = new Promise( (resolve, reject) => { // MetadataService.request has no support for promise, make one ourselves | |
| metadata.request('/latest/meta-data/instance-id', (err, InstanceId) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| If saving AWS creds locally they need to be in ~/.aws/credentials | |
| [default] | |
| aws_access_key_id = foo | |
| aws_secret_access_key = bar | |
| */ | |
| const puppeteer = require('puppeteer'); | |
| const AWS = require('aws-sdk'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Prevent cron tasks from being ran by multiple instances in Elastic Beanstalk. | |
| # Automatically adjusts to new "leading instance" when scaling up or down. | |
| # Stores the result in an environment variable for other uses as AWS_EB_CRON | |
| # | |
| # This must be ran by cron as the root user to function correctly. | |
| # Anything after this file will be executed as webapp for security. | |
| # | |
| # Example Cron (should be created by .ebextensions): |