Connecting ECS to MetalBear Cloud
Connect an Amazon ECS task to the MetalBear Cloud sessions-manager: store the API key in AWS Secrets Manager, allow outbound HTTPS, and add the connection variables to the task.
This guide connects an ECS task that runs the mirrord remote bootstrap to the MetalBear Cloud sessions-manager. The task authenticates with your MetalBear API key, which ECS injects from AWS Secrets Manager. No Kubernetes cluster, mirrord Operator or IAM permissions on the task role are needed. At a glance, the setup is:
Store the API key in AWS Secrets Manager, and let the task's execution role read it (Store the API key).
Allow outbound HTTPS from the tasks to MetalBear (Allow outbound HTTPS).
Add the connection variables to the task and deploy it (Add the connection variables).
Verify that the task registers and a developer session works.
Prerequisites
The ECS task definition set up with the remote bootstrap, up to Connect to your deployment mode.
An API key,
<API_KEY>.An IAM execution role on the ECS service (
executionRoleArnin the task definition). This is not the task role.The AWS CLI, with permission to manage Secrets Manager secrets, IAM role policies and the ECS task definition.
Throughout this guide, replace:
<REGION>
The AWS region the ECS service runs in
<EXECUTION_ROLE_NAME>
The name of the ECS service's execution role
<EXECUTION_ROLE_ARN>
The ARN of that execution role
<SECRET_ARN>
The ARN of the secret created in Store the API key
Store the API key
Create a secret holding the API key as plain text:
The command prints the secret's ARN, <SECRET_ARN>. One secret serves every ECS service in the region.
ECS reads the secret with the task's execution role when the task starts, and passes it to the container as an environment variable. Allow the execution role to read it:
If the secret is encrypted with a customer-managed KMS key rather than the default aws/secretsmanager key, also allow kms:Decrypt on that key.
Allow outbound HTTPS
The tasks only make outbound connections, to the hosts in Network access. Check that:
The tasks' security group allows outbound TCP 443 to them.
The tasks' subnets route to the internet, through a NAT gateway for private subnets, or have a public IP for public ones.
Any firewall or egress proxy on the path allows
app.metalbear.comandsm-aws-use1.app.metalbear.com(or*.app.metalbear.com, see Network access), doesn't buffer responses, and has an idle timeout of at least 300 seconds.
Add the connection variables
Add the API key to the application container's secrets, next to the environment variables from Amazon ECS:
MIRRORD_SESSIONS_MANAGER_API_KEY
Injected by ECS from <SECRET_ARN>. Don't put the key in environment or in an environment file, where it's visible to anyone who can describe the task definition.
Register the new task definition revision and update the service to use it. Tasks read the secret when they start, so after rotating the key, update the secret and redeploy the services.
Verify
ECS task registered: after the new task starts, the application container's logs show no sessions-manager or API key errors. With
MIRRORD_AGENT_RUST_LOG=infoin the container'senvironment, they also showRegistering with the MetalBear Cloud sessions-manager.Developer session: with the developer setup and the
mirrord.jsonfrom Using mirrord with a Serverless Workload, without"operator": true,mirrord execconnects, and a request with thebaggageheader reaches the local process.
Infrastructure as code
If you manage your infrastructure with Terraform, each step maps to standard resources:
Store the API key
aws_secretsmanager_secret, aws_secretsmanager_secret_version, aws_iam_role_policy
Allow outbound HTTPS
aws_vpc_security_group_egress_rule
Connection variables
aws_ecs_task_definition
Troubleshooting
The bootstrap's messages appear in the application container's logs. For problems that don't depend on the platform, see MetalBear Cloud Sessions-Manager, and for ones that don't depend on the deployment mode, Amazon ECS.
The task fails to start with ResourceInitializationError: unable to pull secrets
The execution role can't read the secret, or can't decrypt it with its KMS key (Store the API key), or the task has no route to Secrets Manager.
MIRRORD_SESSIONS_MANAGER_API_KEY must hold a MetalBear API key
The secret holds something other than the key, such as a JSON object. Store the key as plain text.
A connection timeout to sessions-manager or app.metalbear.com
Outbound HTTPS is blocked (Allow outbound HTTPS).
Last updated
Was this helpful?

