Generic Agent: AWS ECS Fargate Deployment

Deploy the Generic Agent on AWS using ECS Fargate

📝

Prerequisites

  1. AWS CLI configured, or access to the CloudFormation console.
  2. A VPC with two private subnets and outbound internet access (a NAT gateway, or VPC endpoints for the services the agent uses). The tasks get no public IP. Step 2.1 creates one if you don't have one.
  3. You are an Account Owner in Monte Carlo.
  4. The Session Manager plugin for the AWS CLI, used to run the agent's health and reachability checks. Only needed for Step 2.5.

This guide deploys the Generic Agent on AWS ECS Fargate with CloudFormation. Use it when ECS is your organization's container platform and EKS is not an option.

📘

If you want to review the template or share it with a colleague first, download a copy here (source).

Architecture

The agent runs as an ECS service on Fargate with two tasks by default, in your own VPC. It is egress-only: nothing connects to the agent, so the stack creates no load balancer, no inbound security group rule, and no public endpoint.

The stack creates:

ResourcePurpose
ECS cluster, task definition and serviceRuns the agent tasks
S3 bucketData store for sampling and temporary operation data
Task roleReads the agent's credentials and the data store. Attach data source permissions to this role
Task execution rolePulls the image and writes the log stream
Security group (optional)Outbound only, no inbound. Skipped when you supply your own
CloudWatch log groupThe agent's container output

The agent reads its own Monte Carlo credentials from AWS Secrets Manager using the task role, so no credential is stored in the task definition or in the container environment.

The security group the stack creates allows all outbound traffic and no inbound, because the agent connects to data sources on whatever ports they use — 5439 for Redshift, 1521 for Oracle, 1433 for SQL Server. To restrict egress, supply your own security groups with SecurityGroupIds; they need to reach the Monte Carlo agent service, your object storage and secret store, and each data source you connect.

Steps

1. Register the Agent

  1. In Monte Carlo, navigate to Settings > Deployments and click Add.

  2. Select Generic, enter a name for the agent, and choose an Authentication method:

    • Key/Token (default) — the agent authenticates with a Monte Carlo-generated key pair (mcd_id / mcd_token).
    • OAuth — the agent authenticates using OAuth 2.0 Client Credentials (client_id / client_secret). The agent automatically obtains and refreshes short-lived JWT tokens. See Authentication for more details.

    The authentication method is permanent and cannot be changed after provisioning.

  3. Click Provision.

  4. Copy the credentials — they are displayed only once and cannot be retrieved later.

    • Key/Token: copy the Key ID and Key Secret — these are used as mcd_id and mcd_token in the deployment steps below.
    • OAuth: copy the Client ID and Client Secret — these are used as client_id and client_secret in the deployment steps below.

With Terraform or Claude: the Terraform provider replaces these steps with montecarlo_deployment and montecarlo_generic_collection_agent_oauth_client or montecarlo_generic_collection_agent_token, which return the same credentials; see Deploy a collection agent. With the Agent Toolkit, run /monte-carlo-onboarding and Claude creates the deployment and gives you the command or Terraform that creates the credentials.

2. Deploy the Agent

2.1 Create a VPC (optional)

Skip this if you are deploying into an existing VPC. Otherwise, the basic_vpc.yaml template creates a VPC with two public and two private subnets, a NAT gateway, and an S3 gateway endpoint:

aws cloudformation create-stack \
  --stack-name mcd-agent-vpc \
  --template-url https://mcd-public-resources.s3.amazonaws.com/cloudformation/basic_vpc.yaml

This uses the template's defaults: a 10.0.0.0/16 VPC with four /24 subnets. If that overlaps a network you peer with or connect to over a VPN, pass VpcCIDR and SubnetCIDRs instead. The four subnet CIDRs are ordered public, public, private, private, and each must sit inside the VPC CIDR without overlapping the others.

Wait for it and read the VPC and private subnet ids from the outputs:

aws cloudformation wait stack-create-complete --stack-name mcd-agent-vpc

aws cloudformation describe-stacks --stack-name mcd-agent-vpc \
  --query 'Stacks[0].Outputs[?OutputKey==`VpcId` || starts_with(OutputKey, `PrivateSubnet`)]' \
  --output table

2.2 Connect over AWS PrivateLink (optional)

Skip this to reach Monte Carlo over the internet through the NAT gateway.

To keep that traffic on the AWS network instead, create an interface VPC endpoint to the Agent Service in the agent's VPC, following Agent Service AWS PrivateLink. Monte Carlo allowlists your AWS account, you create the endpoint and a Route 53 private hosted zone that resolves the Agent Service private link hostname to it, and Monte Carlo approves the connection.

Two things specific to this deployment:

  • Give the endpoint its own security group allowing inbound 443 from the agent tasks' security group, whether the one this stack creates or the ones you pass as SecurityGroupIds.
  • Put the endpoint in the same subnets as the tasks, so each task reaches an endpoint ENI in its own availability zone.

Once the connection shows Available, the only change to this stack is BackendServiceUrl: set it to the Private link endpoint from Account Information instead of the public one. The image, task role and security group stay the same. With OAuth, the agent requests its access tokens through the same endpoint, so it needs no internet path to Monte Carlo.

2.3 Store the Agent Credentials

Using the credentials from registration, create a Secrets Manager secret in the same region as the stack. The stack reads the agent's credentials from this secret and requires its ARN. It takes no credential parameter of its own, since a value passed as a parameter stays readable in the stack's parameter list. Choose the tab matching the authentication method you selected.

aws secretsmanager create-secret \
  --name mcd/agent/credentials \
  --secret-string '{"client_id":"<YOUR_CLIENT_ID>","client_secret":"<YOUR_CLIENT_SECRET>"}' \
  --query ARN --output text

Keep the ARN it prints for the next step.

2.4 Deploy the Stack

aws cloudformation create-stack \
  --stack-name mcd-generic-agent \
  --template-url https://mcd-public-resources.s3.amazonaws.com/cloudformation/aws_generic_agent_fargate.yaml \
  --capabilities CAPABILITY_IAM \
  --parameters \
    ParameterKey=BackendServiceUrl,ParameterValue=<YOUR_BACKEND_SERVICE_URL> \
    ParameterKey=AuthMethod,ParameterValue=OAUTH \
    ParameterKey=CredentialsSecretArn,ParameterValue=<YOUR_SECRET_ARN> \
    ParameterKey=VpcId,ParameterValue=<YOUR_VPC_ID> \
    "ParameterKey=SubnetIds,ParameterValue=<SUBNET_1>\,<SUBNET_2>"
📘

Set BackendServiceUrl to the Public endpoint shown in Account Information > Agent Service in the Monte Carlo app, or to the Private link endpoint if you use PrivateLink.

Parameters worth setting:

ParameterDefaultNotes
AuthMethodOAUTHKEY_TOKEN for a Monte Carlo key pair
DesiredCount2Tasks to run. Two or more keeps the agent serving during a deploy
TaskCpu / TaskMemory1024 / 4096Must be a valid Fargate pairing
OpsRunnerThreadCount18Concurrent operations per task
SecurityGroupIds(empty)Your own security groups. Empty means the stack creates one that allows all outbound traffic and no inbound
AdditionalTaskRolePolicyArns(empty)Customer-managed policies to attach to the task role, for integration secrets and data source access
AgentImagemontecarlodata/agent:latest-genericPin a version to control upgrades

Before you deploy a pinned tag, you can verify that the image is signed by Monte Carlo. See Verify an agent image.

2.5 Verify

Wait for the stack, then confirm both tasks are healthy:

aws cloudformation wait stack-create-complete --stack-name mcd-generic-agent

CLUSTER=$(aws cloudformation describe-stacks --stack-name mcd-generic-agent \
  --query "Stacks[0].Outputs[?OutputKey=='ClusterName'].OutputValue" --output text)

aws ecs list-tasks --cluster "$CLUSTER" --query taskArns --output text \
  | xargs aws ecs describe-tasks --cluster "$CLUSTER" --tasks \
  --query 'tasks[].{Task:taskArn,Status:lastStatus,Health:healthStatus}' --output table

Both tasks should report RUNNING and HEALTHY. Keep one of the task ARNs for the next command. Check the log group named in the stack outputs for the startup line and the authentication method in use.

Run the reachability test to confirm the agent can communicate with the Monte Carlo platform. Fargate has no kubectl exec, so use ECS Exec. The template enables it and grants the task role the permissions it needs:

aws ecs execute-command --cluster "$CLUSTER" --task <TASK_ARN> \
  --container mcd-agent --interactive \
  --command "curl -s -X POST localhost:8080/api/v1/test/reachability"

A successful response contains "ok": true.

📘

aws ecs execute-command needs the Session Manager plugin installed locally.

3. Enable the Agent

After verifying the agent is running, click Enable on the agent registration screen.

With the Terraform provider, montecarlo_generic_collection_agent enables the agent instead, once it's running. With Claude, ask it to register the agent and it does this step through the Monte Carlo MCP server.

📘

If you've navigated away from the registration screen, go to Settings > Deployments, select your agent, and click Enable.

Once validations pass, click Enable in the validations dialog to activate the agent.

Outputs

OutputUse
ClusterName / ServiceNameScaling, redeploys and ECS Exec
TaskRoleArn / TaskRoleNameThe role to grant data source and secret access to
StorageBucketNameThe agent's data store
LogGroupNameAgent container output

FAQs

Why is there no load balancer?

The agent is egress-only. It opens connections to Monte Carlo, and nothing connects to it. Its HTTP port serves only the health and reachability endpoints, reached from inside the task with ECS Exec. A load balancer would add an inbound path that the agent does not need.

How do I add credentials for data source integrations?

Store each integration's credentials in its own Secrets Manager secret, then onboard the integration in the Monte Carlo UI or with the CLI. Self-Hosted Credentials covers both, along with the JSON schema each integration type expects in the secret.

Two things are specific to this deployment:

  • The agent reads the secret as its task role, so that is the role to grant secretsmanager:GetSecretValue on. See the FAQ below.
  • File-based credentials do not apply, because Fargate tasks have no secret volume to mount them from. Use AWS Secrets Manager.

With the CLI, the secret goes on the connection itself, and every connection type takes the same --self-hosted-* flags:

montecarlo connections add redshift \
  --name <connection_name> \
  --deployment-id <YOUR_DEPLOYMENT_ID> \
  --self-hosted-aws-secret <YOUR_SECRET_ARN>

How do I give the agent access to my data sources and integration secrets?

The agent acts as its task role, so anything it reaches through IAM is granted on that one role and no access keys are needed. The stack already grants it the data store bucket and the secret holding the agent's own credentials.

What else the role needs depends on the integration:

  • Integration credentials in Secrets Manager. secretsmanager:GetSecretValue on each secret the agent reads.
  • Redshift, Glue and Athena. By default these authenticate as themselves, with a service user for Redshift and a role Monte Carlo assumes for Glue and Athena, so the task role needs nothing. If you connect them with IAM directly on the agent's role instead, attach that integration's permissions here; its own documentation lists them.
  • S3 and other sources reached with IAM. Attach the permissions that source needs.

Add them either way:

  • In this stack: write the policies yourself, then pass their ARNs as AdditionalTaskRolePolicyArns. They must exist before the stack is created.
  • In a separate stack: take TaskRoleName from the outputs and list it in the Roles property of an AWS::IAM::ManagedPolicy. The permissions then have their own lifecycle, which suits teams where a different group owns data source access:
Resources:
  AgentDataAccess:
    Type: AWS::IAM::ManagedPolicy
    Properties:
      Roles:
        - !ImportValue 'mcd-generic-agent:TaskRoleName'
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Action: 'secretsmanager:GetSecretValue'
            Resource: 'arn:aws:secretsmanager:<region>:<account>:secret:mcd/agent/integrations/*'

How do I scale the agent?

Raise DesiredCount to run more tasks, or OpsRunnerThreadCount to run more operations per task. Increase TaskCpu and TaskMemory alongside the thread count.

How do I upgrade the agent?

Update the stack with a new AgentImage. ECS replaces the tasks one at a time, so the agent keeps serving. Remote upgrades from Monte Carlo are not supported for this deployment.

How do I rotate agent credentials?

Generate a new credential in Monte Carlo, update the Secrets Manager secret, and restart the service:

aws ecs update-service --cluster "$CLUSTER" --service <SERVICE_NAME> --force-new-deployment

The agent re-reads the secret within 15 minutes even without a restart. Delete the old credential once the agent is healthy.

How do I monitor the agent?

Use the CloudWatch log group in the stack outputs, and ECS service events. The agent also ships its own logs to Monte Carlo. Container CPU and memory metrics are not collected, because the metrics collector is a Kubernetes DaemonSet with no ECS equivalent. Enable Container Insights on the cluster if you want them in CloudWatch.

Can I use AWS PrivateLink instead of the internet?

Yes, see Step 2.2.

How do I route agent traffic through a forward proxy?

Set HTTP_PROXY and HTTPS_PROXY on the container. The template does not expose them as parameters yet; add them to the task definition's Environment list.

Can I run the agent on ECS with EC2 instead of Fargate?

The template requires Fargate. The same container runs under the EC2 launch type, but you manage the instances, and the template's task definition would need RequiresCompatibilities and the service's launch type changed.



Did this page help you?