‫Okay, so let's create a new resource.
‫And this resource I'm going to call mapping.
‫And I'm going to demo mapping templates.
‫So I'll create this resource.
‫And this time we're going to create a GET method.
‫So I'll create a method called GET.
‫And okay.
‫And I'm going to choose a Lambda function.
‫So I have to create another Lambda function.
‫So let me copy this and I'm going to create a new function.
‫So this one function I will call
‫lambda-api-gateway-proxy, it's not a proxy anymore,
‫so I will move it.
‫I'll just say mapping-get.
‫Here we go.
‫The runtime is gonna be Python 3.8.
‫And I will create this function.
‫So this function is going to return
‫just a simple JSON document.
‫So I'm going to return something, I'm going to type it out.
‫I'm gonna say example.
‫And here, the value of this example is going to be test.
‫Okay, very simple, so if I save this function
‫and test it and create a test event,
‫what it returns is just a simple JSON document
‫called example test.
‫Back in our API Gateway, I'm going to create a method again.
‫And it's going to be GET.
‫And here we go.
‫So this GET is going to be invoking a Lambda function.
‫Not a proxy.
‫And the Lambda region is going to eu-west-2.
‫And the Lambda function itself, I have to get it from here.
‫So I will copy this entire name.
‫And then press save.
‫So this is about to give API Gateway permission
‫to invoke our Lambda function, which I'm happy with.
‫So I'll ask okay.
‫And here we go.
‫So now we can test our Lambda function.
‫So if I click on test, and then pass in the test,
‫I can see that the response says example test.
‫And so the result of this execution
‫this time get passed entirely into our API Gateway.
‫So before we had to say status code 200 and so on
‫because it was a proxy.
‫But this one is not a proxy.
‫And so as such, it returns exactly the result
‫from my Lambda function.
‫So we can play a little bit now.
‫And what we're going to do
‫is that we want to change the Integration Response.
‫So instead of returning this JSON with example test,
‫I wanna change the value of here,
‫maybe I wanna call it other example.
‫And then I'll keep the value sort it straight out.
‫So I will go to my Integration Response and expand this.
‫And expand Mapping Templates.
‫And I will click on application/json.
‫And here I will select an empty.
‫And we are set with a template.
‫So I'm going to expand this.
‫And now this is the JSON I want to return.
‫So I'm going to say, renamed example.
‫So this is the name of my key.
‫And the value of my key is equal to input root dot example.
‫So what we mean by this very simple mapping template
‫is that the example coming from this,
‫the value of which the test is going to be mapped now
‫to the JSON key called renamed example.
‫So we did effectively rename our example.
‫We could add another key with,
‫obviously, we do another value.
‫So we're really free to change however we want
‫this response when we're happy.
‫So I remove the last comma, I'll click on save
‫and save my mapping template.
‫And so now if I execute my method, go to test and test it,
‫now the result I get is renamed example test,
‫another key, another value.
‫So this is a very simple example.
‫Here I used the power of mapping templates
‫to change my response and model it the way I wanted to.
‫Which is very helpful is somehow your Lambda function
‫returns a different kind of output
‫but you still want to maintain some stability
‫for your clients.
‫So you would generate these mapping templates.
‫So that's it.
‫A very one-to-one example, but one that works.
‫I hope you liked it, and I will see you in the next lecture.