Skip to content

Commit

Permalink
fix the terraform config
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshCasper committed Feb 19, 2024
1 parent 09d0dd2 commit 86299f9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- uses: gautamkrishnar/keepalive-workflow@v1

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2

Expand Down Expand Up @@ -55,6 +57,10 @@ jobs:
tflocal init
tflocal apply --auto-approve
- name: Deploy Web Application
run: |
make run
- name: Check deployed resources
run: |
sleep 10
Expand Down Expand Up @@ -93,6 +99,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- uses: gautamkrishnar/keepalive-workflow@v1

- name: Set up Python 3.10
id: setup-python
uses: actions/setup-python@v2
Expand Down Expand Up @@ -123,6 +131,10 @@ jobs:
CF_FILE="ecsapi-demo-cloudformation.yaml"
awslocal cloudformation create-stack --stack-name $STACK --template-body file://$CF_FILE
- name: Deploy Web Application
run: |
make run
- name: Check deployed resources
run: |
sleep 10
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ run: ## Run the sample app
@echo "Building Web assets and uploading to local S3 bucket 🪣"; \
cd client-application-react; \
test -e node_modules || yarn; \
test -e build/index.html || yarn build; \
test -e build/index.html || NODE_OPTIONS=--openssl-legacy-provider yarn build; \
awslocal s3 mb s3://sample-app; \
awslocal s3 sync build s3://sample-app; \
API_ID=$$(awslocal apigatewayv2 get-apis | jq -r '.Items[] | select(.Name=="ecsapi-demo") | .ApiId'); \
Expand Down
31 changes: 9 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ We are using the following AWS services and their features to build our infrastr
Start LocalStack Pro with the appropriate configuration to enable the S3 website to send requests to the container APIs:

```shell
export LOCALSTACK_API_KEY=<your-api-key>
export LOCALSTACK_AUTH_TOKEN=<your-auth-token>
EXTRA_CORS_ALLOWED_ORIGINS=http://sample-app.s3.localhost.localstack.cloud:4566 DISABLE_CUSTOM_CORS_APIGATEWAY=1 DEBUG=1 localstack start
```

Expand Down Expand Up @@ -95,7 +95,7 @@ To build the web application, navigate to the root directory of the sample appli
```shell
cd client-application-react
yarn
yarn build
NODE_OPTIONS=--openssl-legacy-provider yarn build
```

Ensure a `build` directory is created in the `client-application-react` directory.
Expand Down Expand Up @@ -146,34 +146,22 @@ Alternatively, you can use the AWS CLI to query the table data. For example, to
awslocal dynamodb scan --table-name FoodStoreFoods
```

## Cloud Pods
## State Management

[Cloud Pods](https://docs.localstack.cloud/user-guide/tools/cloud-pods/) are a mechanism that allows you to take a snapshot of the state in your current LocalStack instance, persist it to a storage backend, and easily share it with your team members.
The [Export/Import State feature](https://docs.localstack.cloud/user-guide/state-management/export-import-state/) enables you to export the state of your LocalStack instance into a file and import it into another LocalStack instance. This feature is useful when you want to save your LocalStack instance’s state for later use.

To save your local AWS infrastructure state using Cloud Pods, you can use the `save` command with a desired name for your Cloud Pod as the first argument:
To save your local AWS infrastructure state, you can use the `export` command with a desired name for your state file as the first argument:

```bash
localstack pod save cloud-pod/serverless-api-ecs-apigateway-pod
localstack state export serverless-api-ecs-apigateway-state
```

You can alternatively use the `save` command with a local file path as the first argument to save the Cloud Pod on your local file system and not the LocalStack Web Application:
The above command will create a file named `serverless-api-ecs-apigateway-state` to the specified location on the disk.

```bash
localstack pod save file://<path_to_disk>/serverless-api-ecs-apigateway-pod
```

The above command will create a zip file named `serverless-api-ecs-apigateway-pod` to the specified location on the disk.

The `load` command is the inverse operation of the `save` command. It retrieves the content of a previously stored Cloud Pod from the local file system or the LocalStack Web Application and injects it into the application runtime. On an alternate machine, start LocalStack with the API key configured, and pull the Cloud Pod we created previously using the `load` command with the Cloud Pod name as the first argument:
You can import the state file we created previously using the `import` command with the file name as the first argument:

```bash
localstack pod load serverless-api-ecs-apigateway-pod
```

Alternatively, you can use load the Cloud Pod with the local file path as the first argument:

```bash
localstack pod load file://<path_to_disk>/serverless-api-ecs-apigateway-pod
localstack state import serverless-api-ecs-apigateway-state
```

To ensure everything is set in place now, follow the previous steps of setting the configuration variables and query the application URL. The state will be restored, and you should be able to see the same data as before.
Expand All @@ -192,4 +180,3 @@ The sample application is based on a public [AWS sample app](https://github.com/

We appreciate your interest in contributing to our project and are always looking for new ways to improve the developer experience. We welcome feedback, bug reports, and even feature ideas from the community.
Please refer to the [contributing file](CONTRIBUTING.md) for more details on how to get started.

Binary file not shown.
6 changes: 3 additions & 3 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ resource "aws_ecs_task_definition" "task_definition_foodstore_foods" {
[
{
"name": "FoodstoreFoods",
"image": "localstack.container-registry.com/library/foodstore",
"image": "localstack/ecsapi-demo-foodstore",
"essential": true,
"environment": [
{"name": "DynamoDBTable", "value": "${aws_dynamodb_table.dynamo_db_table_foodstore_foods.name}"}
Expand All @@ -544,7 +544,7 @@ resource "aws_ecs_task_definition" "task_definition_petstore_pets" {
[
{
"name": "PetstorePets",
"image": "localstack.container-registry.com/library/petstore",
"image": "localstack/ecsapi-demo-petstore",
"essential": true,
"environment": [
{"name": "DynamoDBTable", "value": "${aws_dynamodb_table.dynamo_db_table_petstore_pets.name}"}
Expand Down Expand Up @@ -663,7 +663,7 @@ resource "aws_apigatewayv2_api" "http_api" {
"${aws_cognito_user_pool_client.user_pool_client.client_secret}"
]
# TODO: look into better parity with AWS
issuer = "http://localhost:4566/${aws_cognito_user_pool.user_pool.id}"
issuer = "http://localhost.localstack.cloud:4566/${aws_cognito_user_pool.user_pool.id}"
}
type = "jwt"
}
Expand Down

0 comments on commit 86299f9

Please sign in to comment.