Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Maua-Dev/battlesnake_nodejs_victorgasperi

Repository files navigation

battlesnake_nodejs_template 🐍

This is a Battlesnake template written in Typescript using the ExpressJs.

Introduction and Objectives ⁉

The main purpose of this project is to create a template for Battlesnake using Typescript NodeJS. The biggest challenge is to understand how an API works and how to deploy it in AWS Lambda.

Example

How to use 🤔

First of all, you need to create a repo using issues from Devmaua setup, set the project_name as "battlesnake_nodejs_{your name}" and project template as battlesnake_nodejs_template and make sure it's public . Hit create issue and wait for the setup to finish.

After that you need to clone your new repo, you need to install the dependecies with NPM or YARN. Just choose ONE of them, to avoid future problems!

Installation 👩‍💻

create FILE .env:
STAGE = TEST

Install the dependencies

npm install
or
yarn

Run the server locally (needs .env -> STAGE = TEST)

npm run start
or
yarn start

The Challenge 🐍

The challenge is to create a Battlesnake using NodeJs and ExpressJS. The Battlesnake must be deployed in AWS Lambda. You can find the documentation for Battlesnake here.

The files 📁

The project have one folder: src. In src, you can find the index.ts file, which is the file that contains the ExpressJS app and the routes. From there, you can create your own routes and functions.

The routes 🛣

The routes are created in the index.ts file. You can create your own routes and functions. The routes are created using Express with Typescript, you can find the documentation here. Follow the rules from the Battlesnake documentation to create your routes, they should look like this.

Attention 🚨

In order to deploy your Battlesnake in AWS Lambda, you need to follow some rules:

  • The routes must be created using express;
  • ALWAYS test your code before pushing it to the repo. You can use pytest to test your code;
  • Every file should be inside the src folder;

Deploy 🚀

After pushing your code to the repo, it will trigger an action to deploy your code in AWS Lambda. You can find the action in the .github/workflows/aws_cd.yml file.

The first time you push your code, the action will create a new stack in AWS CloudFormation. After that, every time you push your code, the action will update the stack with the new code.

In the Actions tab, you can see the status of the deploy and if it was successful or not. If it was successful, you can find the URL of your API in the outputs tab of the action (in the final part of the "Deploy with CDK" step).

Action Tab STEP

There you can find your API URL. You can use this URL to create your Battlesnake in the Battlesnake website. You can find the documentation here. You can also find a user and password to access the AWS Console and view the logs of the lambda function to debug it.

Outputs

To log in to the AWS Console, click on the link named "console" in the output, and then click "Sign in to a different account". There you need to put the account id and the user and password from the outputs tab. On your login, you are required to change your password, DON'T FORGET THE NEW ONE. After that, you can click on the link to the lambda console, and click monitor to find the logs.

Lambda Console Cloudwatch Logs

After finishing your project, you can delete it from our backend using our CD.

AwsDestroy

Useful tools 🛠

Thanks 👢🍿

We hope you like and enjoy it! Thanks!

Contributors 💰🤝💰

This project was developed to use inside the Dev. Community Mauá, but feel free to help!.

Contact us 📞

If you have any questions, feel free to contact us! You can find us in our Discord server.