Generate Infrastructure as Code from local AWS resources using LocalStack & Former2
Former2 scans your AWS resources and automatically generates Infrastructure as Code templates. Learn how to use Former2 with LocalStack to convert your local AWS prototypes into reproducible IaC templates and validate them locally before deploying to production.
Introduction
Imagine this: You’ve spent hours prototyping your AWS application locally with LocalStack — experimenting with S3 buckets, Lambda functions, and SQS queues. Now, you want to convert this ad-hoc setup into a reproducible, shareable format. Infrastructure-as-Code (IaC) is the answer, offering consistency, collaboration, and version control, but manually converting configurations often leads to templates that don’t match the expected behavior. While no tool is perfect, a “reverse IaC” solution for generating infrastructure-as-code from existing infrastructure would bridge this gap by saving time and reducing errors.
If you’re looking for exactly that, let me introduce you to Former2. This tool scans your live (or local) AWS resources and automates IaC template generation for your pre-existing AWS resources in your preferred framework. Pair it with LocalStack, and you can validate these IaC templates before deploying to the cloud, ensuring they match your expectation without costly & time-consuming trial-and-error workflows.
In this guide, we’ll explore how to convert your local AWS development environment into IaC using Former2. You’ll learn how this tool simplifies reverse-engineering your local resources into code, and how LocalStack lets you test these templates locally — no cloud account required. We’ll walk through a sample setup step-by-step, proving that your IaC works as intended before you deploy.
How Former2 Works with LocalStack
Former2 converts existing AWS resources into Infrastructure as Code (IaC) by using the AWS SDK for JavaScript to make relevant Get/List calls, scanning your infrastructure, providing you with a resource list and map them to different IaC formats. When used with LocalStack, it can generate templates from your local development environment in several formats, such as CloudFormation, Terraform, CDK, Pulumi to name a few.
The typical workflow looks like this:
- Former2 scans your LocalStack container to find existing resources like S3 buckets, Lambda functions, and DynamoDB tables.
- You select which resources to include, and Former2 creates an IaC template capturing their configuration.
- Test the template by deploying it back to LocalStack using
tflocal,cdklocal, orpulumilocaldepending on your chosen format. - Once tested, commit the template to your version control system. This lets you run automated tests in CI, or collaborate with features like Cloud Pods.
Former2 runs in your browser through a Web dashboard - no login needed. It uses a browser extension (Chrome, Firefox, Edge) to make the AWS SDK calls. Let’s see how this works by converting some sample AWS resources into IaC.
Set Up Former2
To use Former2, you can either use the publicly hosted Former2 web application or self-host it to generate the IaC outputs.
You will also need the Former2 Helper extension/add-on for your preferred web browser:
Alternatively, you can download and install the extension yourself.
Stop your LocalStack container and start it with the following environment variables, depending on the browser you are using:
- Google Chrome:
EXTRA_CORS_ALLOWED_ORIGINS=chrome-extension://fhejmeojlbhfhjndnkkleooeejklmigi - Mozilla Firefox:
EXTRA_CORS_ALLOWED_ORIGINS=moz-extension://853c673f-1bd8-4226-a5ff-f1473f7b3d90 - Microsoft Edge:
EXTRA_CORS_ALLOWED_ORIGINS=extension://okkjnfohglnomdbpimkcdkiojbeiedof
If you’re using Google Chrome, you can start the LocalStack container in the following manner:
EXTRA_CORS_ALLOWED_ORIGINS=chrome-extension://fhejmeojlbhfhjndnkkleooeejklmigi \localstack startYou can now set up the example scenario to see how Former2 maps configurations directly to your preferred IaC framework.
Example Scenario: Creating a Step Functions workflow that puts the object to an S3 bucket
To start, we’ll go through a simple scenario of creating a Step Functions workflow that publishes a file to an S3 bucket.
First, we’ll use the AWS CLI and the awslocal wrapper script to create this infrastructure. After setting up the infrastructure, we’ll use Former2 to generate a CloudFormation template, showcasing the “reverse IaC” use case. You can also convert it to other formats (like Terraform or Pulumi) based on your needs.
Assuming your LocalStack container is already running, you can create a simple S3 bucket named my-sfn-bucket-target as follows:
awslocal s3 mb s3://my-sfn-bucket-targetYou can create a state machine that calls s3:putObject. For Step Functions with the AWS SDK integrations, the Resource is arn:aws:states:::aws-sdk:s3:putObject. Let’s create a Step Functions state machine:
awslocal stepfunctions create-state-machine \ --name MyS3StateMachine \ --role-arn arn:aws:iam::000000000000:role/MyS3StateMachineRole \ --definition '{ "StartAt": "SendCustomEvent", "States": { "SendCustomEvent": { "Type": "Task", "Resource": "arn:aws:states:::aws-sdk:s3:putObject", "Parameters": { "Body": "Hello World", "Bucket": "my-sfn-bucket-target", "Key": "filename.txt" }, "End": true } } }'This will output a JSON object containing the stateMachineArn, which, in LocalStack’s default setup, would look like arn:aws:states:us-east-1:000000000000:stateMachine:MyS3StateMachine.
To test the State Machine, run an execution that calls s3:putObject:
STATE_MACHINE_ARN="arn:aws:states:us-east-1:000000000000:stateMachine:MyS3StateMachine"
awslocal stepfunctions start-execution \ --state-machine-arn "$STATE_MACHINE_ARN" \ --name "test-exec-1" \ --input '{}'To check the State Machine execution, you can run the following command:
awslocal stepfunctions list-executions --state-machine-arn "$STATE_MACHINE_ARN"Or, you can confirm that filename.txt was created in the bucket:
awslocal s3 ls s3://my-sfn-bucket-targetYou can use Step Functions or the S3 Resource Browser to analyze these details further.
Configure Former2
The next step is to configure Former2. Navigate to the Former2 setup dashboard and open the “Credentials” tab to enter your IAM credentials. For LocalStack, set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables to test and test, respectively.

Proceed to “Continue to Parameters” and add your CloudFormation stack parameters. You can leave them empty if you prefer.
Then, go to “Continue to Settings” and navigate to “Custom Endpoints”. Enable the “Use LocalStack Endpoint” switch to set the LocalStack endpoint URL (http://localhost:4566).

Finally, click on “Go to Dashboard” to complete the setup.

Click on the Scan Account button in the top-right corner of the dashboard to scan your LocalStack instance for resources. This process takes less than a minute as Former2 runs Get/List API calls across all available AWS services, including those not explicitly supported by LocalStack. You can ignore any warnings and proceed with the setup.
Generate the CloudFormation Output
After the scan is complete, select the resources to generate outputs for. In this case, choose the resources created for Step Functions and S3. Navigate to the Former2 dashboard and open the “S3” page. Locate the bucket created earlier, select it, and click “Add Selected”.

Repeat the same steps for other resources. Open the “Step Functions” page and add the state machine created earlier.

Once all resources are selected, click “Generate” in the top-left corner of the dashboard to create the IaC outputs. The generated output is available in CloudFormation, as well as other formats like Terraform, Pulumi, and CDK (v1 & v2). These formats can be explored using the options on the left-hand side of the dashboard.

Copy the generated CloudFormation template to test it against LocalStack.
Test the CloudFormation Template
To test the CloudFormation template, restart your LocalStack container. You can use awslocal to create the CloudFormation stack or use the Resource Browser. Here, we’ll use the Resource Browser.
Navigate to the CloudFormation Resource Browser and click on “Create Stack”. Paste the copied CloudFormation template into the “Template Body” field and enter a stack name (e.g., sfn-s3-stack). Click “Submit” to create the stack.

Refresh the page to check when the stack status changes from CREATE_IN_PROGRESS to CREATE_READY. Click on the stack to explore the created resources.

To test the workflow, go to the Step Functions Resource Browser and select the newly created state machine. Click “Start Execution”, provide a name and input, then click “Submit”.

The execution should succeed, and you can view the state machine execution under “Events”. To check the S3 file, navigate to the S3 Resource Browser, open the bucket, and locate the filename.txt file.

Conclusion
“Reverse IaC” solutions transform infrastructure management from a manual, error-prone process into a systematic, code-driven approach. Tools like Former2 and LocalStack help developers automatically generate Infrastructure as Code (IaC) templates from existing resources, bridging the gap between ad-hoc deployments and reproducible infrastructure. This workflow enables teams to document their current system architecture, gradually adopt IaC practices, and create living documentation of their infrastructure’s state, while also supporting local testing and validation of these templates.
While promising, these automatically generated templates serve as a starting point rather than a complete solution. Critical elements like IAM roles, permissions, and detailed resource configurations typically require manual review and refinement. LocalStack and Former2 aim to reduce infrastructure management complexity, but they are ultimately tools that empower developers to initiate IaC adoption, not automatic solutions that work entirely on their own.
The true value emerges when infrastructure transitions from a complex, manual process to a reproducible, version-controlled asset that can be consistently deployed, tested, and maintained across different environments.