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:
| Field | Example |
|---|---|
| Access key ID | {{awsAccessKeyId}} |
| Secret access key | {{awsSecretAccessKey}} |
| Session token | {{awsSessionToken}} (only for temporary credentials) |
| Region | eu-central-1 |
| Service | execute-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 calling | Service |
|---|---|
| API Gateway (REST or HTTP API) with IAM auth | execute-api |
Lambda function URL with AWS_IAM | lambda |
| OpenSearch Service domain | es |
| S3 | s3 |
| Other AWS APIs | the 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:
aws sso login --profile staging
aws configure export-credentials --profile staging --format envCopy 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, everyx-amz-*header andcontent-type, and leaves the rest out so a proxy changingUser-Agentdoesn'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
403there 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:
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.