[API key is required] Error from OZ Defender Actions

I am running the following Defender Action with a Relayer.

I'm getting the following error:

Error
API key is required
Logs
ACTION RUN
2024-10-22T22:46:09.649Z	INFO	event
2024-10-22T22:46:09.649Z	INFO	{
  autotaskId: '266cec3f-4d74-449a-a240-05636ad6580e',
  autotaskName: 'Process Report',
  autotaskRunId: '5dcf8bc5-3fcf-486f-a61b-bf70360c1c7c',
  credentials: '{"AccessKeyId":"ASIAZWAXLRYVTDE6BAZ7","SecretAccessKey":"jQbIi8nF7fUfy07Omard4zLIIpuvAlR4pATS+cK6","SessionToken":"FwoGZXIvYXdzEFgaDGXjw7u+qfIO/utOTSKXA8iNSpA7iUMdncFQ84C509Cm9Kapqv8p+OtI5HzCBsg9RZIrNiqkdw+a++KNOFTGil/QIJRVLnDsKXnIf82abiwmkA3XxFJewhBT40fVtnlD3JOG8gGQNxJ8J+RqKneQTwsug9aXRiuZEbrBHS1ybT4ea23jH2v3CxNLbwRQ7VfdYv37uUTCyPjZ2zqoNIYNUxUKkZ+34Mjn1s/yDGO7YnDEcQRkRw0ttty5f/9oM3McpaGfGrFC8PqLrcUNmqikuPwyyM/hlug6zLjFyLQONGYx+Mqp3TtktCSq6Hzx76rB5gi5T31/5CplLF/M6BPSI45XGvMNOvodSwK7+LpxJpliUn9Vp9kp16LpQzVlkoZFfVjEY+SuLtgM3pfrP70s6hnanIH+zy7juM48+mi8iOwik0jhpMpPt0Ee7iY4uhYgzZ4ybYTQb/9pF1UrUTXMPVW3xH7Y8N1wDRwYaYYjC6HTNBIWmFzGC2vWCzJU4rTVs8/BGZvNPYeAAsnyJQSwTAIk+enAPF987Alw6qQG9GdoSI0bn2TjKK7W4LgGMi1jU+OCRsOpbGVa9aEk+PkdSW6SqY34ork1AtnV6ipg3348uwZjnKxxISb7Tx4=","Expiration":"2024-10-22T23:01:06.000Z"}',
  kvstoreARN: 'arn:aws:lambda:us-west-2:665768922667:function:defender-prod-proxy-kvstore:baaae573-a208-4379-96ee-729193fa0892_STORE',
  previousRun: {
    trigger: 'manual',
    status: 'error',
    createdAt: '2024-10-22T22:36:42.463Z',
    autotaskId: '266cec3f-4d74-449a-a240-05636ad6580e',
    message: 'API key is required',
    statusCreatedAt: 'error|2024-10-22T22:36:42.463Z',
    autotaskRunId: '4c48d740-dbf8-49a2-9ec7-3d3117903ec6'
  },
  relayerARN: 'arn:aws:lambda:us-west-2:665768922667:function:defender-prod-proxy-relayer:baaae573-a208-4379-96ee-729193fa0892_2ef80a11-70ad-4944-ba22-bcc25321ea4f',
  tenantId: 'baaae573-a208-4379-96ee-729193fa0892',
  trigger: 'manual',
  actionId: '266cec3f-4d74-449a-a240-05636ad6580e',
  actionName: 'Process Report',
  actionRunId: '5dcf8bc5-3fcf-486f-a61b-bf70360c1c7c',
  secrets: {}
}
END RequestId: b78cd9a1-6b93-4625-93f7-d77f51e3a285
ACTION COMPLETE
2024-10-22T22:46:09.669Z	ERROR	Invoke Error

:computer: Environment

This action uses dependency version v2024-10-02 and runs on Relayers on the Sepolia Network that have an API Key created on. The Relayer wallet has 0.5 sepolia Eth deposited.

:memo:Details

Keeping getting the post-action error for api key even though I added an api key to the Relayer.

:1234: Code to reproduce

const { Defender } = require('@openzeppelin/defender-sdk');
const { ethers } = require('ethers');


exports.handler = async function(event) {
  console.log("event");
  console.log(event);

  // Create a Defender relay provider and signer using the secrets
  const provider = new Defender(event);
  const signer = await provider.relay();
  const abi = [
    'function process_report(address) external'
  ];
  const vaultAddress = '0x336DcFd08E31e728481a065e57708e176BcC6227';
  const vaultContract = new ethers.Contract(vaultAddress, abi, signer);
  const tx = await vaultContract.process_report("0x429d239102D67AC9Cb00460ab6B85Bc62b7306E6");
  const txRes = await signer.sendTransaction(tx);

  console.log(txRes);
  return txRes.hash;
}
1 Like

Hi Andrew! The code to instantiate the relayer signer is wrong:

Here an example

You must access to relaySigner subpackage, and then get the provider and signer:

const client = new Defender({
  relayerApiKey: process.env.RELAYER_API_KEY,
  relayerApiSecret: process.env.RELAYER_API_SECRET,
});
const provider = client.relaySigner.getProvider();
const signer = await client.relaySigner.getSigner(provider);
1 Like