AWS - Make multiple HTTP requests in pipeline resolver function

18 Views Asked by At

I have this pipeline resolver that has two functions, first function scans a DynamoDB.

Second function reads the data from the scan and then makes an HTTP request to an s3 bucket (I did it this way because you can't put s3 as data source), reading the key from the database scan.

My problem comes when the first function returns more than one item, is there a way to run the second function as many times as items are returned from the scan?

Here's the code of the second function that makes the request for the first element, first function is just a regular dynamodb scan request and it's working fine so I'm just posting this one.

export function request(ctx) {
    if(ctx.prev.result.items.length > 0){
      if(ctx.prev.result.items[0].Images_s3 != null){
        return {
            "version": "2018-05-29",
            "method": "GET",
            "resourcePath": "/" + ctx.prev.result.items[0].Images_s3
        } 
      }
    }
    return{
        "version": "2018-05-29",
        "method": "GET",
        "resourcePath": "/"
    }
}

export function response(ctx) {
    let res = ctx.prev.result;
    if(JSON.parse(ctx.result.body).Images != null){
        res.items[0].Images =  JSON.parse(ctx.result.body).Images;
    }
    return res;
}

All I can think about is making a lambda function to deal with it but that would probably take up too much execution time.

0

There are 0 best solutions below