Skip to content

Instantly share code, notes, and snippets.

View celalo's full-sized avatar

Celal Baris Ozdemir celalo

View GitHub Profile
@hayd
hayd / elastic-beanstalk-log-prefix.md
Last active June 27, 2023 12:28
Modify elastic beanstalk default log output prefix

By default elastic beanstalk logs are prefixed by the date and the ip. This is may not be desired, either because the date is also in the logs or because the timestamp is included in cloudwatch logs metadata.

We can remove it by adding two hooks (both with the same content):

  • .platform/hooks/predeploy/10_logs.sh
  • .platform/confighooks/predeploy/10_logs.sh

Note: You must ensure these are executable before packaing (chmod +x).

@sindresorhus
sindresorhus / esm-package.md
Last active November 14, 2024 05:44
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@sjlu
sjlu / Migrating from Amazon Linux to Amazon Linux 2 with Elastic Beanstalk and Node.js.md
Last active September 12, 2023 08:56
Migrating from Amazon Linux to Amazon Linux 2 with Elastic Beanstalk and Node.js

This file is a log of everything I've encountered when trying to migrate a Node.js, Elastic Beanstalk application from the Amazon Linux platform to the Amazon Liunx 2 platform. Here's why you should migrate:

  1. LTS support up to 2023 source
  2. The Amazon Linux AMI's end-of-life is December, 2020 source
  3. Amazon Linux 2 has some big package upgrades (GCC, Glibc, etc.)
  4. Elastic Beanstalk also has some upgrades on top of Amazon Linux 2 (e.g. faster deploys)

Challenges

Disabling NPM install

@vivekbeas
vivekbeas / 02_proxy.config
Created April 28, 2020 23:11
Nginx secure server configuration for AWS Elastic beanstalk
files:
"/etc/nginx/conf.d/02_proxy.conf":
mode: "00644"
owner: root
group: root
content: |
server_tokens off;
add_header Content-Security-Policy "script-src 'self'";
@brianleroux
brianleroux / BeforeExitListener.js
Created September 12, 2019 22:04
Lambda NodeJS 10.x Default Runtime JavaScript
/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
"use strict";
/**
* The runtime has a single beforeExit function which is stored in the global
* object with a symbol key.
* The symbol is not exported.
* The process.beforeExit listener is setup in index.js along with all other
* top-level process event listeners.
*/
@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) => {
@andyrbell
andyrbell / scanner.sh
Last active November 3, 2024 13:42
Make a pdf look scanned using ImageMagick
# use ImageMagick convert
# the order is important. the density argument applies to input.pdf and resize and rotate to output.pdf
convert -density 90 input.pdf -rotate 0.5 -attenuate 0.2 +noise Multiplicative -colorspace Gray output.pdf
@thomasmichaelwallace
thomasmichaelwallace / nodelogs_fix.config
Created July 26, 2017 16:26
An ebextension to fix node log streaming after rotation.
files:
"/etc/cron.hourly/cron.logrotate.elasticbeanstalk.nodejs.conf":
mode: "000655"
owner: root
group: root
content: |
#!/bin/sh
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.elasticbeanstalk.hourly/logrotate.elasticbeanstalk.nodejs.conf
/sbin/service awslogs restart
@tomodian
tomodian / firehose-to-athena.js
Created February 28, 2017 15:22
Firehose to Athena
'use strict';
const aws = require('aws-sdk');
const s3 = new aws.S3({ apiVersion: '2006-03-01' });
exports.handler = (event, context, callback) => {
const key = decodeURIComponent(event.Records[0].s3.object.key);
const meta = key.split('/');
@pcan
pcan / README.md
Last active October 17, 2024 05:56
Node.js plain TLS Client & Server, 2-way Cert Auth

Node.js TLS plain TLS sockets

This guide shows how to set up a bidirectional client/server authentication for plain TLS sockets.

Newer versions of openssl are stricter about certificate purposes. Use extensions accordingly.

Prepare certificates

Generate a Certificate Authority: