@vercel/functions
v1.5.0
Published
Runtime functions to be used with your Vercel Functions
Downloads
465,014
Keywords
Readme
OIDC Support Functions
AWS S3 Example
import * as s3 from '@aws-sdk/client-s3';
import { awsCredentialsProvider } from '@vercel/functions/oidc';
const s3Client = new s3.S3Client({
credentials: awsCredentialsProvider({
roleArn: process.env.AWS_ROLE_ARN,
}),
});
export const GET = () => {
const result = await s3Client.send(
new s3.ListObjectsV2Command({
Bucket: process.env.BUCKET_NAME,
})
);
return Response.json({ objects: result.Contents });
};
Azure CosmosDB Example
import { ClientAssertionCredential } from '@azure/identity';
import { CosmosClient } from '@azure/cosmos';
import { getVercelOidcToken } from '@vercel/functions/oidc';
const credentialsProvider = new ClientAssertionCredential(
process.env.AZURE_TENANT_ID,
process.env.AZURE_CLIENT_ID,
getVercelOidcToken
);
const cosmosClient = new CosmosClient({
endpoint: process.env.COSMOS_DB_ENDPOINT,
aadCredentials: credentialsProvider,
});
export const GET = () => {
const container = cosmosClient
.database(process.env.COSMOS_DB_NAME)
.container(process.env.COSMOS_DB_CONTAINER);
const items = await container.items.query('SELECT * FROM f').fetchAll();
return Response.json({ items: items.resources });
};