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:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-ts-ai-app-infrastructurecd pulumi-examples/aws-ts-ai-app-infrastructureA 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:InvokeModelon 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#
- Install Pulumi
- Configure your AWS credentials
- Install Node.js
- 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#
-
Create a new stack:
Terminal window pulumi stack init dev -
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:0pulumi config set modelId anthropic.claude-haiku-4-5-20251001-v1:0 -
Install dependencies:
Terminal window npm install -
Run
pulumi upto preview and deploy:Terminal window pulumi up -
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:
pulumi destroypulumi stack rmSummary#
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
Deploy OpenClaw on AWS or Hetzner Securely with Pulumi and Tailscale
