Skip to content

Commit 3f608fe

Browse files
committed
Add Preview deployments + Cloudfront distro (#6)
1 parent 022a747 commit 3f608fe

31 files changed

+1137
-951
lines changed

.github/workflows/preview.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Create PR Preview
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
preview:
9+
permissions: write-all
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 15
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Deploy Preview
17+
uses: LocalStack/setup-localstack/preview@main
18+
with:
19+
github-token: ${{ secrets.GITHUB_TOKEN }}
20+
localstack-api-key: ${{ secrets.LOCALSTACK_API_KEY }}
21+
preview-cmd: |
22+
npm install -g aws-cdk-local aws-cdk
23+
pip install awscli-local[ver1]
24+
make build
25+
make bootstrap
26+
make deploy
27+
make prepare-frontend-local
28+
make build-frontend
29+
make bootstrap-frontend
30+
make deploy-frontend
31+
distributionId=$(awslocal cloudfront list-distributions | jq -r '.DistributionList.Items[0].Id')
32+
echo "Open URL: $AWS_ENDPOINT_URL/cloudfront/$AWS_DEFAULT_REGION/$distributionId/"
33+
34+
- name: Finalize PR comment
35+
uses: LocalStack/setup-localstack/finish@main
36+
with:
37+
github-token: ${{ secrets.GITHUB_TOKEN }}
38+
include-preview: true

README.md

Lines changed: 35 additions & 15 deletions
Large diffs are not rendered by default.

aws-sdk-js-notes.png

-314 KB
Binary file not shown.

images/aws-sdk-js-notes.png

380 KB
Loading

packages/backend/src/createNote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { success, failure } from "./libs/response";
55

66
// eslint-disable-next-line no-unused-vars
77
import { APIGatewayEvent } from "aws-lambda";
8+
import { endpoint } from "./libs/endpoint";
89

910
export const handler = async (event: APIGatewayEvent) => {
1011
const data = JSON.parse(event.body || "{}");
@@ -19,7 +20,7 @@ export const handler = async (event: APIGatewayEvent) => {
1920
};
2021

2122
try {
22-
const client = new DynamoDBClient({});
23+
const client = new DynamoDBClient({endpoint});
2324
await client.send(new PutItemCommand(params));
2425
return success(params.Item);
2526
} catch (e) {

packages/backend/src/deleteNote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { success, failure } from "./libs/response";
44

55
// eslint-disable-next-line no-unused-vars
66
import { APIGatewayEvent } from "aws-lambda";
7+
import { endpoint } from "./libs/endpoint";
78

89
export const handler = async (event: APIGatewayEvent) => {
910
const params = {
@@ -14,7 +15,7 @@ export const handler = async (event: APIGatewayEvent) => {
1415
};
1516

1617
try {
17-
const client = new DynamoDBClient({});
18+
const client = new DynamoDBClient({endpoint});
1819
await client.send(new DeleteItemCommand(params));
1920
return success({ status: true });
2021
} catch (e) {

packages/backend/src/getNote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { success, failure } from "./libs/response";
44

55
// eslint-disable-next-line no-unused-vars
66
import { APIGatewayEvent } from "aws-lambda";
7+
import { endpoint } from "./libs/endpoint";
78

89
export const handler = async (event: APIGatewayEvent) => {
910
const params = {
@@ -14,7 +15,7 @@ export const handler = async (event: APIGatewayEvent) => {
1415
};
1516

1617
try {
17-
const client = new DynamoDBClient({});
18+
const client = new DynamoDBClient({endpoint});
1819
const result = await client.send(new GetItemCommand(params));
1920
if (result.Item) {
2021
// Return the retrieved item

packages/backend/src/libs/endpoint.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const endpoint = process.env.AWS_ENDPOINT_URL || '';

packages/backend/src/listNotes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { DynamoDBClient, ScanCommand } from "@aws-sdk/client-dynamodb";
22
import { unmarshall } from "@aws-sdk/util-dynamodb";
33
import { success, failure } from "./libs/response";
4+
import { endpoint } from "./libs/endpoint";
45

56
export const handler = async () => {
67
const params = {
78
TableName: process.env.NOTES_TABLE_NAME || "",
89
};
910

11+
1012
try {
11-
const client = new DynamoDBClient({});
13+
const client = new DynamoDBClient({endpoint});
1214
const result = await client.send(new ScanCommand(params));
1315
// Return the matching list of items in response body
1416
return success(result.Items.map((Item) => unmarshall(Item)));

packages/backend/src/updateNote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { success, failure } from "./libs/response";
44

55
// eslint-disable-next-line no-unused-vars
66
import { APIGatewayEvent } from "aws-lambda";
7+
import { endpoint } from "./libs/endpoint";
78

89
export const handler = async (event: APIGatewayEvent) => {
910
const data = JSON.parse(event.body || "{}");
@@ -23,7 +24,7 @@ export const handler = async (event: APIGatewayEvent) => {
2324
};
2425

2526
try {
26-
const client = new DynamoDBClient({});
27+
const client = new DynamoDBClient({endpoint});
2728
await client.send(new UpdateItemCommand(params));
2829
return success({ status: true });
2930
} catch (e) {

0 commit comments

Comments
 (0)