turbo-remote-cache-construct
Version:
A Turborepo Remote Cache implementation using AWS API Gateway, Lambda, S3, and DynamoDB.
2 lines (1 loc) • 995 B
JavaScript
import{DynamoDBClient as n,QueryCommand as i}from"@aws-sdk/client-dynamodb";import{unmarshall as y}from"@aws-sdk/util-dynamodb";var d=new n({}),u=process.env.EVENTS_TABLE_NAME,f=async a=>{if(!a.body)return{statusCode:400,body:JSON.stringify({message:"No body provided"})};let{hashes:o}=JSON.parse(a.body);if(!Array.isArray(o))return{statusCode:400,body:JSON.stringify({message:"Invalid request body, expected an array of hashes"})};try{let r={};for(let s of o){let e=await d.send(new i({TableName:u,KeyConditionExpression:"#artifactHash = :hash",ExpressionAttributeNames:{"#artifactHash":"hash"},ExpressionAttributeValues:{":hash":{S:s}},Limit:1,ScanIndexForward:!1}));if(e.Items&&e.Items.length>0){let t=y(e.Items[0]);r[s]={size:t.size,taskDurationMs:t.duration,tag:t.tag}}else r[s]=null}return{statusCode:200,body:JSON.stringify(r)}}catch(r){return console.error("Error querying artifacts:",r),{statusCode:500,body:JSON.stringify({message:"Error querying artifacts"})}}};export{f as handler};