-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deploying resources to AWS via GH actions
- Loading branch information
1 parent
fa1e1e6
commit 7ea52d3
Showing
7 changed files
with
11,299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: example dir `deployment-with-github-actions` deployment | ||
|
||
on: | ||
push: | ||
branches: | ||
- main # run the workflow when a push is made to the main branch | ||
paths: | ||
- deployment-with-github-actions | ||
|
||
pull_request: | ||
branches: | ||
- main # run the workflow when the target branch of the PR is main | ||
paths: | ||
- deployment-with-github-actions | ||
|
||
permissions: | ||
id-token: write # This is required for requesting the JWT | ||
contents: read # This is required for actions/checkout | ||
|
||
defaults: | ||
run: | ||
working-directory: ./deployment-with-github-actions | ||
|
||
env: | ||
AWS_REGION : 'eu-west-2' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: ⬇️ Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: ⎔ Setup node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Unit test | ||
run: npm run test | ||
|
||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git clone the repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: ⎔ Setup node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
run: node -v | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: configure aws credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: arn:aws:iam::552686430014:role/github-actions-ci-cd-deployment-role | ||
role-session-name: github-action-sls-examples | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: versions | ||
run: | | ||
pwd | ||
node -v | ||
aws --version | ||
sls --version | ||
- name: deploy | ||
run: npm run deploy:dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# package directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Serverless directories | ||
.serverless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<!-- | ||
title: 'AWS Simple HTTP Endpoint example in NodeJS' | ||
description: 'This template demonstrates how to make a simple HTTP API with Node.js running on AWS Lambda and API Gateway using the Serverless Framework.' | ||
layout: Doc | ||
framework: v3 | ||
platform: AWS | ||
language: nodeJS | ||
authorLink: 'https://github.com/serverless' | ||
authorName: 'Serverless, inc.' | ||
authorAvatar: 'https://avatars1.githubusercontent.com/u/13742415?s=200&v=4' | ||
--> | ||
|
||
# Serverless Framework Node HTTP API on AWS | ||
|
||
This template demonstrates how to make a simple HTTP API with Node.js running on AWS Lambda and API Gateway using the Serverless Framework. | ||
|
||
This template does not include any kind of persistence (database). For more advanced examples, check out the [serverless/examples repository](https://github.com/serverless/examples/) which includes Typescript, Mongo, DynamoDB and other examples. | ||
|
||
## Usage | ||
|
||
### Deployment | ||
|
||
``` | ||
$ serverless deploy | ||
``` | ||
|
||
After deploying, you should see output similar to: | ||
|
||
```bash | ||
Deploying aws-node-http-api-project to stage dev (us-east-1) | ||
|
||
✔ Service deployed to stack aws-node-http-api-project-dev (152s) | ||
|
||
endpoint: GET - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/ | ||
functions: | ||
hello: aws-node-http-api-project-dev-hello (1.9 kB) | ||
``` | ||
|
||
_Note_: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to [http event docs](https://www.serverless.com/framework/docs/providers/aws/events/apigateway/). | ||
|
||
### Invocation | ||
|
||
After successful deployment, you can call the created application via HTTP: | ||
|
||
```bash | ||
curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/ | ||
``` | ||
|
||
Which should result in response similar to the following (removed `input` content for brevity): | ||
|
||
```json | ||
{ | ||
"message": "Go Serverless v2.0! Your function executed successfully!", | ||
"input": { | ||
... | ||
} | ||
} | ||
``` | ||
|
||
### Local development | ||
|
||
You can invoke your function locally by using the following command: | ||
|
||
```bash | ||
serverless invoke local --function hello | ||
``` | ||
|
||
Which should result in response similar to the following: | ||
|
||
``` | ||
{ | ||
"statusCode": 200, | ||
"body": "{\n \"message\": \"Go Serverless v3.0! Your function executed successfully!\",\n \"input\": \"\"\n}" | ||
} | ||
``` | ||
|
||
|
||
Alternatively, it is also possible to emulate API Gateway and Lambda locally by using `serverless-offline` plugin. In order to do that, execute the following command: | ||
|
||
```bash | ||
serverless plugin install -n serverless-offline | ||
``` | ||
|
||
It will add the `serverless-offline` plugin to `devDependencies` in `package.json` file as well as will add it to `plugins` in `serverless.yml`. | ||
|
||
After installation, you can start local emulation with: | ||
|
||
``` | ||
serverless offline | ||
``` | ||
|
||
To learn more about the capabilities of `serverless-offline`, please refer to its [GitHub repository](https://github.com/dherault/serverless-offline). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const handler = async (event) => { | ||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ message: 'hello this is updated via github actions' }), | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}; | ||
} |
Oops, something went wrong.