{"id":19447079,"url":"https://github.com/stacktape/starter-lambda-api-mysql","last_synced_at":"2026-06-19T05:32:42.492Z","repository":{"id":226143574,"uuid":"679259769","full_name":"stacktape/starter-lambda-api-mysql","owner":"stacktape","description":"Stacktape starter project","archived":false,"fork":false,"pushed_at":"2026-02-04T16:37:27.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-05T03:59:52.012Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://stacktape.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stacktape.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-16T12:52:34.000Z","updated_at":"2026-02-04T16:37:31.000Z","dependencies_parsed_at":"2024-06-26T14:49:31.821Z","dependency_job_id":"c58eb818-bd08-426e-9f97-a8df6d4c73db","html_url":"https://github.com/stacktape/starter-lambda-api-mysql","commit_stats":null,"previous_names":["stacktape/starter-lambda-api-mysql"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stacktape/starter-lambda-api-mysql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacktape%2Fstarter-lambda-api-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacktape%2Fstarter-lambda-api-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacktape%2Fstarter-lambda-api-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacktape%2Fstarter-lambda-api-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stacktape","download_url":"https://codeload.github.com/stacktape/starter-lambda-api-mysql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacktape%2Fstarter-lambda-api-mysql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34519049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T16:16:22.792Z","updated_at":"2026-06-19T05:32:42.480Z","avatar_url":"https://github.com/stacktape.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Lambda API with MySQL\n\n\u003e [!TIP]\n\u003e To deploy this project using **GUI-based flow**, navigate to [console](https://console.stacktape.com/create-new-project/git-project-using-console?name=my-stacktape-app\u0026repositoryType=public\u0026repositoryUrl=https://github.com/stacktape/starter-lambda-api-mysql)\n\n- simple Lambda-based HTTP API.\n- The application runs in a [Lambda function](https://docs.stacktape.com/compute-resources/lambda-functions/) and uses a\n  MySQL [relational database](https://docs.stacktape.com/resources/relational-databases/) to store the data. To simplify\n  the database access, this project uses [Prisma](https://www.prisma.io/).\n- This project includes a pre-configured [stacktape.yml configuration](stacktape.yml).\nThe configured infrastructure is described in the [stack description section](#stack-description)\n\n## Prerequisites\n\n1. **AWS account**. If you don't have one, [create new account here](https://portal.aws.amazon.com/billing/signup).\n\n2. **Stacktape account**. If you don't have one, [create new account here](https://console.stacktape.com/sign-up).\n\n3. **Stacktape installed**.\n\n  \u003cdetails\u003e\n  \u003csummary\u003eInstall on Windows (Powershell)\u003c/summary\u003e\n\n  ```bash\n  iwr https://installs.stacktape.com/windows.ps1 -useb | iex\n  ```\n\n  \u003c/details\u003e\n  \u003cdetails\u003e\n  \u003csummary\u003eInstall on Linux\u003c/summary\u003e\n\n  ```bash\n  curl -L https://installs.stacktape.com/linux.sh | sh\n  ```\n\n  \u003c/details\u003e\n  \u003cdetails\u003e\n  \u003csummary\u003eInstall on MacOS\u003c/summary\u003e\n\n  ```bash\n  curl -L https://installs.stacktape.com/macos.sh | sh\n  ```\n\n  \u003c/details\u003e\n  \u003cdetails\u003e\n  \u003csummary\u003eInstall on MacOS ARM (Apple silicon)\u003c/summary\u003e\n\n  ```bash\n  curl -L https://installs.stacktape.com/macos-arm.sh | sh\n  ```\n\n  \u003c/details\u003e\n\n\n\n\n## 1. Generate your project\nTo initialize the project, use\n\n```bash\nstacktape init --starterId lambda-api-mysql\n```\n\n\n\n\n## 2. Deploy your stack\n\nThe deployment will take ~5-15 minutes. Subsequent deploys will be significantly faster.\n\n\u003cdetails\u003e\n\u003csummary\u003eDeploy from local machine\u003c/summary\u003e\n\n\u003cbr /\u003e\n\nThe deployment from local machine will build and deploy the application from your system. This means you also need to have:\n- Docker. To install Docker on your system, you can follow [this guide](https://docs.docker.com/get-docker/).- Node.js installed.\n\n\u003cbr /\u003e\n\nTo perform the deployment, use the following command:\n\n```bash\nstacktape deploy --projectName \u003c\u003cproject-name\u003e\u003e --stage \u003c\u003cstage\u003e\u003e --region \u003c\u003cregion\u003e\u003e\n```\n\n`stage` is an arbitrary name of your environment (for example **staging**, **production** or **dev-john**)\n\n`region` is the AWS region, where your stack will be deployed to. All the available regions are listed below.\n\n`projectName` is the name of your project. You can create it in the console or interactively using CLI.\n\n\u003cbr /\u003e\n\n| Region name \u0026 Location     | code           |\n  | -------------------------- | -------------- |\n  | Europe (Ireland)           | eu-west-1      |\n  | Europe (London)            | eu-west-2      |\n  | Europe (Frankfurt)         | eu-central-1   |\n  | Europe (Milan)             | eu-south-1     |\n  | Europe (Paris)             | eu-west-3      |\n  | Europe (Stockholm)         | eu-north-1     |\n  | US East (Ohio)             | us-east-2      |\n  | US East (N. Virginia)      | us-east-1      |\n  | US West (N. California)    | us-west-1      |\n  | US West (Oregon)           | us-west-2      |\n  | Canada (Central)           | ca-central-1   |\n  | Africa (Cape Town)         | af-south-1     |\n  | Asia Pacific (Hong Kong)   | ap-east-1      |\n  | Asia Pacific (Mumbai)      | ap-south-1     |\n  | Asia Pacific (Osaka-Local) | ap-northeast-3 |\n  | Asia Pacific (Seoul)       | ap-northeast-2 |\n  | Asia Pacific (Singapore)   | ap-southeast-1 |\n  | Asia Pacific (Sydney)      | ap-southeast-2 |\n  | Asia Pacific (Tokyo)       | ap-northeast-1 |\n  | China (Beijing)            | cn-north-1     |\n  | China (Ningxia)            | cn-northwest-1 |\n  | Middle East (Bahrain)      | me-south-1     |\n  | South America (São Paulo)  | sa-east-1      |\n\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003eDeploy using AWS CodeBuild pipeline\u003c/summary\u003e\n\n\u003cbr /\u003e\n\nDeployment using AWS CodeBuild will build and deploy your application inside [AWS CodeBuild pipeline](https://aws.amazon.com/codebuild/). To perform the deployment, use\n\n```bash\nstacktape codebuild:deploy --stage \u003c\u003cstage\u003e\u003e --region \u003c\u003cregion\u003e\u003e --projectName \u003c\u003cproject-name\u003e\u003e\n```\n\n`stage` is an arbitrary name of your environment (for example **staging**, **production** or **dev-john**)\n\n`region` is the AWS region, where your stack will be deployed to. All the available regions are listed below.\n\n`projectName` is the name of your project. You can create it in the console or interactively using CLI.\n\n\u003cbr /\u003e\n\n| Region name \u0026 Location     | code           |\n  | -------------------------- | -------------- |\n  | Europe (Ireland)           | eu-west-1      |\n  | Europe (London)            | eu-west-2      |\n  | Europe (Frankfurt)         | eu-central-1   |\n  | Europe (Milan)             | eu-south-1     |\n  | Europe (Paris)             | eu-west-3      |\n  | Europe (Stockholm)         | eu-north-1     |\n  | US East (Ohio)             | us-east-2      |\n  | US East (N. Virginia)      | us-east-1      |\n  | US West (N. California)    | us-west-1      |\n  | US West (Oregon)           | us-west-2      |\n  | Canada (Central)           | ca-central-1   |\n  | Africa (Cape Town)         | af-south-1     |\n  | Asia Pacific (Hong Kong)   | ap-east-1      |\n  | Asia Pacific (Mumbai)      | ap-south-1     |\n  | Asia Pacific (Osaka-Local) | ap-northeast-3 |\n  | Asia Pacific (Seoul)       | ap-northeast-2 |\n  | Asia Pacific (Singapore)   | ap-southeast-1 |\n  | Asia Pacific (Sydney)      | ap-southeast-2 |\n  | Asia Pacific (Tokyo)       | ap-northeast-1 |\n  | China (Beijing)            | cn-north-1     |\n  | China (Ningxia)            | cn-northwest-1 |\n  | Middle East (Bahrain)      | me-south-1     |\n  | South America (São Paulo)  | sa-east-1      |\n\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003eDeploy using Github actions CI/CD pipeline\u003c/summary\u003e\n\n\u003cbr /\u003e\n\n1. If you don't have one, create a new repository at https://github.com/new\n2. Create Github repository secrets: https://docs.stacktape.com/user-guides/ci-cd/#2-create-github-repository-secrets\n3. Replace `\u003c\u003cstage\u003e\u003e` and `\u003c\u003cregion\u003e\u003e` in the .github/workflows/deploy.yml file.\n4. `git init --initial-branch=main`\n5. `git add .`\n6. `git commit -m \"setup stacktape project\"`\n7. `git remote add origin git@github.com:\u003c\u003cnamespace-name\u003e\u003e/\u003c\u003crepo-name\u003e\u003e.git`\n8. `git push -u origin main`\n9. To monitor the deployment progress, navigate to your github project and select the Actions tab\n\n`stage` is an arbitrary name of your environment (for example **staging**, **production** or **dev-john**)\n\n`region` is the AWS region, where your stack will be deployed to. All the available regions are listed below.\n\n`projectName` is the name of your project. You can create it in the console or interactively using CLI.\n\n\u003cbr /\u003e\n\n| Region name \u0026 Location     | code           |\n  | -------------------------- | -------------- |\n  | Europe (Ireland)           | eu-west-1      |\n  | Europe (London)            | eu-west-2      |\n  | Europe (Frankfurt)         | eu-central-1   |\n  | Europe (Milan)             | eu-south-1     |\n  | Europe (Paris)             | eu-west-3      |\n  | Europe (Stockholm)         | eu-north-1     |\n  | US East (Ohio)             | us-east-2      |\n  | US East (N. Virginia)      | us-east-1      |\n  | US West (N. California)    | us-west-1      |\n  | US West (Oregon)           | us-west-2      |\n  | Canada (Central)           | ca-central-1   |\n  | Africa (Cape Town)         | af-south-1     |\n  | Asia Pacific (Hong Kong)   | ap-east-1      |\n  | Asia Pacific (Mumbai)      | ap-south-1     |\n  | Asia Pacific (Osaka-Local) | ap-northeast-3 |\n  | Asia Pacific (Seoul)       | ap-northeast-2 |\n  | Asia Pacific (Singapore)   | ap-southeast-1 |\n  | Asia Pacific (Sydney)      | ap-southeast-2 |\n  | Asia Pacific (Tokyo)       | ap-northeast-1 |\n  | China (Beijing)            | cn-north-1     |\n  | China (Ningxia)            | cn-northwest-1 |\n  | Middle East (Bahrain)      | me-south-1     |\n  | South America (São Paulo)  | sa-east-1      |\n\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003eDeploy using Gitlab CI pipeline\u003c/summary\u003e\n\n\u003cbr /\u003e\n\n1. If you don't have one, create a new repository at https://gitlab.com/projects/new\n2. Create Gitlab repository secrets: https://docs.stacktape.com/user-guides/ci-cd/#2-create-gitlab-repository-secrets\n3. replace `\u003c\u003cstage\u003e\u003e` and `\u003c\u003cregion\u003e\u003e` in the .gitlab-ci.yml file.\n4. `git init --initial-branch=main`\n5. `git add .`\n6. `git commit -m \"setup stacktape project\"`\n7. `git remote add origin git@gitlab.com:\u003c\u003cnamespace-name\u003e\u003e/\u003c\u003crepo-name\u003e\u003e.git`\n8. `git push -u origin main`\n9. `To monitor the deployment progress, navigate to your gitlab project and select CI/CD-\u003ejobs`\n\n`stage` is an arbitrary name of your environment (for example **staging**, **production** or **dev-john**)\n\n`region` is the AWS region, where your stack will be deployed to. All the available regions are listed below.\n\n`projectName` is the name of your project. You can create it in the console or interactively using CLI.\n\n\u003cbr /\u003e\n\n| Region name \u0026 Location     | code           |\n  | -------------------------- | -------------- |\n  | Europe (Ireland)           | eu-west-1      |\n  | Europe (London)            | eu-west-2      |\n  | Europe (Frankfurt)         | eu-central-1   |\n  | Europe (Milan)             | eu-south-1     |\n  | Europe (Paris)             | eu-west-3      |\n  | Europe (Stockholm)         | eu-north-1     |\n  | US East (Ohio)             | us-east-2      |\n  | US East (N. Virginia)      | us-east-1      |\n  | US West (N. California)    | us-west-1      |\n  | US West (Oregon)           | us-west-2      |\n  | Canada (Central)           | ca-central-1   |\n  | Africa (Cape Town)         | af-south-1     |\n  | Asia Pacific (Hong Kong)   | ap-east-1      |\n  | Asia Pacific (Mumbai)      | ap-south-1     |\n  | Asia Pacific (Osaka-Local) | ap-northeast-3 |\n  | Asia Pacific (Seoul)       | ap-northeast-2 |\n  | Asia Pacific (Singapore)   | ap-southeast-1 |\n  | Asia Pacific (Sydney)      | ap-southeast-2 |\n  | Asia Pacific (Tokyo)       | ap-northeast-1 |\n  | China (Beijing)            | cn-north-1     |\n  | China (Ningxia)            | cn-northwest-1 |\n  | Middle East (Bahrain)      | me-south-1     |\n  | South America (São Paulo)  | sa-east-1      |\n\n\u003c/details\u003e\n\n## 3. Test your application\n\nAfter a successful deployment, some information about the stack will be printed to the terminal (**URLs** of the deployed services, links to **logs**, **metrics**, etc.).\n\nTo test the application, you will need the web service URL. It's printed to the terminal.\n\n### Create a post\nMake a `POST` request to `\u003c\u003cweb_service_url\u003e\u003e/post` with the JSON data in its body to save the post. Use your preferred HTTP client or\nthe following cURL command:\n\n```bash\ncurl -X POST \u003c\u003cweb_service_url\u003e\u003e/posts -H 'content-type: application/json' -d '{ \"title\": \"MyPost\", \"content\": \"Hello!\", \"authorEmail\": \"info@stacktape.com\"}'\n```\n\nIf the above cURL command did not work, try escaping the JSON content:\n\n```bash\ncurl -X POST \u003c\u003cweb_service_url\u003e\u003e/posts -H 'content-type: application/json' -d '{ \\\"title\\\":\\\"MyPost\\\",\\\"content\\\":\\\"Hello!\\\",\\\"authorEmail\\\":\\\"info@stacktape.com\\\"}'\n```\n\n### Get all posts\n\nMake a `GET` request to `\u003c\u003cweb_service_url\u003e\u003e/posts` to get all posts.\n\n```bash\ncurl \u003c\u003cweb_service_url\u003e\u003e/posts\n```\n\n## 4. Run the application in development mode\nTo run functions in the development mode (remotely on AWS), you can use the\n[dev command](https://docs.stacktape.com/cli/commands/dev/). For example, to develop and debug lambda function `savePost`, you can use\n\n```bash\nstacktape dev --region \u003c\u003cyour-region\u003e\u003e --stage \u003c\u003cstage\u003e\u003e --resourceName savePost\n```\n\nThe command will:\n- quickly re-build and re-deploy your new function code\n- watch for the function logs and pretty-print them to the terminal\n\nThe function is rebuilt and redeployed, when you either:\n- type `rs + enter` to the terminal\n- use the `--watch` option and one of your source code files changes\n\n## 5. Hotswap deploys\n- Stacktape deployments use [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) under the hood. It\n  brings a lot of guarantees and convenience, but can be slow for certain use-cases.\n\n- To speed up the deployment, you can use the `--hotSwap` flag which avoids using Cloudformation.\n- Hotswap deployments work only for source code changes (for lambda function, containers and batch jobs) and for content uploads to buckets.\n- If the update deployment is not hot-swappable, Stacktape will automatically fall back to using a Cloudformation deployment.\n```bash\nstacktape deploy --hotSwap --stage \u003c\u003cstage\u003e\u003e --region \u003c\u003cregion\u003e\u003e --projectName \u003c\u003cproject-name\u003e\u003e\n```\n\n## 6. Delete your stack\n\n- If you no longer want to use your stack, you can delete it.\n- Stacktape will automatically delete every infrastructure resource and deployment artifact associated with your stack.\n\n```bash\nstacktape delete --stage \u003c\u003cstage\u003e\u003e --region \u003c\u003cregion\u003e\u003e\n```\n\n# Stack description\n\n  Stacktape uses a simple `stacktape.yml` configuration file to describe infrastructure resources, packaging, deployment\n  pipeline and other aspects of your project.\n\n  You can deploy your project to multiple environments (stages) - for\n  example `production`, `staging` or `dev-john`. A stack is a running instance of an project. It consists of your application\n  code (if any) and the infrastructure resources required to run it.\n\n  The configuration for this project is described below.\n\n  ## 1. Resources\n\n  - Every resource must have an arbitrary, alphanumeric name (A-z0-9).\n  - Stacktape resources consist of multiple underlying AWS or 3rd party resources.\n### 1.1 HTTP API Gateway\n\nAPI Gateway receives requests and routes them to the container.\n\nFor convenience, it has [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) allowed.\n\n```yml\nresources:\n  mainApiGateway:\n    type: http-api-gateway\n    properties:\n      cors:\n        enabled: true\n```\n\n### 1.2 MySQL relational database\n\nThe application data is stored in a MySQL database. The database is configured as follows:\n\n- **Database credentials**. In this example, we input them directly. In production, you should use\n  [secrets](https://docs.stacktape.com/resources/secrets/) to store them securely.\n\n- **Engine type**. We are using `mysql` engine. It uses a single-node database server - the simplest and cheapest\n  option.\n\n- **Instance size**. We are using the `db.t3.micro` instance. It has 1 vCPU, 1GB of memory, and is free-tier eligible\n  (~$12.5/month without a free tier). To see the full list of available options, refer to\n  [AWS instance type list](https://aws.amazon.com/rds/instance-types/).\n\nBy default, the version used for the database is the latest AWS-supported stable version (currently `8.0.27`). Minor\nversion upgrades are done automatically.\n\nYou can also configure many other aspects of your database, such as\n[storage](https://docs.stacktape.com/resources/relational-databases/#storage),\n[logging](https://docs.stacktape.com/resources/relational-databases/#logging),\n[read replicas](https://docs.stacktape.com/resources/relational-databases/#read-replicas), or\n[failover instances](https://docs.stacktape.com/resources/relational-databases/#multi-az-mode).\n\n```yml\nmainDatabase:\n  type: relational-database\n  properties:\n    credentials:\n      masterUserPassword: my_secret_password\n    engine:\n      type: mysql\n      properties:\n        primaryInstance:\n          instanceSize: db.t3.micro\n```\n\n### 1.3 Functions\n\nThe core of our application consists of two serverless functions:\n\n- **savePost function** - saves post into database\n- **getPosts function** - get all posts from the database\n\nFunctions are configured as follows:\n\n- **Packaging** - determines how the lambda artifact is built. The easiest and most optimized way to build the lambda\n  from Typescript/Javascript is using `stacktape-lambda-buildpack`. We only need to configure `entryfilePath`. Stacktape\n  automatically transpiles and builds the application code with all of its dependencies, creates the lambda zip\n  artifact, and uploads it to a pre-created S3 bucket on AWS. You can also use\n  [other types of packaging](https://docs.stacktape.com/configuration/packaging/#packaging-lambda-functions).\n- **ConnectTo list** - we are adding database `mainDatabase` into `connectTo` list. By doing this, Stacktape will\n  automatically inject relevant environment variables into the function's runtime (such as the connection string\n  required to connect to the database)\n- **Events** - Events determine how is function triggered. In this case, we are triggering the function when an event\n  (HTTP request) is delivered to the HTTP API gateway:\n\n  - if URL path is `/posts` and HTTP method is `POST`, request is delivered to `savePost` function.\n  - if URL path is `/posts` and HTTP method is `GET`, request is delivered to `getPosts` function.\n\n  Event(request) including the request body is passed to the function handler as an argument.\n\n```yml\nsavePost:\n    type: function\n    properties:\n      packaging:\n        type: stacktape-lambda-buildpack\n        properties:\n          entryfilePath: ./src/lambdas/save-post.ts\n      memory: 512\n      connectTo:\n        - mainDatabase\n      events:\n        - type: http-api-gateway\n          properties:\n            httpApiGatewayName: mainApiGateway\n            path: /post\n            method: POST\n\n  getPosts:\n    type: function\n    properties:\n      packaging:\n        type: stacktape-lambda-buildpack\n        properties:\n          entryfilePath: ./src/lambdas/get-posts.ts\n      memory: 512\n      connectTo:\n        - mainDatabase\n      events:\n        - type: http-api-gateway\n          properties:\n            httpApiGatewayName: mainApiGateway\n            path: /posts\n            method: GET\n```\n\n## 2. Database migration hooks\n\nTo simplify database access and migrations, this project uses [Prisma](https://www.prisma.io/). If you're not familiar\nwith it, don't worry - it's very simple. [Prisma schema](https://www.prisma.io/docs/concepts/components/prisma-schema)\nfor this application is already configured at `prisma/schema.prisma` in the project directory.\n\n### 2.1 Generate Prisma client\n\nPrisma offers a database client that we can import into our code. To generate it, we use the `npx prisma generate`\ncommand. To do it automatically every time before the stack is deployed, the command is saved as a\n[script](https://docs.stacktape.com/configuration/scripts/) and then used inside a `beforeDeploy`\n[hook](https://docs.stacktape.com/configuration/hooks/). We are also creating a hook to install dependencies when\ndeploying from CI.\n\n```yml\nscripts:\n  generatePrismaClient:\n    executeCommand: npx prisma generate\n\nhooks:\n  beforeDeploy:\n    - executeNamedScript: generatePrismaClient\n```\n\n### 2.2 Prisma database migration\n\nTo sync our Prisma schema with the database, we need to use `npx prisma db push` command. We can't do this before the\ndatabase is created, so we use the `afterDeploy` hook.\n\nWe also need to pass the `STP_MAIN_DATABASE_CONNECTION_STRING` environment variable to the script. We do it using the\n[$ResourceParam()](https://docs.stacktape.com/configuration/directives/#resource-param) directive that will\nautomatically download the connection string value and pass it to the script.\n\n```yml\nscripts:\n  generatePrismaClient:\n    executeCommand: npx prisma generate\n    migrateDb:\n    executeCommand: npx prisma db push --skip-generate\n    environment:\n      - name: STP_MAIN_DATABASE_CONNECTION_STRING\n        value: $ResourceParam('mainDatabase', 'connectionString')\n  \nhooks:\n  beforeDeploy:\n    - executeNamedScript: generatePrismaClient\n    afterDeploy:\n    - executeNamedScript: migrateDb\n  ```\n\nYou can also execute the migration script anytime using\n\n```bash\nstp script:run --scriptName migrateDb --stage \u003c\u003cpreviously-used-stage\u003e\u003e --region \u003c\u003cpreviously-used-region\u003e\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacktape%2Fstarter-lambda-api-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstacktape%2Fstarter-lambda-api-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacktape%2Fstarter-lambda-api-mysql/lists"}