LocalStack extension that proxies AWS resources into your LocalStack instance
Project description
AWS Cloud Proxy Extension (experimental)
A LocalStack extension to proxy and integrate AWS resources into your local machine. This enables one flavor of "hybrid" or "remocal" setups where you can easily bridge the gap between LocalStack (local resources) and remote AWS (resources in the real cloud).
⚠️ Please note that this extension is experimental and still under active development.
⚠️ Note: Given that the scope of this extension has recently changed (see below) - it has been renamed from aws-replicator to aws-proxy.
Prerequisites
- LocalStack Pro
- Docker
- Python
AWS Cloud Proxy
The AWS Cloud Proxy can be used to forward certain API calls in LocalStack to real AWS, in order to enable seamless transition between local and remote resources.
Warning: Be careful when using the proxy - make sure to never give access to production accounts or any critical/sensitive data!
Usage
Using curl (API)
The proxy can be enabled and disabled via the LocalStack internal API. This is the recommended approach.
-
Start LocalStack and install the AWS Proxy extension (restart LocalStack after installation).
-
Enable the proxy for specific services (e.g., DynamoDB, S3, Cognito) by posting a configuration along with your AWS credentials:
$ curl -X POST http://localhost:4566/_localstack/aws/proxies \
-H 'Content-Type: application/json' \
-d '{
"config": {
"services": {
"dynamodb": {},
"s3": {},
"cognito-idp": {}
}
},
"env_vars": {
"AWS_ACCESS_KEY_ID": "<your-access-key-id>",
"AWS_SECRET_ACCESS_KEY": "<your-secret-access-key>",
"AWS_SESSION_TOKEN": "<your-session-token>"
}
}'
- Check the proxy status:
$ curl http://localhost:4566/_localstack/aws/proxies/status
- Disable the proxy:
$ curl -X POST http://localhost:4566/_localstack/aws/proxies/status \
-H 'Content-Type: application/json' \
-d '{"status": "disabled"}'
- Now, when issuing an API call against LocalStack (e.g., via
awslocal), the invocation gets forwarded to real AWS and should return data from your real cloud resources.
Using the LocalStack Web App
You can also configure the proxy from the LocalStack Web App at https://app.localstack.cloud. Navigate to your instance and use the AWS Proxy extension settings to enable/disable the proxy and manage credentials.
Alternatively, the extension exposes a local configuration UI at http://localhost:4566/_localstack/aws-proxy/index.html (requires starting LocalStack with EXTRA_CORS_ALLOWED_ORIGINS=https://aws-proxy.localhost.localstack.cloud:4566). Use this Web UI to define the proxy configuration (in YAML syntax) and AWS credentials, then save the configuration. To clean up the running proxy container, click "disable" in the UI.
Resource-specific proxying
As an alternative to forwarding all requests for a particular service, you can also proxy only requests for specific resources to AWS.
For example, assume we own an S3 bucket my-s3-bucket in AWS, then we can use the following configuration to forward any requests to s3://my-s3-bucket to real AWS, while still handling requests to all other buckets locally in LocalStack:
services:
s3:
resources:
# list of ARNs of S3 buckets to proxy to real AWS
- '.*:my-s3-bucket'
operations:
# list of operation name regex patterns (optional)
- 'Get.*'
- 'Put.*'
# optionally, specify that only read requests should be allowed (Get*/List*/Describe*, etc)
read_only: false
# optionally, allow invoke/execute operations (e.g., Lambda invocations) alongside read_only mode.
# execute operations have side-effects and are deliberately excluded from read_only by default.
execute: false
Pass this configuration in the config field of the POST /_localstack/aws/proxies request body (as shown above).
If we then perform local operations against the S3 bucket my-s3-bucket, the proxy will forward the request and will return the results from real AWS:
$ awslocal s3 ls s3://my-s3-bucket
2023-05-14 15:53:40 148 my-file-1.txt
2023-05-15 10:24:43 22 my-file-2.txt
Any other S3 requests targeting other buckets will be run against the local state in LocalStack itself, for example:
$ awslocal s3 mb s3://test123
make_bucket: test123
...
A more comprehensive sample, involving local Lambda functions combined with remote SQS queues and S3 buckets, can be found in the example folder of this repo.
Configuration
In addition to the proxy services configuration shown above, the following configs can be used to customize the behavior of the extension itself (simply pass them as environment variables to the main LocalStack container):
PROXY_CLEANUP_CONTAINERS: whether to clean up (remove) the proxy Docker containers once they shut down (default1). Can be set to0to help debug issues, e.g., if a proxy container starts up and exits immediately.PROXY_LOCALSTACK_HOST: the target host to use when the proxy container connects to the LocalStack main container (automatically determined by default)PROXY_DOCKER_FLAGS: additional flags that should be passed when creating the proxy Docker containers
Resource Replicator CLI (deprecated)
Note: Previous versions of this extension also offered a "replicate" mode to copy/clone (rather than proxy) resources from an AWS account into the local instance. This functionality has been removed from this extension, and is now available directly in the LocalStack Pro image (see here).
If you wish to access the deprecated instructions, they can be found here.
Change Log
0.2.4: Replace deprecatedlocalstack aws proxyCLI command with direct Python/HTTP-based proxy startup; update README with curl-based usage instructions0.2.3: Enhance proxy support and tests for several services (API Gateway v1/v2, CloudWatch, AppSync, Kinesis, KMS, SNS, Cognito-IDP)0.2.2: Refactor UI to use WebAppExtension pattern0.2.1: Restructure project to use pyproject.toml0.2.0: Rename extension fromlocalstack-extension-aws-replicatortolocalstack-extension-aws-proxy0.1.25: Fix dynamodb proxying for read-only mode0.1.24: Fix healthcheck probe for proxy container0.1.23: Fix unpinned React.js dependencies preventing webui from loading0.1.22: Fix auth-related imports that prevent the AWS proxy from starting0.1.20: Fix logic for proxying S3 requests with*.s3.amazonaws.comhost header0.1.19: Print human-readable message for invalid regexes in resource configs; fix logic for proxying S3 requests with host-based addressing0.1.18: Update environment check to use SDK Docker client and enable starting the proxy from within Docker (e.g., from the LS main container as part of an init script)0.1.17: Add basic support for ARN-based pattern-matching forsecretsmanagerresources0.1.16: Update imports for localstack >=3.6 compatibility0.1.15: Move localstack dependency installation to extra since it's provided at runtime0.1.14: Install missing dependencies into proxy container for localstack >=3.4 compatibility0.1.13: Add compatibility with localstack >=3.4; add http2-server; migrate to localstack auth login0.1.12: Modify aws credentials text field type to password0.1.11: Fix broken imports after recent upstream CloudFormation changes0.1.10: AddREPLICATOR_PROXY_DOCKER_FLAGSoption to pass custom flags to proxy Docker containers0.1.9: Enhance proxy networking and addREPLICATOR_LOCALSTACK_HOSTconfig option0.1.8: AddREPLICATOR_CLEANUP_PROXY_CONTAINERSoption to skip removing proxy containers for debugging0.1.7: Add rolo dependency to tests0.1.6: Adjust config to supportLOCALSTACK_AUTH_TOKENin addition to legacy API keys0.1.5: Minor fix to accommodate recent upstream changes0.1.4: Fix imports ofbootstrap.authmodules for v3.0 compatibility0.1.3: Adjust code imports for recent LocalStack v3.0 module changes0.1.2: Remove deprecated ProxyListener for starting local aws-replicator proxy server0.1.1: Add simple configuration Web UI0.1.0: Initial version of extension
License
This extension is published under the Apache License, Version 2.0. By using it, you also agree to the LocalStack End-User License Agreement (EULA).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file localstack_extension_aws_proxy-0.2.4.tar.gz.
File metadata
- Download URL: localstack_extension_aws_proxy-0.2.4.tar.gz
- Upload date:
- Size: 1.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2459c96a792682cd169609f8f707e54a2bc80b69d5eb1e0ab290f4e697941cb8
|
|
| MD5 |
b46a779218ed45451395d1aeffd7b63c
|
|
| BLAKE2b-256 |
3e0f0b9f6c62afba276ffa50274195770080a294c56412ec417594073af810c1
|
File details
Details for the file localstack_extension_aws_proxy-0.2.4-py3-none-any.whl.
File metadata
- Download URL: localstack_extension_aws_proxy-0.2.4-py3-none-any.whl
- Upload date:
- Size: 1.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ed0206ea7113d7a7f51d0220850101ee5aadb6717563468a59fbc66969f5c3d
|
|
| MD5 |
4b430c37b1a2df78f2a23c47c477fc62
|
|
| BLAKE2b-256 |
6c309759b0743d5ca053ff8e02cf2117fd46d50a5ef2e5af95c52368fa452ea9
|