I have a lambda function that is trying to store (and retrieve) data from a blob, but I am having real trouble with the blob API.
Here is my code:
const { getDeployStore } = require('@netlify/blobs');
exports.handler = async function(event, context) {
// fetches data from a third-party API and sets it as 'availableTimes' - the idea is to reduce the number of calls to this API
const store = getDeployStore({ siteID: SITE_ID, token: TOKEN, deployID: DEPLOY_ID });
await store.setJSON(CACHE_KEY, availableTimes);
console.log('Available times cached in Netlify Blobs:', availableTimes);
return {
statusCode: 200,
body: JSON.stringify({ message: 'Cache updated successfully' }),
};
} catch (error) {
console.error('Error in update-cache function:', error);
return {
statusCode: 500,
body: JSON.stringify({ error: error.message }),
};
}
};
where:
SITE_ID = ‘lovely-maamoul-1f6c06’;
TOKEN = process.env.NETLIFY_AUTH_TOKEN; // this is generated from my Netlify account as a personal access token and then stored in an .env file (i am currently only testing locally)
const DEPLOY_ID = process.env.DEPLOY_ID || ‘mock-deploy-id’; // mocked up the deploy ID as testing locally
CACHE_KEY = ‘available-times’;
I am getting the following error, which is making me think that some of the tokens being passed are incorrect:
Error in update-cache function: BlobsInternalError: Netlify Blobs has generated an internal error (400 status code)
Any ideas?