Skip to main content

Serverless AI Inference Endpoint with Amazon Bedrock

A serverless AI inference endpoint on AWS - a Lambda Function URL that invokes an Amazon Bedrock foundation model, scoped to least privilege.

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-ts-ai-app-infrastructure
cd pulumi-examples/aws-ts-ai-app-infrastructure

A minimal, production-shaped starting point for a generative-AI feature: an HTTP endpoint that takes a prompt, calls an Amazon Bedrock foundation model, and returns the generated text.

It provisions:

  • A Lambda function that invokes a Bedrock model, with a public Function URL so you can call it over HTTPS.
  • An IAM role scoped to least privilege - the function may call bedrock:InvokeModel on the configured model and nothing else.
  • A CloudWatch log group with a retention policy for the function’s logs.

The function code lives in lambda/ and uses the AWS SDK for JavaScript’s Bedrock Runtime client (bundled with the Lambda Node.js 20 runtime).

Prerequisites#

  1. Install Pulumi
  2. Configure your AWS credentials
  3. Install Node.js
  4. Enable access to the Bedrock model you want to use in the Bedrock console (Model access), in the same region you deploy to.

Deploying and running the program#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Set the AWS region (and optionally the model):

    Terminal window
    pulumi config set aws:region us-west-2
    # Optional - defaults to anthropic.claude-haiku-4-5-20251001-v1:0
    pulumi config set modelId anthropic.claude-haiku-4-5-20251001-v1:0
  3. Install dependencies:

    Terminal window
    npm install
  4. Run pulumi up to preview and deploy:

    Terminal window
    pulumi up
  5. Call the endpoint with a prompt:

    Terminal window
    curl -X POST "$(pulumi stack output endpointUrl)" \
    -H "content-type: application/json" \
    -d '{"prompt":"Write one sentence about infrastructure as code."}'
    {"text":"Infrastructure as code lets you define and manage cloud resources with the same version control, review, and automation practices you use for application code."}

Clean up#

To tear down the resources, run:

Terminal window
pulumi destroy
pulumi stack rm

Summary#

In this example you deployed a serverless inference endpoint on AWS: a Lambda Function URL that invokes an Amazon Bedrock foundation model with a least-privilege IAM policy. Point the modelId config at any Bedrock model you have access to, and swap the handler in lambda/ to shape prompts and responses for your own application.

Related

The infrastructure as code platform for any cloud.