I have this simple form executed into React page:
import React, {useState} from 'react';
import { Link } from 'react-router-dom';
import {LambdaClient, InvokeCommand, LogType} from "@aws-sdk/client-lambda"; // ES Modules import
const { fromTemporaryCredentials } = require("@aws-sdk/credential-providers");
const FooterOne = ({ footerLight, style, footerGradient }) => {
const handleSubmit = async (event) => {
event.preventDefault();
const credentials = await fromTemporaryCredentials({
params: {
RoleArn: "arn:aws:lambda:us-east-1:123456789:function:email-submit",
},
clientConfig: {
region: 'us-west-2',
},
})();
try {
const client = new LambdaClient({
region: 'us-west-2',
credentials,
});
const command = new InvokeCommand({
FunctionName: "email-submit",
Payload: JSON.stringify("payload"),
LogType: LogType.Tail,
});
const { Payload, LogResult } = await client.send(command);
const result = Buffer.from(Payload).toString();
const logs = Buffer.from(LogResult, "base64").toString();
return { logs, result };
} catch (error) {
console.error('Error invoking function:', error);
// Handle errors as needed
}
};
return (
<>
<form onSubmit={handleSubmit}>
<input
type='text'
placeholder='Enter your email'
name='email'
required=''
autoComplete='off'
/>
<input
type='submit'
value='Subscribe'
data-wait='Please wait...'
/>
</form>
</>
);
};
export default FooterOne;
Lambda code into AWS Lambda:
export const handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
But I get error:
Uncaught (in promise) Error: Credential is missing
at SignatureV4.credentialProvider (runtimeConfig.browser.js:22:1)
at SignatureV4.signRequest (SignatureV4.js:103:1)
at SignatureV4.sign (SignatureV4.js:58:1)
at awsAuthMiddleware.js:24:1
at async retryMiddleware.js:27:1
at async loggerMiddleware.js:3:1
at async fromTemporaryCredentials.js:20:1
at async handleSubmit (FooterOne.js:12:1)
Do you know how I can fix this issue?

