diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5850b5b..8fdf6bd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,7 @@ on: permissions: contents: write + actions: write jobs: sam: @@ -25,8 +26,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - uses: gautamkrishnar/keepalive-workflow@v1 - - name: Setup Python uses: actions/setup-python@v4 with: @@ -42,21 +41,14 @@ jobs: with: use-installer: true - - name: Setup SAM-Local - run: | - pip install aws-sam-cli-local - samlocal --help + - name: Install lstk + run: npm install -g @localstack/lstk - name: Start LocalStack run: | - pip install localstack docker pull localstack/localstack-pro:latest # Start LocalStack in the background - DEBUG=1 localstack start -d - # Wait 30 seconds for the LocalStack container to become ready before timing out - echo "Waiting for LocalStack startup..." - localstack wait -t 15 - echo "Startup complete" + LOCALSTACK_DEBUG=1 lstk start env: LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }} @@ -65,12 +57,11 @@ jobs: cd function pip install --target ../package/python -r requirements.txt - - name: Build the SAM app + - name: Build the SAM app run: | - samlocal build + lstk sam build - name: Deploy the SAM app run: | curl http://localhost:4566/_localstack/info - samlocal deploy --no-confirm-changeset - \ No newline at end of file + lstk sam deploy --no-confirm-changeset diff --git a/Makefile b/Makefile index e336079..4ee46a0 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,9 @@ usage: ## Show this help @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which samlocal || pip install aws-sam-cli-local + @which lstk || npm install -g @localstack/lstk + @which aws || pip install awscli + @which sam || pip install aws-sam-cli start: ## Start LocalStack and Neo4j using Docker Compose @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set. Find your token at https://app.localstack.cloud/workspace/auth-token"; exit 1) @@ -18,16 +18,12 @@ start: ## Start LocalStack and Neo4j using Docker Compose stop: ## Stop LocalStack and Neo4j @docker-compose down -ready: ## Wait until LocalStack is ready - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo LocalStack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - logs: ## Save the logs in a separate file - @localstack logs > logs.txt + @lstk logs > logs.txt deploy: ## Build and deploy the SAM application cd function && pip install --target ../package/python -r requirements.txt - samlocal build - samlocal deploy --no-confirm-changeset + lstk sam build + lstk sam deploy --no-confirm-changeset -.PHONY: usage install start stop ready logs deploy +.PHONY: usage install start stop logs deploy diff --git a/README.md b/README.md index 433d41f..15da249 100644 --- a/README.md +++ b/README.md @@ -15,19 +15,18 @@ This sample application will guide you through the process of integrating a loca ## Prerequisites -- LocalStack with the [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli). -- [Serverless Application Model](https://docs.localstack.cloud/user-guide/integrations/aws-sam/) with the [`samlocal`](https://github.com/localstack/aws-sam-cli-local) installed. -- [AWS CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) with the [`awslocal` wrapper](https://docs.localstack.cloud/user-guide/integrations/aws-cli/#localstack-aws-cli-awslocal). +- LocalStack with the [`lstk` CLI](https://docs.localstack.cloud/aws/developer-tools/running-localstack/lstk/). +- [Serverless Application Model](https://docs.localstack.cloud/user-guide/integrations/aws-sam/) with `aws-sam-cli` installed, used via the `lstk sam` proxy. +- [AWS CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/), required by `lstk aws`. - [Python 3.10](https://www.python.org/downloads/) & `pip` - [Docker Compose](https://docs.docker.com/compose/install/) -- A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/) to activate LocalStack. +- A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/aws/getting-started/auth-token/) to activate LocalStack. Start LocalStack Pro with the `LOCALSTACK_AUTH_TOKEN` pre-configured: ```shell export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` The Docker Compose file will start LocalStack Pro and a local Neo4j database. The `LOCALSTACK_AUTH_TOKEN` environment variable is required to activate the LocalStack Pro features, such as Lambda Layers in this example. @@ -48,7 +47,7 @@ pip install --target ../package/python -r requirements.txt To build the SAM application, run the following command from the root directory of the application: ```shell -samlocal build +lstk sam build ``` If you see a `Build Succeeded` message, you can proceed to the next step. @@ -59,7 +58,7 @@ If you see a `Build Succeeded` message, you can proceed to the next step. To deploy the SAM application, run the following command: ```shell -samlocal deploy --guided +lstk sam deploy --guided ``` The above command will create a new managed S3 bucket to store the artifacts of the SAM application. If you want to use an existing S3 bucket, you can use the `--s3-bucket` flag to specify the bucket name. Before being deployed, the CloudFormation changeset will be displayed in the terminal. If you want to deploy the application without confirmation, you can use the `--no-confirm-changeset` flag. @@ -72,8 +71,8 @@ You need to update the Lambda function configuration to use the Neo4j environmen export NEO4J_PASSWORD=neo4j-harsh-test export NEO4J_URI=bolt://neo4j:7687 export NEO4J_USERNAME=neo4j -FUNCTION=$(awslocal cloudformation describe-stack-resource --stack-name sam-app --logical-resource-id function --query 'StackResourceDetail.PhysicalResourceId' --output text) -awslocal lambda update-function-configuration \ +FUNCTION=$(lstk aws cloudformation describe-stack-resource --stack-name sam-app --logical-resource-id function --query 'StackResourceDetail.PhysicalResourceId' --output text) +lstk aws lambda update-function-configuration \ --function-name $FUNCTION \ --environment "Variables={NEO4J_USERNAME=$NEO4J_USERNAME,NEO4J_PASSWORD=$NEO4J_PASSWORD,NEO4J_URI=$NEO4J_URI}" ``` @@ -83,7 +82,7 @@ awslocal lambda update-function-configuration \ You can invoke the Lambda function using the following command: ```shell -awslocal lambda invoke \ +lstk aws lambda invoke \ --function-name $FUNCTION \ --payload file://event.json \ --cli-binary-format raw-in-base64-out out.json diff --git a/docker-compose.yml b/docker-compose.yml index 40a6cec..4a42521 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.9' services: localstack: - container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}" + container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-aws}" image: localstack/localstack-pro:latest # required for Pro ports: - "127.0.0.1:4566:4566" # LocalStack Gateway