Skip to content

Instantly share code, notes, and snippets.

View RAMPKORV's full-sized avatar

RAMPKORV RAMPKORV

  • Reguity Group AB
  • Gothenburg, Sweden
View GitHub Profile
@ayavilevich
ayavilevich / aws_ebs_leader.js
Created February 19, 2019 18:28
AWS Elastic Beanstalk "is leader instance" check for use with cron, etc (nodejs, async/await).
// 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) => {
@litzinger
litzinger / index.js
Last active December 21, 2021 17:01
Simple Puppeteer screenshot script
/*
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');
@heathdutton
heathdutton / aws-eb-cron.sh
Last active August 16, 2020 09:45
Execute cron tasks in elastic beanstalk on only one instance with this.
#!/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):