From 0470da9623848d4e1a342f4eb6f0e45a90bc17e5 Mon Sep 17 00:00:00 2001 From: "meetkumar.patel" Date: Thu, 30 May 2024 14:49:32 -0400 Subject: [PATCH 1/3] add cors, headers --- api.js | 16 ++++++++++------ serverless.yml | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/api.js b/api.js index 5c18c04..955da1f 100644 --- a/api.js +++ b/api.js @@ -8,8 +8,13 @@ const { } = require("@aws-sdk/client-dynamodb"); const { marshall, unmarshall } = require("@aws-sdk/util-dynamodb"); +const headers = { + 'Access-Control-Allow-Origin': '*', // Allow from any origin + 'Access-Control-Allow-Credentials': true +}; + const getNote = async (event) => { - const response = { statusCode: 200 }; + const response = { statusCode: 200, headers }; try { const params = { @@ -19,7 +24,6 @@ const getNote = async (event) => { const { Item } = await db.send(new GetItemCommand(params)); console.log({ Item }); - console.log("ci/cd check 2"); response.body = JSON.stringify({ message: "Successfully retrieved note.", data: (Item) ? unmarshall(Item) : {}, @@ -39,7 +43,7 @@ const getNote = async (event) => { }; const createNote = async (event) => { - const response = { statusCode: 200 }; + const response = { statusCode: 200, headers }; try { const body = JSON.parse(event.body); @@ -67,7 +71,7 @@ const createNote = async (event) => { }; const updateNote = async (event) => { - const response = { statusCode: 200 }; + const response = { statusCode: 200, headers }; try { const body = JSON.parse(event.body); @@ -105,7 +109,7 @@ const updateNote = async (event) => { }; const deleteNote = async (event) => { - const response = { statusCode: 200 }; + const response = { statusCode: 200, headers }; try { const params = { @@ -132,7 +136,7 @@ const deleteNote = async (event) => { }; const getAllNotes = async () => { - const response = { statusCode: 200 }; + const response = { statusCode: 200, headers }; try { const { Items } = await db.send(new ScanCommand({ TableName: process.env.DYNAMODB_TABLE_NAME })); diff --git a/serverless.yml b/serverless.yml index 77cf49e..113efd2 100644 --- a/serverless.yml +++ b/serverless.yml @@ -24,6 +24,7 @@ functions: - http: path: note/{noteId} method: GET + cors: true iamRoleStatements: - Effect: "Allow" Action: @@ -38,6 +39,7 @@ functions: - http: path: note method: POST + cors: true iamRoleStatements: - Effect: "Allow" Action: @@ -52,6 +54,7 @@ functions: - http: path: note/{noteId} method: PUT + cors: true iamRoleStatements: - Effect: "Allow" Action: @@ -66,6 +69,7 @@ functions: - http: path: note/{noteId} method: DELETE + cors: true iamRoleStatements: - Effect: "Allow" Action: @@ -80,6 +84,7 @@ functions: - http: path: notes method: GET + cors: true iamRoleStatements: - Effect: "Allow" Action: From 5cbf4b4dd287bdef236c0a0f1fe8175ef59737f1 Mon Sep 17 00:00:00 2001 From: Meet Patel <99104527+mspatell@users.noreply.github.com> Date: Sat, 19 Jul 2025 12:44:34 -0400 Subject: [PATCH 2/3] package upgrade: action/action@v3 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 61b11f3..3e4f4f1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so the job can access it - uses: actions/checkout@v2 - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: '**/node_modules' key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} From 1db819066b384a184803420b9b26b4fe48cf4a83 Mon Sep 17 00:00:00 2001 From: Meet Patel <99104527+mspatell@users.noreply.github.com> Date: Sat, 19 Jul 2025 13:13:05 -0400 Subject: [PATCH 3/3] update sls secret key & value --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3e4f4f1..32a1b1e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,7 +36,7 @@ jobs: with: args: deploy env: - # SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} + SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} # or if using AWS creds directly AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}