AWS API Gateway with IAM Authorization

Ganesh
2 min readOct 1, 2022

--

Enabling and consuming AWS_IAM Authorized API Gateway from Lambda and programming Language

AWS_IAM Authorization

You may have seen many videos or blogs about how to enable/configure IAM authorization in API gateway and testing it through postman. But how to access it through coding?. Let’s see how it is done.

You can use any HTTP client(Ex: HttpClient in C# or Axios in JS) to invoke API Gateway but if the Gateway is secured through AWS_IAM then we first need to sign the request before invoking. We need to use AWS4 signing method to sign the http request.

For more blogs, Visit https://infinity-creator.blogspot.com/

Why AWS4 signing?

Signing the request with AWS4 method is mandatory to access the any AWS resources which is internally handled by AWS CLI, AWS SDK etc.

When AWS API Gateway is secured with AWS_IAM authorization type then AWS will take care of the authentication and authorization of API call based on IAM permission. So to authenticate and authorize the request, the request must have Authorization header with AWS signature along with X-Amz-Date and X-Amz-Security-Token headers.

If you are developing in Python use this python code to generate these headers.

If you are developing in Dotnet use Aws4RequestSigner nuget package and source code for the same.

If you are developing in nodejs use aws4 npm package.

Happy coding!!!

--

--

Ganesh
Ganesh

Written by Ganesh

AWS Certified | .NET | C# |NodeJs. Visit https://infinity-creator.blogspot.com/ for more posts on AWS.

Responses (1)