{ "kind": "open-flow-workflow", "version": 1, "name": "Invoke an AWS Lambda Function", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_32605aafe3e4a753": { "name": "Run the function", "kind": "start", "inputDefs": [] }, "n_fbc76b8f76fec050": { "inputs": { "functionName": { "kind": "value", "value": "YOUR_FUNCTION_NAME" }, "region": { "kind": "value", "value": "ap-south-1" }, "accessKeyId": { "kind": "unset" }, "secretAccessKey": { "kind": "unset" }, "sessionToken": { "kind": "value", "value": null } }, "name": "Sign the Lambda request", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "functionName" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "region" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "accessKeyId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "secretAccessKey" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "sessionToken" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "authorization" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "amzDate" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "body" } ], "name": "Sign the Lambda request", "moduleId": "n_5ff325a8f837a998", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_b61f2d87a7138641": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fbc76b8f76fec050", "output": "url" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fbc76b8f76fec050", "output": "body" } ] }, "header.Content-Type": { "kind": "value", "value": "application/x-amz-json-1.0" }, "header.Authorization": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fbc76b8f76fec050", "output": "authorization" } ] }, "header.X-Amz-Date": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fbc76b8f76fec050", "output": "amzDate" } ] }, "header.X-Amz-Invocation-Type": { "kind": "value", "value": "RequestResponse" }, "header.X-Amz-Security-Token": { "kind": "value", "value": null } }, "name": "Invoke Lambda", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.Content-Type" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.Authorization" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.X-Amz-Date" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.X-Amz-Invocation-Type" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.X-Amz-Security-Token" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "body" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Invoke Lambda", "executor": { "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [ "Content-Type", "Authorization", "X-Amz-Date", "X-Amz-Invocation-Type", "X-Amz-Security-Token" ] }, "bodyFormat": "text", "authentication": { "type": "none" }, "responseFormat": "auto", "statusPolicy": "success", "kind": "http-request" } } }, "n_91b70c1e166d1030": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_b61f2d87a7138641", "output": "body" } ] }, "headers": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_b61f2d87a7138641", "output": "headers" } ] } }, "name": "Check the invocation", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "result" } ], "name": "Check the invocation", "moduleId": "n_b7e357d03434e96e", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_b0b88c54e91d5611": { "name": "Function result", "kind": "outputs", "outputDefs": [ { "jsonSchema": {}, "nullable": true, "handle": "result" } ], "outputMappings": { "result": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_91b70c1e166d1030", "output": "result" } ] } } } }, "edges": [ { "source": "n_32605aafe3e4a753", "target": "n_fbc76b8f76fec050" }, { "source": "n_fbc76b8f76fec050", "target": "n_b61f2d87a7138641" }, { "source": "n_b61f2d87a7138641", "target": "n_91b70c1e166d1030" }, { "source": "n_91b70c1e166d1030", "target": "n_b0b88c54e91d5611" } ] } }, "modules": { "n_5ff325a8f837a998": { "name": "Sign the Lambda request", "imports": [], "source": "import{createHash,createHmac}from'node:crypto';\nexport default function sign({functionName,region,accessKeyId,secretAccessKey,sessionToken}){for(const [k,v]of Object.entries({functionName,region,accessKeyId,secretAccessKey}))if(typeof v!=='string'||!v||v.startsWith('YOUR_'))throw Error('Configure '+k);if(!/^[a-z]{2}(?:-[a-z]+){1,2}-[0-9]+$/.test(region))throw Error('Invalid AWS region');const host='lambda.'+region+'.amazonaws.com'+(region.startsWith('cn-')?'.cn':''),path='/2015-03-31/functions/'+encodeURIComponent(functionName)+'/invocations',query='Qualifier=%24LATEST',body='',timestamp=new Date().toISOString().replace(/[:-]|\\.\\d{3}/g,''),date=timestamp.slice(0,8),headers={'content-type':'application/x-amz-json-1.0',host,'x-amz-date':timestamp,'x-amz-invocation-type':'RequestResponse',...(sessionToken?{'x-amz-security-token':sessionToken}:{})},names=Object.keys(headers).sort(),signedHeaders=names.join(';'),canonicalHeaders=names.map(k=>k+':'+headers[k].trim().replace(/\\s+/g,' ')+'\\n').join(''),hash=x=>createHash('sha256').update(x).digest('hex'),hmac=(k,v)=>createHmac('sha256',k).update(v).digest(),scope=date+'/'+region+'/lambda/aws4_request',canonical=['POST',path.replace(/%/g,'%25'),query,canonicalHeaders,signedHeaders,hash(body)].join('\\n'),toSign=['AWS4-HMAC-SHA256',timestamp,scope,hash(canonical)].join('\\n'),key=hmac(hmac(hmac(hmac('AWS4'+secretAccessKey,date),region),'lambda'),'aws4_request'),signature=createHmac('sha256',key).update(toSign).digest('hex');return{url:'https://'+host+path+'?'+query,authorization:'AWS4-HMAC-SHA256 Credential='+accessKeyId+'/'+scope+', SignedHeaders='+signedHeaders+', Signature='+signature,amzDate:timestamp,body};}\n" }, "n_b7e357d03434e96e": { "name": "Check the invocation", "imports": [], "source": "export default function check({body,headers}){if(Object.entries(headers??{}).some(([k,v])=>k.toLowerCase()==='x-amz-function-error'&&v))throw Error('Lambda function failed');if(body&&typeof body==='object'&&body.errorMessage!==undefined)throw Error('Lambda function failed');return{result:body}}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }