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
'use strict'; | |
let clearAll = () => global.CONTEXT = undefined; | |
let replaceAllWith = ctx => global.CONTEXT = ctx; | |
let set = (key, value) => { | |
if (!key.startsWith("x-correlation-")) { | |
key = "x-correlation-" + key; | |
} |
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
'use strict'; | |
const co = require('co'); | |
const _ = require('lodash'); | |
const AWS = require('aws-sdk'); | |
const s3 = new AWS.S3(); | |
// Data loaded from S3 and chached in case of recursion. | |
let cached; |
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
module.exports.handler = (event, context, callback) => { | |
let position = event.position || 0; | |
do { | |
... // process the tasks in small batches that can be completed in, say, less than 10s | |
// when there's less than 10s left, stop | |
} while (position < totalTaskCount && context.getRemainingTimeInMillis() > 10000); | |
if (position < totalTaskCount) { | |
let newEvent = Object.assign(event, { position }); |
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
{ | |
"Comment": "Applying the Saga pattern with AWS Lambda and Step Functions", | |
"StartAt": "BookHotel", | |
"States": { | |
"BookHotel": { | |
"Type": "Task", | |
"Resource": "arn:aws:lambda:us-east-1:{AccountID}:function:lambda-saga-dev-book-hotel", | |
"Catch": [ | |
{ | |
"ErrorEquals": ["States.ALL"], |
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
type Player = { Name: string; Score: int; Id: System.Guid } | |
type PlayerDTO = | |
{ Name: string; Score: int; Id: string } | |
with static member op_Implicit(p: Player) : PlayerDTO = | |
{ Name = p.Name; Score = p.Score; Id = p.Id.ToString() } | |
let p: Player = { Name = "Yan"; Score = 42; Id = System.Guid.NewGuid() } | |
let dto = PlayerDTO.op_Implicit(p) |
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
using System; | |
public sealed class Player | |
{ | |
public Player(string name, long score) | |
{ | |
Name = name; | |
Score = score; | |
Id = Guid.NewGuid().ToString(); | |
} |
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
let publishSNS = segment => { | |
return new Promise((resolve, reject) => { | |
console.log('publishing to SNS topic'); | |
let f = co.wrap(function* (subsegment) { | |
... | |
subsegment.addAnnotation('topic', topicArn); | |
subsegment.addMetadata('message', 'test'); | |
let req = { |
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
'use strict'; | |
const AWSXRay = require('aws-xray-sdk'); | |
const https = AWSXRay.captureHTTPs(require('https')); | |
console.log(AWSXRay); | |
let request = (method, hostname, path) => { | |
const options = { hostname, port: 443, path, method }; |
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
// ... omitted for brevity | |
module.exports.handler = co.wrap(function* (event, context, callback) { | |
console.log(JSON.stringify(event)); | |
console.log(JSON.stringify(context)); | |
global.hostname = event.headers.Host; | |
global.accountId = event.requestContext.accountId; | |
global.requestId = event.requestContext.requestId; |
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
'use strict'; | |
const co = require('co'); | |
const Promise = require('bluebird'); | |
const AWS = require('aws-sdk'); | |
const cloudwatch = Promise.promisifyAll(new AWS.CloudWatch()); | |
let isColdstart = false; | |
let trackColdstart = co.wrap(function* (funcName) { |