Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to add X-Amz-Invocation-Type:Event to existing API Gateway POST method

First, the basic question - is there a straightforward way to add the HTTP header X-Amz-Invocation-Type:'Event' to an existing API Gateway POST method with Integration Type Lambda Function so that I can easily launch an asynchronous Lambda from my existing endpoint?

Now the background...

I have an API Gateway with a POST method, Integration type Lambda Function that works quite well for me via curl and Javascript, except for the 29s API timeout.

Through some searching, I think I've learned that setting up an HTTP header X-Amz-Invocation-Type:'Event' is what I would need to get my Lambda function to run asynchronously.

I've seen advice that suggests going through the console and using an AWS Service integration type, then adding in the header along with mapping templates and such, and this is far more complicated than I really want to try (maybe I don't have a choice?). I tried, but I "think" I end up having to deal with mapping templates, and I have a pretty complicated payload - does it really have to be this hard?

I've also seen suggestions to use two Lambdas, the first one is triggered through the API and is synchronous, and triggers the asynchronous one. I know how to do this, and it does have advantages (but also added complexity), but I'm putting that aside for now.

I read one post that "hinted" that it might be possible to add this new HTTP header via CLI. I've done a bit of trial and error with things like aws.apigateway.put_method() etc., but I'm kind of shooting in the dark. I like to think there's an easy way to do this, but the solution is evading me up to now.

like image 988
DonMorton Avatar asked Sep 22 '18 02:09

DonMorton


People also ask

How do I add a resource to API gateway?

Add ResourcesSelect the /api resource. Then Click on "Actions" and in the drop-down list select "Create Resource". Enter basket for resource name, the resource path will be automatically filled in. Then check "Enable API Gateway CORS." Finally, click "Create Resource".

What is invoke URL in AWS API gateway?

You can find a REST API's root URL in the Stage Editor for the API in the API Gateway console. It's listed as the Invoke URL at the top. If the API's root resource exposes a GET method without requiring user authentication, you can call the method by clicking the Invoke URL link.


1 Answers

I've faced this isssue also here is how I found the Header should be define: in the panel "Integration Request" of your POST method: screenshot here

The single quotes around 'Event' are important, so I've read (as it is a static value). With this set up, you can test your method and you will receive an instant (well ~100ms after) 200 code.

like image 119
Sarah Fnc Avatar answered Sep 29 '22 01:09

Sarah Fnc