Deploy with Terraform
This guide provides a complete Terraform configuration for deploying Deepgram on Amazon SageMaker. The configuration creates an IAM execution role, a SageMaker Model from your AWS Marketplace subscription, an Endpoint Configuration, and a live Endpoint. An optional module adds auto-scaling. The same configuration can deploy either a real-time endpoint (the default) or an asynchronous endpoint that processes large pre-recorded files from S3 and can scale to zero — set enable_async_inference = true.
Before running Terraform, you must subscribe to a Deepgram product on the AWS Marketplace and note the Model Package ARN. Subscribe via the AWS Management Console or the AWS Marketplace API, then see Find the Model Package ARN.
Prerequisites
- Terraform 1.5 or later
- AWS credentials configured for the target account (via environment variables, shared credentials file, or an IAM role)
- An active AWS Marketplace subscription to a Deepgram SageMaker product. You can subscribe through the console or, if you provision infrastructure as code, via the Marketplace API.
- The Model Package ARN for the subscribed product. See Find the Model Package ARN for how to locate it in the AWS Marketplace Manage subscriptions console.
Subscribe to a Deepgram product via the Marketplace API
If you provision infrastructure as code, you can subscribe to a Deepgram SageMaker product entirely through the AWS Marketplace API instead of the console. This section is an alternative to Subscribe to Deepgram Products via AWS Marketplace Console — use whichever method fits your workflow, then continue to Find the Model Package ARN.
The steps below use the AWS CLI, but AWS also publishes SDKs for many languages — including Python (Boto3), Node.js, Java, Go, and .NET — that expose the same Marketplace Discovery and Agreement Service APIs. Use whichever SDK fits your stack to build your own subscription automations and scripts.
Subscribing creates a billing agreement on your AWS account. You are not charged until you deploy a SageMaker Endpoint and send it traffic — the usage-based pricing term has no upfront cost — but AcceptAgreementRequest (the last step below) is not a dry run. It creates a real, active agreement.
Permissions
The AWSMarketplaceManageSubscriptions policy referenced in Prerequisites covers product discovery (SearchListings, GetOffer, GetOfferTerms, ListPurchaseOptions, and similar) but does not include the AWS Marketplace Agreement Service actions this flow also needs: CreateAgreementRequest, AcceptAgreementRequest, DescribeAgreement, SearchAgreements, and GetAgreementTerms. Either attach AWSMarketplaceFullAccess or add those five actions to a custom policy alongside AWSMarketplaceManageSubscriptions.
Find the product ID
List Deepgram’s SageMaker-deployable products, filtered by fulfillment type and seller:
6efa21f9-9a33-4cae-ba44-756436fa71dd is Deepgram’s AWS Marketplace seller profile ID. Note the productId for the listing you want to deploy (eg. prod-tnv5pm6nlcm44 for Nova-3 Monolingual Streaming).
Calls the SearchListings action of the AWS Marketplace Discovery API.
Find the standard offer for that product
This can return more than one purchase option — for example, a private offer your account manager extended to you, alongside the standard public offer. The standard public offer has no PRIVATE_PRICING badge and no custom purchaseOptionName (AWS labels it "Offer created on <timestamp>"). Use a private offer’s ID instead if your account has negotiated pricing.
Calls the ListPurchaseOptions action of the AWS Marketplace Discovery API.
Get the offer's proposal ID and pricing model
Note the agreementProposalId and pricingModel.pricingModelType from the response — you need both for the next steps.
Calls the GetOffer action of the AWS Marketplace Discovery API.
Get the offer's terms
The response lists one or more terms, each with an id. For a USAGE-priced Deepgram SageMaker product, expect LegalTerm, SupportTerm, and UsageBasedPricingTerm — collect all three id values. Deepgram’s public SageMaker listings also include a FreeTrialPricingTerm (14 days); collect its id too if you want to claim the trial. See Required terms by pricing model if the offer uses a different pricing model.
Calls the GetOfferTerms action of the AWS Marketplace Discovery API.
Generate a quote
Returns an agreementRequestId and a chargeSummary. For usage-based pricing, newAgreementValue is "0.00" — you’re only quoted for the mandatory terms, not future usage.
Calls the CreateAgreementRequest action of the AWS Marketplace Agreement Service API.
FreeTrialPricingTerm can be accepted only once per product. If your account has already used the trial for this product, omit that term’s id from requestedTerms — including it again returns a ValidationException. If your account already has an active agreement for this product at all, the whole call fails with ValidationException / UNSUPPORTED_ACTION (“This action is not supported when an active agreement exists on the same resourceId”). Check first with the SearchAgreements action: aws marketplace-agreement search-agreements --region us-east-1 --catalog AWSMarketplace --filters '[{"name":"PartyType","values":["Acceptor"]},{"name":"AgreementType","values":["PurchaseAgreement"]},{"name":"ResourceIdentifier","values":["<productId>"]}]' — if an agreement with "status": "ACTIVE" already exists, you’re already subscribed; skip to Find the Model Package ARN.
Accept the quote to subscribe
Returns the new agreementId. This is the subscribe action — it’s equivalent to clicking Subscribe in the console.
Calls the AcceptAgreementRequest action of the AWS Marketplace Agreement Service API.
Confirm the subscription is active
status moves from ACTIVE immediately, but the underlying entitlement can take a few minutes to provision — the same delay you’d see waiting on the console’s subscription page. Poll aws marketplace-agreement get-agreement-entitlements --region us-east-1 --agreement-id <agreementId> until it clears PENDING/PROVISIONING_IN_PROGRESS before continuing to Find the Model Package ARN.
Calls the DescribeAgreement and GetAgreementEntitlements actions of the AWS Marketplace Agreement Service API.
Find the Model Package ARN
The Terraform configuration references the Model Package ARN for the product version and AWS Region you plan to deploy. The AWS Marketplace surfaces the ARN through the CLI configuration view.
In the AWS Management Console, navigate to the AWS Marketplace Manage subscriptions console
On the Active subscriptions tab, find the subscription for the Deepgram product you want to deploy (eg. Deepgram Voice AI- Nova-3 Monolingual Speech-to-Text (STT) Streaming)
Project layout
Variables
Create variables.tf with the input variables the configuration needs. The only required value is the Model Package ARN from your Marketplace subscription.
In async mode,
autoscaling_target_valueis interpreted as the targetApproximateBacklogSizePerInstance(queued requests per instance), andautoscaling_min_capacitymay be set to0to enable scale-to-zero. In real-time mode it remains concurrent-requests-per-instance with a minimum of 1.
Main configuration
Create main.tf with the provider, IAM role, and SageMaker resources. The configuration uses the Model Package ARN from your AWS Marketplace subscription to create the model without referencing a container image directly.
Outputs
Create outputs.tf to surface the endpoint details after terraform apply completes.
Example variable values
Create a terraform.tfvars file with your specific values. Replace the model_package_arn with the ARN from your AWS Marketplace subscription.
Do not commit terraform.tfvars to version control if it contains sensitive values. Add it to .gitignore or use environment variables instead.
Deploy
Preview the resources Terraform will create
Verify the plan shows the expected resources: an IAM role, a SageMaker Model, an Endpoint Configuration, and an Endpoint.
Validate the endpoint
After the endpoint reaches InService, run a test inference to confirm it returns results. See Validate a Deepgram SageMaker Endpoint for the full testing guide using the dg-sagemaker test clients.
Customize the deployment
Instance types
Choose an instance type based on the Deepgram product you are deploying. GPU-accelerated instances are required.
For a full list of compatible instances, see the Deployment Environments hardware specifications.
Environment variable overrides
Pass Deepgram configuration overrides through the deepgram_engine_env and deepgram_api_env variables. Each map key becomes the suffix (for example, "01", "02"), and the value is the TOML expression. See Configure Amazon SageMaker Deployments for the full reference.
VPC configuration
To deploy the endpoint inside a VPC, add a vpc_config block to the aws_sagemaker_model resource:
Asynchronous endpoints
By default this configuration deploys a real-time endpoint for streaming and synchronous transcription. To instead deploy an asynchronous endpoint — for large pre-recorded files (up to 1 GB), queued processing, and scale-to-zero — set enable_async_inference = true and provide an async_s3_output_path.
Asynchronous inference is a distinct endpoint mode: an async endpoint accepts only asynchronous invocations (InvokeEndpointAsync with S3 input/output) and cannot serve streaming or synchronous requests. Switching enable_async_inference replaces the endpoint configuration and endpoint.
When async is enabled, the configuration also:
- grants the execution role
s3:GetObject,s3:PutObject, ands3:ListBucketon the output and failure buckets; - switches the autoscaling target metric to
ApproximateBacklogSizePerInstanceand allowsautoscaling_min_capacity = 0for scale-to-zero; - adds a scale-from-zero policy so the endpoint wakes on the first queued request instead of waiting for the backlog to exceed the target value.
For invocation details, see Deploy Deepgram on Amazon SageMaker. For autoscaling details, see Auto-Scaling Asynchronous Endpoints.
Tear down
To delete all resources created by this configuration:
This removes the SageMaker Endpoint, Endpoint Configuration, Model, auto-scaling resources (if enabled), and the IAM execution role. You are no longer billed for SageMaker compute after the endpoint is deleted. Your AWS Marketplace subscription remains active.