# LocalStack Cloud Pods

Cloud Pods - sounds fancy, right? Well, they certainly are an elegant solution - they're all about a dynamic and efficient approach to managing state within your LocalStack ecosystem and sharing it like a pro with your squad.

Gone are the days of mundane infrastructure setup and data restore routines at every startup of LocalStack. Cloud Pods eliminate all those reboot worries, making it a breeze to set the stage for your top-priority work.

We’ll get to a follow-along example in a minute, but first, let’s have a look at how things work.

Instead of simply restoring a state when restarting LocalStack, Cloud Pods allow you to take snapshots of your local instance (with the `save` command) and inject such snapshots into a running instance (with the `load` command) without requiring a restart.

In addition, we provide a remote storage backend that can be used to store the state of your running application and share it with your team members.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693153073015/ff5f3b60-96b9-4db4-835b-20a58d80522d.png align="center")

Now, let’s explore how this is done.

1. Clone the repository.
    
    ```bash
    git clone https://github.com/tinyg210/stack-bytes-apigw-lambda-s3.git
    ```
    
2. Export your `LOCALSTACK_API_KEY` as an environment variable.
    
    ```bash
    export LOCALSTACK_API_KEY=<YOUR_API_KEY>
    ```
    
    \*Sidenote: make sure there’s `apigw-lambda.jar` in the `/stack-bytes-lambda/target/` folder. If not, or if anything fails, please run `mvn clean package shade:shade` in the `stack-bytes-lambda` folder.
    
3. Start LocalStack:
    
    ```bash
    docker compose up
    ```
    
4. Let’s add some Quotes to our S3 storage:
    
    ```bash
    curl --location 'http://id12345.execute-api.localhost.localstack.cloud:4566/dev/quoteApi' \
                                        --header 'Content-Type: application/json' \
                                        --data '{
                                        "author": "Shrek",
                                        "text": "NO! You dense, irritating, miniature beast of burden! Ogres are like onions!"
                                    }'
    curl --location 'http://id12345.execute-api.localhost.localstack.cloud:4566/dev/quoteApi' \
                                        --header 'Content-Type: application/json' \
                                        --data '{
                                        "author": "Donkey",
                                        "text": "And in the morning...I\'m making waffles!"
                                    }'
    ```
    
5. Log in to the `localstack CLI` tool with your registered account and password to get the full Cloud Pod experience. You can only create a snapshot on your machine if you are not logged in.
    
    ```bash
    localstack login
    ```
    
6. Now that we have a reasonable amount of data, let’s save our state:
    
    ```bash
    localstack pod save cloud-pod-quotes
    
    Cloud Pod cloud-pod-quotes successfully exported.
    ```
    
7. We can confidently shut down our containers.
    
    ```bash
    docker compose down
    ```
    
8. Verify the pod is there for your team to see.
    
    ```bash
    localstack pod list
    ┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    ┃ local/remote ┃ Name                                 ┃
    ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
    │    remote    │ cloud-pod-quotes                     │
    ```
    
9. Let’s start a fresh instance of LocalStack, this time using the CLI tool.
    
    ```bash
    localstack start
    ```
    
10. Load the pod into the LocalStack container.
    
    ```bash
    localstack pod load cloud-pod-quotes
    ```
    
11. Verify that the state and data are there:
    
    ```bash
    curl --location 'http://id12345.execute-api.localhost.localstack.cloud:4566/dev/quoteApi?author=Donkey'
    
    {"text":"Quote: And in the morning...I'm making waffles!"}
    ```
    
    ```bash
    curl --location 'http://id12345.execute-api.localhost.localstack.cloud:4566/dev/quoteApi?author=Shrek'
    
    {"text":"Quote: NO! You dense, irritating, miniature beast of burden! Ogres are like onions!"}⏎
    ```
    

Smooth sailing all the way! We did a little state and data magic and tucked them neatly into a Cloud Pod. Now, it's our secret weapon – perfect for sprinkling LocalStack goodness into those repetitive acts like CI tests. And hey, sharing is caring, right? So, we pass this Cloud Pod gem to our colleagues for a front-row seat to our LocalStack brilliance.
