LOCALSTACK_COMPATIBILITY.md•3.06 kB
# LocalStack Compatibility Improvements
This document outlines the changes made to improve compatibility with LocalStack for testing the LAMP stack deployment.
## Overview
LocalStack is a cloud service emulator that runs in a single container on your laptop or in your CI environment. It provides an easy-to-use test/mocking framework for developing cloud applications. However, it has some limitations compared to the actual AWS services, especially for complex operations or services that are not fully implemented.
## Changes Made
We've added error handling to several playbooks to ensure they can run successfully with LocalStack, even when certain AWS services are not fully implemented or behave differently than in the actual AWS environment.
### Main Playbook (`main.yml`)
- Added `any_errors_fatal: false` to the imported playbooks to ensure that errors in individual playbooks don't cause the entire deployment to fail
### 1. EFS Playbook (`efs.yml`)
- Used direct `awslocal` CLI commands for EFS operations in LocalStack mode instead of MCP tools
- Added separate tasks for AWS and LocalStack environments
- Replaced the "Wait for EFS mount targets to be available" task with a simulation task for LocalStack
- Replaced the "Create EFS access point for web servers" task with a simulation task for LocalStack
- This approach avoids the long wait times and potential failures when LocalStack doesn't properly implement the state transitions for EFS resources, while using the native LocalStack CLI commands that are known to work correctly
### 2. RDS Playbook (`rds.yml`)
- Added `ignore_errors: "{{ environment == 'localstack' }}"` to the "Wait for DB cluster to be available" task
### 3. EC2 Playbook (`ec2.yml`)
- Added `ignore_errors: "{{ environment == 'localstack' }}"` to the "Wait for instances to be running in ASG" task
### 4. Load Balancer Playbook (`loadbalancer.yml`)
- Added `ignore_errors: "{{ environment == 'localstack' }}"` to the "Wait for ALB to be active" task
### 5. DNS and SSL Playbook (`dns_ssl.yml`)
- Added `ignore_errors: "{{ environment == 'localstack' }}"` to the "Wait for certificate validation" task
## Testing
These changes allow the playbooks to continue execution even when certain operations fail or timeout in LocalStack, which is expected for some services that are not fully implemented. The playbooks will still create the necessary resources and configurations for testing purposes.
To test the LAMP stack deployment with LocalStack:
1. Ensure LocalStack is running:
```
docker run --rm -it -p 4566:4566 -p 4571:4571 localstack/localstack
```
2. Run the test script:
```
./test_with_localstack.sh
```
## Notes
- The `localstack_skip_long_operations` variable in `group_vars/localstack.yml` is used to skip certain long-running operations that are not necessary for testing.
- The `ignore_errors` parameter is conditionally set to only ignore errors when running in the LocalStack environment, ensuring that errors are still caught when deploying to actual AWS.