Skip to content

Commit

Permalink
update to new cli interface and add coverage table
Browse files Browse the repository at this point in the history
  • Loading branch information
cloutierMat committed Feb 25, 2025
1 parent a597ef9 commit 46df5bd
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 25 deletions.
66 changes: 41 additions & 25 deletions content/en/user-guide/tools/aws-replicator/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: "AWS Replicator"
weight: 13
description: "AWS Replicator makes it easier to use LocalStack in shared AWS environments by copying resources into LocalStack using their ARNs."
tags: ["Pro image"]
description: "AWS Replicator makes it easier to use LocalStack in shared AWS environments by copying resources into LocalStack."
tags: ["Teams plan"]
---

## Introduction
Expand All @@ -12,18 +12,29 @@ It helps when deploying applications that rely on existing resources like SSM pa

This removes the need to change existing stacks or create custom infrastructure, making LocalStack setup easier.

{{< callout "note">}}
The AWS Replicator is in a preview state, supporting only [selected resources](#supported-resources).
It is only available as part of the **LocalStack Teams** plan and higher.
{{< /callout >}}

## Getting started

To get started, set `LOCALSTACK_ENABLE_REPLICATOR=1` configuration variable when starting LocalStack.
A valid `LOCALSTACK_AUTH_TOKEN` must be configured to start the LocalStack Pro image.

{{< callout "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](https://docs.localstack.cloud/getting-started/installation/#updating).
{{< /callout >}}


Check failure on line 30 in content/en/user-guide/tools/aws-replicator/index.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Multiple consecutive blank lines

content/en/user-guide/tools/aws-replicator/index.md:30 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md012.md

Check failure on line 30 in content/en/user-guide/tools/aws-replicator/index.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Multiple consecutive blank lines

content/en/user-guide/tools/aws-replicator/index.md:30 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md012.md
### Retrieve credentials to access AWS

The AWS Replicator needs read access to your AWS account and can perform a limited set of read-only operations on supported resources.

Replication is triggered using the LocalStack CLI, which must run in a shell configured to access AWS.
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`.

Check failure on line 35 in content/en/user-guide/tools/aws-replicator/index.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Max 1 sentence should be on a line

content/en/user-guide/tools/aws-replicator/index.md:35:101 max-one-sentence-per-line Max 1 sentence should be on a line [Context: "ess AWS. If yo"] https://github.com/aepfli/markdownlint-rule-max-one-sentence-per-line

Check failure on line 35 in content/en/user-guide/tools/aws-replicator/index.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Max 1 sentence should be on a line

content/en/user-guide/tools/aws-replicator/index.md:35:101 max-one-sentence-per-line Max 1 sentence should be on a line [Context: "ess AWS. If yo"] https://github.com/aepfli/markdownlint-rule-max-one-sentence-per-line

The following environment variables must be set:
Otherwise, the following environment variables must be set:

- `AWS_ACCESS_KEY_ID`
- `AWS_SECRET_ACCESS_KEY`
Expand All @@ -34,7 +45,7 @@ The following environment variables must be set:
Use `aws configure export-credentials --format env` to print the required environment variables in a format that can be evaluated.

{{< command >}}
$ eval $(AWS_PROFILE=<aws-profile> aws configure export-credentials \
<disable-copy>$ </disable-copy>eval $(AWS_PROFILE=<aws-profile> aws configure export-credentials \
--format env)
{{< /command >}}
{{< /callout >}}
Expand All @@ -52,14 +63,6 @@ Both methods have two steps:
The Replicator CLI is part of the LocalStack CLI.
Follow the [installation instructions](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) to set it up.

{{< callout "note" >}}

The Replicator is in limited preview and must be enabled with `LOCALSTACK_ENABLE_REPLICATOR=1` when using the CLI.

It is available from LocalStack CLI version 4.2.0.
If you encounter issues, update your [LocalStack CLI](https://docs.localstack.cloud/getting-started/installation/#updating).
{{< /callout >}}

To start a replication job, get the ARN of the resource to replicate.
Then, trigger the job using the command:

Expand All @@ -73,23 +76,33 @@ export AWS_DEFAULT_REGION=...
# export AWS_SECRET_ACCESS_KEY=
</disable-copy>
localstack replicator start \
--replication-type SINGLE_RESOURCE \
--resource-arn <resource-arn> \
--resource-type <resource-type> \
--identifier <identifier> \
[--target-account-id <account-id>] \
[--target-region-name <region-name>]
{{< /command >}}


Check failure on line 85 in content/en/user-guide/tools/aws-replicator/index.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Multiple consecutive blank lines

content/en/user-guide/tools/aws-replicator/index.md:85 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md012.md

Check failure on line 85 in content/en/user-guide/tools/aws-replicator/index.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Multiple consecutive blank lines

content/en/user-guide/tools/aws-replicator/index.md:85 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md012.md
{{< callout "note" >}}
Resources that supports replicating with arn can be replicated by providing `--resource-arn` instead of `--resource-type` and `--identifier`.

{{< command >}}
<disable-copy>$ </disable-copy>localstack replicator start --resource-arn <resource-arn>
{{< /command >}}
{{< /callout >}}

This triggers the replication job.
The output will look similar to:

```bash
```json
{
"job_id": "50005865-1589-4f6d-a720-c86f5a5dd021",
"state": "TESTING_CONNECTION",
"error_message": null,
"type": "SINGLE_RESOURCE",
"replication_config": {
"resource_arn": "arn:aws:ssm:<region>:<account-id>:parameter/myparam"
"resource_type": "AWS::SSM::PARAMETER",
"identifier": "myParameter"
}
}
```
Expand All @@ -109,7 +122,8 @@ To trigger replication via the HTTP API, send a `POST` request to `http://localh
{
"replication_type": "SINGLE_RESOURCE",
"replication_job_config": {
"resource_arn": "<arn>"
"resource_type": "<resource-type>",
"identifier": "<identifier>"
},
"source_aws_config": {
"aws_access_key_id": "...",
Expand Down Expand Up @@ -140,14 +154,15 @@ $ localstack replicator status <job-id>

This command returns the job status in JSON format, for example:

```bash
```json
{
"job_id": "50005865-1589-4f6d-a720-c86f5a5dd021",
"state": "SUCCEEDED",
"error_message": null,
"type": "SINGLE_RESOURCE",
"replication_config": {
"resource_arn": "arn:aws:ssm:<region>:<account-id>:parameter/myparam"
"resource_type": "AWS::SSM::PARAMETER",
"identifier": "myParameter"
}
}
```
Expand Down Expand Up @@ -224,8 +239,8 @@ $ LOCALSTACK_AUTH_TOKEN=<ls-auth-token> \
AWS_PROFILE=ls-sandbox \
LOCALSTACK_ENABLE_REPLICATOR=1 \
localstack replicator start \
--replication-type SINGLE_RESOURCE \
--resource-arn arn:aws:ssm:eu-central-1:<account-id>:parameter/myparam
--resource-type AWS::SSM::Parameter \
--identifier myparam
<disable-copy>
Configured credentials from the AWS CLI
{
Expand All @@ -234,7 +249,8 @@ Configured credentials from the AWS CLI
"error_message": null,
"type": "SINGLE_RESOURCE",
"replication_config": {
"resource_arn": "arn:aws:ssm:eu-central-1:<account-id>:parameter/myparam"
"resource_type": "AWS::SSM::PARAMETER",
"identifier": "myparam"
}
}
</disable-copy>
Expand Down Expand Up @@ -293,4 +309,4 @@ Use the `--target-account-id` flag to specify a different account.
To ensure support for all resources, use the latest LocalStack Docker image.
{{< /callout >}}

// WIP
{{< localstack_replicator_table >}}

Check failure on line 312 in content/en/user-guide/tools/aws-replicator/index.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Files should end with a single newline character

content/en/user-guide/tools/aws-replicator/index.md:312:35 MD047/single-trailing-newline Files should end with a single newline character https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md047.md

Check failure on line 312 in content/en/user-guide/tools/aws-replicator/index.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Files should end with a single newline character

content/en/user-guide/tools/aws-replicator/index.md:312:35 MD047/single-trailing-newline Files should end with a single newline character https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md047.md
71 changes: 71 additions & 0 deletions data/replicator/coverage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[
{
"resource_type": "AWS::EC2::SecurityGroup",
"policy_statements": [
"cloudformation:GetResource",
"ec2:DescribeSecurityGroups"
],
"service": "ec2",
"identifier": "Id"
},
{
"resource_type": "AWS::EC2::Subnet",
"policy_statements": [
"cloudformation:GetResource",
"ec2:DescribeSubnets"
],
"service": "ec2",
"identifier": "SubnetId"
},
{
"resource_type": "AWS::EC2::VPC",
"policy_statements": ["cloudformation:GetResource", "ec2:DescribeVpcs"],
"service": "ec2",
"identifier": "VpcId"
},
{
"resource_type": "AWS::IAM::Policy",
"policy_statements": ["iam:GetPolicy"],
"service": "iam",
"identifier": "Id"
},
{
"resource_type": "AWS::IAM::Role",
"policy_statements": ["cloudformation:GetResource", "iam:GetRole"],
"service": "iam",
"identifier": "RoleName"
},
{
"resource_type": "AWS::KMS::Key",
"policy_statements": ["cloudformation:GetResource", "kms:DescribeKey"],
"service": "kms",
"identifier": "KeyId"
},
{
"resource_type": "AWS::Lambda::LayerVersion",
"policy_statements": [
"cloudformation:GetResource",
"lambda:GetLayerVersion"
],
"service": "lambda",
"identifier": "LayerVersionArn"
},
{
"resource_type": "AWS::SSM::Parameter",
"policy_statements": [
"cloudformation:GetResource",
"ssm:GetParameters"
],
"service": "ssm",
"identifier": "Name"
},
{
"resource_type": "AWS::SecretsManager::Secret",
"policy_statements": [
"cloudformation:GetResource",
"secretsmanager:DescribeSecret"
],
"service": "secretsmanager",
"identifier": "Id"
}
]
21 changes: 21 additions & 0 deletions layouts/partials/replicator/replicator_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="coverage-report">
<table>
<thead>
<tr>
<th class="coverage-report-header-1">Resource Type</th>
<th class="coverage-report-header-2">Service</th>
<th class="coverage-report-header-1">Identifer</th>
<th class="coverage-report-header-2">Required Actions</th>
<th class="coverage-report-header-1">Arn Support</th>
</tr>
</thead>
<tbody>
{{ $data := .Site.Data.replicator.coverage }}

{{ range $data }}
{{ partial "replicator/replicator_table_row" . }}
{{ end -}}
</tbody>
</table>
<br/>
</div>
19 changes: 19 additions & 0 deletions layouts/partials/replicator/replicator_table_row.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<tr>
<!-- Resource Type -->
<td>{{ .resource_type }}</a></td>
<!-- Service -->
<td>
{{ .service }}
</td>
<!-- Identifer -->
<td>
{{.identifier}}</td>
<!-- Required Actions -->
<td style="white-space:wrap;">
{{ range .policy_statements}}
{{ . }}<br>
{{ end -}}
</td>
<!-- Arn Support -->
<td class="coverage-shadow-overlay-green">✔️</td>
</tr>
1 change: 1 addition & 0 deletions layouts/shortcodes/localstack_replicator_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ partial "replicator/replicator_table" . }}

0 comments on commit 46df5bd

Please sign in to comment.