Skip to content

Instantly share code, notes, and snippets.

View nirsky's full-sized avatar

Nir Hadassi nirsky

View GitHub Profile
const items = [{ key: 'a', value: 1 }, { key: 'a', value: 2 }, { key: 'b', value: 3 }, { key: 'b', value: 4 }];
const hashMap = items.reduce((acc, current) => {
if (!acc[current.key]) acc[current.key] = [];
acc[current.key].push(current.value);
return acc;
}, {});
console.log(hashMap); // { a: [ 1, 2 ], b: [ 3, 4 ] }
import { APIGatewayEvent, Context } from 'aws-lambda';
import { doSomething } from './utils';
export const handler = async (event: APIGatewayEvent, context: Context) => {
doSomething();
// Do some other stuff...
}
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2017",
"lib": ["ES2019"],
"rootDir": "src",
"outDir": "dist",
"declaration": false,
"sourceMap": false,
"inlineSources": false,
name: Deploy
on:
push:
branches: [ master ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
const { NodeTracerProvider } = require("@opentelemetry/node");
const provider = new NodeTracerProvider({
plugins: {
"aws-sdk": {
enabled: true,
path: "opentelemetry-plugin-aws-sdk",
}
}
});
import { Ec2TaskDefinition, Scope, ContainerDefinition } from '@aws-cdk/aws-ecs';
// Create TaskDefinition
const taskDefinition = new Ec2TaskDefinition(...);
// Add EBS volume, this will also create the volume
// Look here to understand all the options:
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-volumes.html
const VOLUME_NAME = 'my-ebs-volume';
taskDefinition.addVolume({
import { Policy, PolicyStatement } from '@aws-cdk/aws-iam';
// Give our EC2 instance the needed permissions to manage EBS
const ec2PolicyEbs = new Policy(stack, 'ec2-policy-create-ebs', {
policyName: 'REXRay-EBS',
statements: [
PolicyStatement.fromJson({
Effect: 'Allow',
Action: [
'ec2:AttachVolume',
// Make sure to set the right EBS_REGION
autoScalingGroup.addUserData('docker plugin install rexray/ebs REXRAY_PREEMPT=true EBS_REGION=eu-west-1 --grant-all-permissions \nstop ecs \nstart ecs');
// Create your ECS cluster, don't use the capacity option.
// We will add it in a different statement so we can keep the returned AutoScalingGroup
const ecsCluster = new ecs.Cluster(this, 'ecs-cluster', {
vpc: myVPC,
clusterName: 'my-cluster',
// ...other props
});
const autoScalingGroup: AutoScalingGroup = ecsCluster.addCapacity('cluster-capacity', {
instanceType: InstanceType.of(InstanceClass.T2, InstanceSize.LARGE),
// node-handler.js
export const handle = () => {
eval('require')('fs').readFileSync(...);
...
};
// browser-handler.js
export const handle = () => { ... };
// index.js