This file contains 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
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 ] } |
This file contains 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
import { APIGatewayEvent, Context } from 'aws-lambda'; | |
import { doSomething } from './utils'; | |
export const handler = async (event: APIGatewayEvent, context: Context) => { | |
doSomething(); | |
// Do some other stuff... | |
} |
This file contains 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
{ | |
"compilerOptions": { | |
"module": "commonjs", | |
"target": "ES2017", | |
"lib": ["ES2019"], | |
"rootDir": "src", | |
"outDir": "dist", | |
"declaration": false, | |
"sourceMap": false, | |
"inlineSources": false, |
This file contains 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
name: Deploy | |
on: | |
push: | |
branches: [ master ] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: |
This file contains 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
const { NodeTracerProvider } = require("@opentelemetry/node"); | |
const provider = new NodeTracerProvider({ | |
plugins: { | |
"aws-sdk": { | |
enabled: true, | |
path: "opentelemetry-plugin-aws-sdk", | |
} | |
} | |
}); |
This file contains 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
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({ |
This file contains 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
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', |
This file contains 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
// 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'); |
This file contains 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
// 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), |
This file contains 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
// node-handler.js | |
export const handle = () => { | |
eval('require')('fs').readFileSync(...); | |
... | |
}; | |
// browser-handler.js | |
export const handle = () => { ... }; | |
// index.js |
NewerOlder