JSPM

  • Created
  • Published
  • Downloads 1618956
  • Score
    100M100P100Q222435F
  • License Apache-2.0

Runtime functions to be used with your Vercel Functions

Package Exports

  • @vercel/functions
  • @vercel/functions/oidc

Readme

Vercel

Develop. Preview. Ship.

Join the community on GitHub Discussions

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 });
};