AWS Replicator
6 minute read
Introduction
Infrastructure deployed on AWS often requires access to shared resources defined externally. For example a VPC defined by another team to contain the application infrastructure. This makes it harder to deploy applications into LocalStack as these resource dependencies must be deployed first. These dependencies may not live in IaC where deployment is easy, or accessing the IaC may not be easy. Some resources may be referred to by ARN, for example Secrets Manager secrets, but these ARNs are partly random meaning that simply creating a new resource in LocalStack will generate a resource with a different ARN.
LocalStack AWS Replicator creates identical copies of AWS resources in a running LocalStack instance. This means that external resources can easily be replicated before deploying the main application, and removes the need to change existing stacks or create custom infrastructure, making LocalStack setup easier.
Note
The AWS Replicator is in a preview state, supporting only selected resources. It is only available as part of the LocalStack Teams plan and higher.Getting started
A valid LOCALSTACK_AUTH_TOKEN
must be configured to start the LocalStack Pro image.
Note
The Replicator is in limited preview and is available from LocalStack CLI version 4.2.0. If you encounter issues, update your LocalStack CLI.Retrieve credentials to access AWS
The AWS Replicator needs read access to your AWS account and performs a limited set of read-only operations on supported resources. These operations can be limited by creating a minimal IAM role with just the policy actions required for replication, and providing credentials to assume this role.
See the supported resources section for details of what policy actions are required for each resource.
Replication is triggered using the LocalStack CLI, which must run in a shell configured to access AWS.
If you have the aws-cli v2 installed, the cli will read credentials from your configured AWS_PROFILE
.
Otherwise, the following environment variables must be set:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_SESSION_TOKEN
(optional)AWS_DEFAULT_REGION
Tip
Use aws configure export-credentials --format env
to print the required environment variables in a format that can be evaluated.
$ eval $(AWS_PROFILE=<aws-profile> aws configure export-credentials \
--format env)
Trigger a replication job
Replication jobs can be triggered using the LocalStack CLI or an HTTP API. Both methods have two steps:
- Submit a replication job.
- Check the job status.
Using the LocalStack CLI
The Replicator CLI is part of the LocalStack CLI. Follow the installation instructions to set it up.
To start a replication job, get the ARN of the resource to replicate. Then, trigger the job using the command:
export LOCALSTACK_AUTH_TOKEN=<auth token>
export AWS_DEFAULT_REGION=...
# if required
# export AWS_ACCESS_KEY_ID=
# export AWS_SECRET_ACCESS_KEY=
localstack replicator start \
--resource-type <resource-type> \
--resource-identifier <identifier> \
[--target-account-id <account-id>] \
[--target-region-name <region-name>]
Note
Resources that supports replicating with arn can be replicated by providing --resource-arn
instead of --resource-type
and --resource-identifier
.
$ localstack replicator start --resource-arn <resource-arn>
This triggers the replication job. The output will look similar to:
{
"job_id": "50005865-1589-4f6d-a720-c86f5a5dd021",
"state": "TESTING_CONNECTION",
"error_message": null,
"type": "SINGLE_RESOURCE",
"replication_config": {
"resource_type": "AWS::SSM::PARAMETER",
"identifier": "myParameter"
}
}
Note
--target-account-id
specifies the destination AWS account for replication. If not set, the resource is replicated into account000000000000
.--target-region-name
specifies the destination AWS region. If not set, the resource is replicated into the default region from the provided credentials.
Using the HTTP API
To trigger replication via the HTTP API, send a POST
request to http://localhost.localstack.cloud:4566/_localstack/replicator/jobs
with the following payload:
{
"replication_type": "SINGLE_RESOURCE",
"replication_job_config": {
"resource_type": "<resource-type>",
"identifier": "<identifier>"
},
"source_aws_config": {
"aws_access_key_id": "...",
"aws_secret_access_key": "...",
"aws_session_token": "...", // optional
"region_name": "...",
"endpoint_url": "..." // optional
},
"target_aws_config": {} // optional, same shape as `source_aws_config`
}
Check Replication Job Status
Replication jobs run asynchronously, so you need to poll their status to check when they finish.
Using the LocalStack CLI
When creating a replication job, the response includes a job_id
.
Use this ID to check the job status:
$ export LOCALSTACK_AUTH_TOKEN=<auth token>
$ localstack replicator status <job-id>
This command returns the job status in JSON format, for example:
{
"job_id": "50005865-1589-4f6d-a720-c86f5a5dd021",
"state": "SUCCEEDED",
"error_message": null,
"type": "SINGLE_RESOURCE",
"replication_config": {
"resource_type": "AWS::SSM::PARAMETER",
"identifier": "myParameter"
}
}
For long-running jobs, the CLI can poll the status until the job reaches a terminal state.
To wait for the job to finish, use the --follow
flag.
Using the HTTP API
To check the status of a replication job via the HTTP API, send a GET
request to http://localhost.localstack.cloud:4566/_localstack/replicator/jobs/<job-id>
.
Tip
If the replication state isSUCCEEDED
but the resource is missing, check in account 000000000000
.Quickstart
This quickstart example creates an SSM parameter in AWS and replicates it to LocalStack.
To start, create the parameter in AWS.
This example uses an SSO profile named ls-sandbox
for AWS configuration, and replicates resources from the eu-central-1
region.
$ AWS_PROFILE=ls-sandbox aws ssm put-parameter\
--name myparam \
--type String \
--value abc123
{
"Version": 1,
"Tier": "Standard"
}
$ AWS_PROFILE=ls-sandbox aws ssm get-parameters --names myparam
{
"Parameters": [
{
"Name": "myparam",
"Type": "String",
"Value": "abc123",
"Version": 1,
"LastModifiedDate": "2025-02-07T13:36:56.240000+00:00",
"ARN": "arn:aws:ssm:eu-central-1:<account-id>:parameter/myparam",
"DataType": "text"
}
],
"InvalidParameters": []
}
The SSM parameter has the ARN: arn:aws:ssm:eu-central-1:<account-id>:parameter/myparam
.
Next, we can check that the parameter is not present in LocalStack using awslocal
:
$ awslocal ssm get-parameters --name myparam
{
"Parameters": [],
"InvalidParameters": [
"myparam"
]
}
Next, trigger replication from AWS to LocalStack.
This example uses an SSO profile named ls-sandbox
for AWS configuration.
$ LOCALSTACK_AUTH_TOKEN=<ls-auth-token> \
AWS_PROFILE=ls-sandbox \
localstack replicator start \
--resource-type AWS::SSM::Parameter \
--resource-identifier <identifier> \
Configured credentials from the AWS CLI
{
"job_id": "9acdc850-f71b-4474-b138-1668eb8b8396",
"state": "TESTING_CONNECTION",
"error_message": null,
"type": "SINGLE_RESOURCE",
"replication_config": {
"resource_type": "AWS::SSM::PARAMETER",
"identifier": "myparam"
}
}
You can check the replication job status using the job_id
:
$ LOCALSTACK_AUTH_TOKEN=<ls-auth-token> \
localstack replicator status 9acdc850-f71b-4474-b138-1668eb8b8396
{
"job_id": "9acdc850-f71b-4474-b138-1668eb8b8396",
"state": "SUCCEEDED",
"error_message": null,
"type": "SINGLE_RESOURCE",
"replication_config": {
"resource_arn": "arn:aws:ssm:eu-central-1:<account-id>:parameter/myparam"
}
}
The state is SUCCEEDED
, indicating the replication job completed successfully.
The SSM parameter is now accessible.
$ awslocal ssm get-parameters --name myparam --region eu-central-1
{
"Parameters": [
{
"Name": "myparam",
"Type": "String",
"Value": "abc123",
"Version": 1,
"LastModifiedDate": 1738935663.08,
"ARN": "arn:aws:ssm:eu-central-1:000000000000:parameter/myparam",
"DataType": "text"
}
],
"InvalidParameters": []
}
The resource is replicated into the same AWS region by default.
Use the --target-region-name
flag to change it.
By default, replication occurs in LocalStack account 000000000000
.
Use the --target-account-id
flag to specify a different account.
Supported Resources
Tip
To ensure support for all resources, use the latest LocalStack Docker image.Resource Type | Service | Identifer | Required Actions | Arn Support |
---|---|---|---|---|
AWS::EC2::SecurityGroup | ec2 | GroupId | cloudformation:GetResource ec2:DescribeSecurityGroups | ✔️ |
AWS::EC2::Subnet | ec2 | SubnetId | cloudformation:GetResource ec2:DescribeSubnets | ✔️ |
AWS::EC2::VPC | ec2 | VpcId | cloudformation:GetResource ec2:DescribeVpcs | ✔️ |
AWS::IAM::Policy | iam | Arn | iam:GetPolicy | ✔️ |
AWS::IAM::Role | iam | RoleName | cloudformation:GetResource iam:GetRole | ✔️ |
AWS::KMS::Key | kms | KeyId | cloudformation:GetResource kms:DescribeKey | ✔️ |
AWS::Lambda::LayerVersion | lambda | LayerVersionArn | cloudformation:GetResource lambda:GetLayerVersion | ✔️ |
AWS::SSM::Parameter | ssm | Name | cloudformation:GetResource ssm:GetParameters | ✔️ |
AWS::SecretsManager::Secret | secretsmanager | Arn | cloudformation:GetResource secretsmanager:DescribeSecret | ✔️ |