This project involves deploying a backend Flask API as a serverless function on AWS Lambda using Zappa and automating the process with GitHub Actions. The backend is designed to support a sample Chrome extension that calculates sales and use tax fields for an Amazon businesses.
To receive your API URL as a notifications via Slack, you'll need to set up an Incoming Webhook in Slack and store the necessary parts of the webhook URL as secrets in your GitHub repository.
- Go to your Slack workspace and navigate to Apps.
- Create new App from scratch
- Select the workspace for the app and select Create App
- Under OAuth & permissions add a scope called incoming-webhook
- Under OAuth Tokens click on Install to "your_workspace"
- Next, choose the channel where you want to receive notifications.
- Now in the Features menu, click Incoming Webhooks
- Scroll until you see Webhook URL. This URL will look something like this:
https://hooks.slack.com/services/TXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX
- Fork the repository to your GitHub account.
- Go to your forked repository on GitHub.
- Navigate to Settings > Secrets and variables > Actions.
- Add the following secrets:
- AWS_ACCESS_KEY_ID: Your AWS Access Key ID.
- AWS_SECRET_ACCESS_KEY: Your AWS Secret Access Key.
- SLACK_TEAM_ID: (Optional) If using Slack notifications, this corresponds to the
TXXXXXXXX
part of your Slack Webhook URL. - SLACK_CHANNEL_ID: (Optional) Corresponds to the
BXXXXXXXX
part of your Slack Webhook URL. - SLACK_TOKEN: (Optional) Corresponds to the
XXXXXXXXXXXXXXXXXXXXXXXX
part of your Slack Webhook URL.
-
Clone your forked repository to your local machine:
git clone https://github.com/YOUR_GITHUB_USERNAME/amz-sales-use-tax-app.git cd amz-sales-use-tax-app
-
Open the
zappa_settings.json
file and make the following changes:- environment: Set this to the branch name you are working on (default is
main
). - s3_bucket: Set your AWS S3 bucket name (e.g.,
"s3_bucket": "zappa-yourbucketname"
).
PRO TIP: You can generate a random string of characters for the bucket name by running:
- environment: Set this to the branch name you are working on (default is
openssl rand -hex 4
Example bucket name: "s3_bucket": "zappa-v1kpvbat6",
-
Commit and push your changes to your GitHub repository:
git add . git commit -m "Configured zappa_settings.json" git push origin YOUR_BRANCH_NAME
- After the deployment is triggered by your commit, grab the API URL:
- From the logs of the GitHub Actions workflow.
- Or, if using Slack, check the Slack channel for the notification with the API URL.
- Open
Chrome EXT > popup.js
and replace"YOUR_API_URL"
in thefetch
call with your actual API URL.
- Open Chrome and navigate to
chrome://extensions
. - Turn on Developer mode in the top right corner.
- Click Load unpacked in the top left.
- Select the
Chrome EXT
folder from your local repo.
- Use the Chrome extension to upload a CSV file and verify that the API processes the sales and use tax calculations correctly.
To make testing easy, there’s a sample file included in the repository called SampleData.csv
. You can use this file to test your setup.
When you upload SampleData.csv
through the Chrome extension, the API should return the following results:
- Total Sales in California: 847.46
- Total Sales for the Period: 8,409.62
- Total Sales in Other States: 7,562.16
If you see these numbers, your setup is working correctly!
By following these simple steps, you can quickly set up and deploy the backend for your Chrome extension using AWS Lambda and Zappa. This streamlined process ensures you spend less time on setup and more time on building and testing your application.