View a markdown version of this page

Model Inference - AWS Prescriptive Guidance

Model Inference

An inference workload receives an application request, invokes a model, and returns a result. This page describes that flow for Amazon Bedrock managed model access and Amazon SageMaker AI hosted inference. It also covers the application controls common to both services and to models on compute you operate.

SageMaker AI can host models trained elsewhere. Teams using pre-trained models can follow this page without operating a training environment. Model customization describes the additional controls for workloads that train or adapt a model.

Security considerations

The inference design should address these risks:

  • An application role can invoke an unapproved model or replace a production endpoint.

  • Prompts, responses, or logs expose sensitive information to unauthorized readers.

  • Prompt injection changes model behavior, or generated output reaches a downstream system without validation.

  • An alternate API or network path bypasses required content or access controls.

Infrastructure security

Choose and isolate the hosting environment

The AI inference account contains production model serving, including Bedrock model access and Amazon SageMaker AI production endpoints. Keeping experimentation in a development account separates test permissions and configuration changes from production requests.

Amazon Bedrock: protect managed model access

Amazon Bedrock manages model hosting. The application team configures access to the service and separates production invocation from model administration. For applications running in an Amazon VPC, invoke models through a Bedrock Runtime interface endpoint with private DNS enabled. Allow HTTPS connections from the application security group and restrict the endpoint policy to the intended roles, model resources, and invocation operations. An endpoint policy governs only requests through that endpoint. When private access is required, apply an explicit deny outside the approved endpoint. Follow the endpoint policy and private-path examples, including the AWS service exceptions and permitted and denied tests.

The model service and your application have separate responsibilities. If you operate the application on containers or instances, maintain that compute even though Bedrock manages model hosting.

Amazon SageMaker AI: protect hosted endpoints

SageMaker AI inference includes real-time, serverless, asynchronous, and batch options. The team operating inference governs the model artifact, serving image, execution role, and deployment configuration for the selected option. Deployment needs its own approval because approval of a training run does not grant permission to create or update a production endpoint.

For real-time inference, configure the model's VPC access with private subnets and security groups limited to required resources. Use a SageMaker Runtime interface endpoint for private invocation from the application. These are separate connections: the model's VPC configuration controls access to workload resources; the interface endpoint provides the caller's path to the service.

Enable network isolation for compatible serving containers that do not need outbound calls. SageMaker AI transfers model artifacts separately; the isolated container cannot call Amazon S3 or other VPC resources. If the serving code needs those connections, restrict its network access to the required destinations. Serverless Inference does not provide VPC configuration or network isolation, so choose a different hosting option when those controls are required. Assign an owner for serving code and dependency updates.

Shared application and self-hosted compute controls

For models hosted on Amazon EC2, Amazon Elastic Container Service (Amazon ECS), or Amazon Elastic Kubernetes Service (Amazon EKS), your team owns the serving stack and its maintenance. Amazon Inspector provides applicable compute and image vulnerability scans, and AWS Systems Manager Patch Manager provides patching for managed nodes you operate. These controls address vulnerabilities in the serving software; model responses need the separate evaluations described later on this page.

Protect public application entry points with authentication, usage limits, request validation, and AWS WAF where the frontend resource permits it. Use AWS Shield Advanced for additional distributed denial of service (DDoS) protection where required, selecting eligible frontend resources for protection. Use AWS Network Firewall for egress that requires inspection, and verify that the relevant traffic traverses it.

Filter outbound DNS requests

Use Amazon Route 53 Resolver DNS Firewall to filter DNS queries from application and serving workloads in VPCs. Associate rule groups with each workload VPC. Block known unsafe domains, and use an allow list when you know the workload's required destinations. Enable Resolver query logging and test permitted and blocked lookups before rollout.

DNS Firewall filters queries sent through Route 53 Resolver. Combine it with network egress controls that restrict direct IP connections and alternate DNS services, including external DNS over HTTPS. DNS filtering can limit outbound communication from compromised dependencies; dependency review and artifact verification remain necessary.

Identity and data security

Authorize users and applications to invoke approved models, and limit access to retained content according to its classification.

Amazon Bedrock: authorize approved model invocation

The application uses an IAM role for Amazon Bedrock access to invoke its approved model resources. Limit the role to the operations the application needs, with separate permissions for model customization and guardrail administration. Use the model and inference-profile policy examples to define the permitted resources. For cross-Region inference, a destination Region can process prompts and responses. Review the profile's destinations against data residency requirements and apply the geographic or global profile controls before granting access.

AWS and third-party model providers do not use Amazon Bedrock inputs or outputs to train Amazon Nova, Amazon Titan, or third-party models. Customer-requested model customization uses the training data you supply. Before approving a model, separately review its data retention requirements and abuse detection terms. Disabling application logs or setting store=false might not result in zero retention. Record whether the selected model and endpoint can process each data classification.

Amazon SageMaker AI: separate invocation from deployment

Give the application role only the invocation permissions required for its approved Amazon SageMaker AI endpoint Amazon Resource Names (ARNs). Configure a separate hosting execution role with access to the required model artifacts, images, and other resources. Give the deployment workflow permission to create and update endpoints and pass that execution role; withhold those permissions from the application role. Test that the application can invoke its approved endpoint but cannot update it or invoke unrelated endpoints.

Shared user identity and retained data controls

Select user sign-in using the AI application access guidance. Authenticate the user and authorize their inference request before the backend uses its AWS role to call the model. Apply the shared identity and data controls to invocation roles, credentials, and retained content, then test permitted and rejected requests.

Classify prompts, responses, conversation history, and caches by sensitivity and applicable legal requirements before retaining them. Have the data owner approve permitted uses, readers, and retention for each stored copy. Enforce those decisions with access policies and expiry settings; test unauthorized reads and removal when retention ends.

For supported text, configure sensitive information filters to block or mask selected personally identifiable information (PII) and patterns, then test the deployed guardrail version with representative sensitive and non-sensitive examples. Use Amazon Macie to discover sensitive data already stored in supported Amazon S3 objects. Neither detection nor masking grants permission to retain a record.

AI application security

Validate model inputs and outputs to reduce prompt injection and unsafe handling before responses reach users or downstream systems.

Include custom request handlers, model-serving code, and output-processing code in the application code review workflow. Test that requests remain bound to the authenticated user's session. For output handling, keep HTML autoescaping enabled when displaying responses and pass generated data values as SQL parameters. Apply the model input, output, and behavior checks below alongside that review.

Use Amazon Bedrock Prompt management or manage prompts in the application's version-control and release process. Separate permissions to use and change prompts. Review and test changes before release, and record the prompt version used for each deployment.

Amazon Bedrock: configure and test inference guardrails

Use Amazon Bedrock Guardrails to apply content policies to model inputs and outputs. Configure prompt attack, harmful content, denied topic, and sensitive information filters for the application's risks. Use the organization policy for the centrally enforced baseline and add reviewed application guardrails where required. IAM policies using bedrock:GuardrailIdentifier can reject requests that omit or change a required application guardrail; they do not attach it. Follow the Bedrock integration pattern for enforcement and API coverage.

Applications using external model providers can call ApplyGuardrail to inspect content and act on the result. Verify that alternate callers cannot bypass required checks. Test prompts, responses, streaming, and alternate APIs. Use Amazon Bedrock Evaluations with representative and adversarial prompts before release and after model changes.

Check grounding and relevance

For summarization or question answering from reference material, configure contextual grounding checks. Supply the reference source, user query, and response, and test grounding and relevance thresholds with representative data. These checks assess the response against the supplied source; they do not establish that the source itself is correct. Streaming relevance checks can identify an irrelevant response only after it has been streamed. When validation must precede disclosure, buffer the complete response, evaluate it with ApplyGuardrail within its input limits, and handle the findings before returning it.

Validate policy-bound responses

Amazon Bedrock Automated Reasoning checks assess responses against a policy you define. They return findings in detect mode, so the application team must review the policy and decide how to handle those findings. The checks require complete responses and cannot process streaming API requests. Complete required validation before returning a response or acting on it.

Centrally enforced guardrails don't support Automated Reasoning policies. Use a supported application-request guardrail or a separate ApplyGuardrail call for these checks. Apply the authorization controls and prompt-injection defenses separately.

Amazon SageMaker AI: integrate input and output checks

A SageMaker inference application can call the independent ApplyGuardrail API to assess text before sending it to the endpoint and before returning generated text to the user. The application implements this integration: it makes the guardrail calls and acts on their results. Amazon Bedrock Guardrails doesn't automatically apply to a SageMaker endpoint.

For this integration, check the input, invoke the endpoint only when the input is allowed, check the response, and return only the permitted result. Define a safe response when checks fail or are unavailable. Verify that streaming and alternate endpoint callers cannot bypass required checks. Evaluate model behavior and serving changes in your SageMaker release workflow. Content checks complement the endpoint's IAM and network controls.

Shared output handling and investigation evidence

Your application can display generated output to a user or pass it to another component. Validate and encode it for that destination before use. Content filtering addresses content policies; factual accuracy and permission to run an action require separate checks. Set limits on prompt size and request rate, and configure input and output token limits for the selected model. Verify that input and output checks cover the content types the application accepts. Provide a defined response for rejected requests and failed dependencies.

Enable Amazon Bedrock model invocation logging in each account and Region where investigation requires request and response records. Amazon Bedrock disables this logging by default. Select the permitted content types and an Amazon CloudWatch Logs or Amazon S3 destination in the same account and Region, then apply access and retention controls. Use Amazon S3 for large or binary content that you cannot retain inline in CloudWatch Logs.

Applications sharing an account and Region share this logging configuration. Use separate accounts when log-reader access, retention, ownership, or data classification requires a separate boundary. Shared logging alone does not require an account per application; assess the account separation tradeoffs with the content owners.

Invocation logging covers supported Bedrock Runtime calls, including the OpenAI-compatible Responses and Chat Completions APIs on that endpoint. Review logging coverage when changing endpoints or APIs. For SageMaker AI, collect endpoint logs and decide whether the investigation requires captured inputs and outputs before enabling SageMaker AI Data Capture.

Correlate these records with application request IDs and Amazon CloudWatch metrics. Set alarms for invocation errors, throttling, and unexpected usage. Configure AWS CloudTrail event coverage for the APIs in use. Enable data events for AWS::Bedrock::Guardrail to record direct ApplyGuardrail calls and evaluations during model invocation, including request-level and organization-enforced guardrails. When multiple guardrails apply, the event does not identify which guardrail produced each assessment. CloudTrail audit records do not replace the content logging decision.

Apply the shared threat detection and configuration checks. Verify that findings reach an assigned response owner and identify the model, endpoint, or invocation path affected.

Design considerations

The foundational controls and shared application controls address different parts of the request flow. Logging decisions need to balance investigation requirements with restrictions on retained prompt and response content. Add data and knowledge base controls when the application retrieves information, and agentic controls when it selects tools or takes actions.