Call IAM-protected API Gateway, Lambda URLs and AWS APIs with SigV4

An API Gateway route with IAM authorization, a Lambda function URL with AWS_IAM auth, OpenSearch, or any AWS API called directly: none of them take a bearer token. Every request has to be signed with AWS Signature Version 4, a hash of the method, path, query, chosen headers, body and time, made with your secret key. Doing that by hand is miserable. An API client should do it on every send.

Set it up

On the request, or once on the collection or folder so every request inherits it, open Auth and choose AWS signature:

FieldExample
Access key ID{{awsAccessKeyId}}
Secret access key{{awsSecretAccessKey}}
Session token{{awsSessionToken}} (only for temporary credentials)
Regioneu-central-1
Serviceexecute-api

Requestarium adds X-Amz-Date, Authorization and, with a session token, X-Amz-Security-Token at send time. Fields can use {{variables}}; if one is still unresolved, the request isn't signed rather than signed with a placeholder.

Which service name

What you're callingService
API Gateway (REST or HTTP API) with IAM authexecute-api
Lambda function URL with AWS_IAMlambda
OpenSearch Service domaines
S3s3
Other AWS APIsthe service's signing name, such as sqs or dynamodb

The region is the region of the endpoint you call, not where you are.

Use temporary credentials

Long-lived access keys in an API client are the kind of secret that leaks. If you sign in with IAM Identity Center (SSO), export short-lived credentials instead:

Terminal
aws sso login --profile staging
aws configure export-credentials --profile staging --format env

Copy the three values into secret variables of your environment (awsAccessKeyId, awsSecretAccessKey, awsSessionToken). Secret variables are encrypted at rest and masked in reports. When they expire, AWS answers ExpiredTokenException; export again.

Why signatures stop matching

SignatureDoesNotMatch or The request signature we calculated does not match almost always means the request changed after it was signed, or the scope is wrong:

  • Wrong region or service. The most common cause. Check both against the endpoint's hostname.
  • Clock skew. Signatures are valid for a few minutes. A machine whose clock is off by more than that gets Signature expired.
  • A proxy rewrote something. Requestarium signs host, every x-amz-* header and content-type, and leaves the rest out so a proxy changing User-Agent doesn't break it. A proxy that changes the path, query or body will still break it.
  • Custom domain. Calling API Gateway through your own domain works, but IAM policies and resource ARNs still refer to the API ID. A 403 there is authorization, not signing.

A 403 with is not authorized to perform: execute-api:Invoke means the signature was fine and the IAM policy doesn't allow this identity. Fix the policy, not the request.

Testing it

Signed requests are ordinary requests for tests and the CLI:

JavaScript
pm.test('IAM caller reached the API', () => {
  pm.response.to.have.status(200);
});

requestarium run-collection signs each request the same way, from the machine that runs it.