When trying to use Predictions.identify({}) from my Lambda function, I get the following error:
ERROR Invoke Error {"errorType":"NoCredentials","errorMessage":"Credentials should not be empty.","name":"NoCredentials","stack":["NoCredentials: Credentials should not be empty.","..."]}
How do I define the credentials?
This is my function.
import { Amplify } from 'aws-amplify'
import { generateClient } from 'aws-amplify/data';
import { Schema } from '../data/resource';
import { env } from '$amplify/env/processSupplierContractsWithDataAccess-handler';
import { Predictions } from '@aws-amplify/predictions';Amplify.configure(
{
API: {
GraphQL: {
endpoint: env.AMPLIFY_DATA_GRAPHQL_ENDPOINT,
region: env.AWS_REGION,
defaultAuthMode: 'identityPool',
}
},
},
{
Auth: {
credentialsProvider: {
getCredentialsAndIdentityId: async () => ({
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
sessionToken: env.AWS_SESSION_TOKEN,
},
}),
clearCredentialsAndIdentityId: () => {
/* noop */
},
},
},
}
);const dataClient = generateClient<Schema>();
export const handler: Schema["processDocumentRecord"]["functionHandler"] = async (event) => {
const { document } = event.arguments; const documentText = await Predictions.identify({ text: { source: { key: document!, }, format: "ALL" }, }) console.log(documentText) return "success";};