You can use the aws-sdk to generate a signed request to API Gateway if authorizer is set as AWS_IAM. First get some temporary credentials, then create a signed request.
Get Credentials (example with javascript sdk ) :
var AWS = require('aws-sdk')
var cognitoidentity = new AWS.CognitoIdentity();
var makeSignedRequest = async function () {
var params = {
IdentityId: 'STRING_VALUE', /* required */
CustomRoleArn: 'STRING_VALUE',
Logins: {
'<IdentityProviderName>': 'STRING_VALUE',
/* '<IdentityProviderName>': ... */
}
};
var credsForIdentity = await cognitoidentity.getCredentialsForIdentity(params).promise()
var httpRequest = new AWS.HttpRequest("https://<API_GATE_WAY_ENDPOINT", "<region>");
httpRequest.headers.host = "<API_GATE_WAY_ENDPOINT>"; // Do not specify http or https!!
AWS.config.credentials = {
accessKeyId: creds.Credentials.AccessKeyId,
secretAccessKey: creds.Credentials.SecretKey,
sessionToken: creds.Credentials.SessionToken
}
httpRequest.method = "POST";
httpRequest.body = JSON.stringify(data)
var v4signer = new AWS.Signers.V4(httpRequest, "execute-api");
v4signer.addAuthorization(AWS.config.credentials, AWS.util.date.getDate());
const rawResponse = await fetch(httpRequest.endpoint.href , {
method: httpRequest.method,
headers: httpRequest.headers,
body: httpRequest.body
});
}
This example is not perfect but it is a good starting point on signed request in AWS.
Of course, don't forget to give proper permissions to your authenticated identities so that they can invoke the API.