create_import_job() on Lambda using Amazon Pinpoint API

0

I'm trying to use this code, to create a single lambda function that will Import a Segment from an S3 bucket and after that use the response from it, so I can pass it to the create_campaign() function, and send a sample Push Campaign right away after importing Enter image description here

Since I need a segment ID from the create_import_job_response before running the create_campaign , I need to wait for it to finish first. After its is finish ,I was able to get the segment ID(checking from the function logs) right after I run the lambda function.

Enter image description here

But I wasn't able to use it right away when giving it to the create_campaign() and giving this error.Enter image description here

I'm aware that the reason of this is that the import job status is not yet completed or in a In progress state so thats why its giving its error. We tried a work around and implemented a for loop that will check the import job status until we get the COMPLETED status, it works.We even added a WAIT state and set it for 5secs and it works also. But, still not yet convinced to this solution since for the pricing of Lambda it bills every milliseconds it runs the function, and for a larger scale it will be a waste if we run this loop over and over again just to get the **COMPLETED **status, and still not running what is the main function is which is to send the campaign.

Enter image description here

Is there any way or best practice on running the create_import_job function? That will give the COMPLETED job status right away as long it is finish when called? I'm still currently searching for any solution but still no luck. Any sample article or code will help if anyone knows or encountered this same issue, Thank you!

No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions