diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 82c7958..df9c205 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,6 +14,9 @@ on: - cron: "0 0 * * 0" workflow_dispatch: +permissions: + contents: write + jobs: terraform: name: Deploy infrastructure using Terraform @@ -22,8 +25,12 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - uses: gautamkrishnar/keepalive-workflow@v1 + - name: Setup Terraform - uses: hashicorp/setup-terraform@v2 + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: "1.5.7" - name: Set up Python 3.10 id: setup-python @@ -55,6 +62,10 @@ jobs: tflocal init tflocal apply --auto-approve + - name: Deploy Web Application + run: | + make run + - name: Check deployed resources run: | sleep 10 @@ -116,13 +127,17 @@ jobs: echo "Startup complete" - - name: Deploy on Terraform + - name: Deploy on CloudFormation run: | cd cloudformation STACK="stack1" 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 diff --git a/Makefile b/Makefile index 60275ae..dd06081 100644 --- a/Makefile +++ b/Makefile @@ -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'); \ diff --git a/README.md b/README.md index 9a412cb..5589b4c 100644 --- a/README.md +++ b/README.md @@ -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= +export LOCALSTACK_AUTH_TOKEN= EXTRA_CORS_ALLOWED_ORIGINS=http://sample-app.s3.localhost.localstack.cloud:4566 DISABLE_CUSTOM_CORS_APIGATEWAY=1 DEBUG=1 localstack start ``` @@ -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. @@ -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:///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:///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. @@ -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. - diff --git a/cloud-pod/sample-pod b/cloud-pod/serverless-api-ecs-apigateway-state similarity index 52% rename from cloud-pod/sample-pod rename to cloud-pod/serverless-api-ecs-apigateway-state index a7f2cb7..902e744 100644 Binary files a/cloud-pod/sample-pod and b/cloud-pod/serverless-api-ecs-apigateway-state differ diff --git a/terraform/main.tf b/terraform/main.tf index 0de7d52..43e5cb7 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -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}"} @@ -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}"} @@ -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" }