Skip to content

Commit 3100e16

Browse files
HarshCasperbentskusteffyP
authored
prepare application for developer hub (#1)
* prepare application for developer hub Co-Authored-By: Benjamin Simon <[email protected]> * add a github action workflow * add a README file to the app sample * add LocalSurf info + node-js hint to README * Update README.md Co-authored-by: steffyP <[email protected]> * Update README.md Co-authored-by: steffyP <[email protected]> --------- Co-authored-by: Benjamin Simon <[email protected]> Co-authored-by: Stefanie Plieschnegger <[email protected]> Co-authored-by: steffyP <[email protected]>
1 parent 66a863f commit 3100e16

File tree

10 files changed

+159
-152
lines changed

10 files changed

+159
-152
lines changed

.github/workflows/main.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Deploy on LocalStack
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'README.md'
7+
branches:
8+
- master
9+
pull_request:
10+
branches:
11+
- master
12+
13+
jobs:
14+
terraform:
15+
name: Setup infrastructure using SAM
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
21+
- name: Setup Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.8'
25+
26+
- name: Setup SAM
27+
uses: aws-actions/setup-sam@v2
28+
with:
29+
use-installer: true
30+
31+
- name: Setup SAM-Local
32+
run: |
33+
pip install aws-sam-cli-local
34+
samlocal --help
35+
36+
- name: Start LocalStack
37+
env:
38+
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
39+
DNS_ADDRESS: 0
40+
run: |
41+
pip install localstack awscli-local[ver1]
42+
docker pull localstack/localstack-pro:latest
43+
# Start LocalStack in the background
44+
DEBUG=1 localstack start -d
45+
# Wait 30 seconds for the LocalStack container to become ready before timing out
46+
echo "Waiting for LocalStack startup..."
47+
localstack wait -t 15
48+
echo "Startup complete"
49+
50+
- name: Build the SAM application
51+
run: make backend
52+
53+
- name: List the resources
54+
run: |
55+
awslocal lambda list-functions
56+
awslocal s3 ls
57+
awslocal dynamodb list-tables
58+
awslocal sqs list-queues

Makefile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
all: backend frontend-build
22

33
TEMPLATES = auth product-mock shoppingcart-service
4-
5-
REGION := $(shell python3 -c 'import boto3; print(boto3.Session().region_name)')
4+
REGION := us-east-1
5+
# REGION := $(shell python3 -c 'import boto3; print(boto3.Session().region_name)')
66
ifndef S3_BUCKET
7-
ACCOUNT_ID := $(shell aws sts get-caller-identity --query Account --output text)
7+
ACCOUNT_ID := 000000000000
8+
# ACCOUNT_ID := $(shell aws sts get-caller-identity --query Account --output text)
89
S3_BUCKET = aws-serverless-shopping-cart-src-$(ACCOUNT_ID)-$(REGION)
910
endif
1011

1112

1213
backend: create-bucket
13-
$(MAKE) -C backend TEMPLATE=auth S3_BUCKET=$(S3_BUCKET)
14-
$(MAKE) -C backend TEMPLATE=product-mock S3_BUCKET=$(S3_BUCKET)
15-
$(MAKE) -C backend TEMPLATE=shoppingcart-service S3_BUCKET=$(S3_BUCKET)
14+
$(MAKE) -C backend TEMPLATE=auth S3_BUCKET=$(S3_BUCKET) REGION=${REGION}
15+
$(MAKE) -C backend TEMPLATE=product-mock S3_BUCKET=$(S3_BUCKET) REGION=${REGION}
16+
$(MAKE) -C backend TEMPLATE=shoppingcart-service S3_BUCKET=$(S3_BUCKET) REGION=${REGION}
1617

1718
backend-delete:
18-
$(MAKE) -C backend delete TEMPLATE=auth
19-
$(MAKE) -C backend delete TEMPLATE=product-mock
20-
$(MAKE) -C backend delete TEMPLATE=shoppingcart-service
19+
$(MAKE) -C backend delete TEMPLATE=auth REGION=${REGION}
20+
$(MAKE) -C backend delete TEMPLATE=product-mock REGION=${REGION}
21+
$(MAKE) -C backend delete TEMPLATE=shoppingcart-service REGION=${REGION}
2122

2223
backend-tests:
2324
$(MAKE) -C backend tests
2425

2526
create-bucket:
2627
@echo "Checking if S3 bucket exists s3://$(S3_BUCKET)"
27-
@aws s3api head-bucket --bucket $(S3_BUCKET) || (echo "bucket does not exist at s3://$(S3_BUCKET), creating it..." ; aws s3 mb s3://$(S3_BUCKET) --region $(REGION))
28+
@awslocal s3api head-bucket --bucket $(S3_BUCKET) || (echo "bucket does not exist at s3://$(S3_BUCKET), creating it..." ; awslocal s3 mb s3://$(S3_BUCKET) --region $(REGION))
2829

2930
amplify-deploy:
3031
aws cloudformation deploy \

README.md

Lines changed: 73 additions & 127 deletions
Large diffs are not rendered by default.

backend/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ STACKNAME ?= aws-serverless-shopping-cart
44

55
build:
66
@echo "Building template $(TEMPLATE).yaml..."
7-
@sam build -t $(TEMPLATE).yaml
7+
@samlocal build -u -t $(TEMPLATE).yaml --region $(REGION)
88

99
deploy: # s3 bucket still needed for layer
1010
@echo "Deploying stack $(STACKNAME)-$(TEMPLATE)..."
11-
@sam deploy --capabilities CAPABILITY_NAMED_IAM --stack-name $(STACKNAME)-$(TEMPLATE) --s3-bucket $(S3_BUCKET) --parameter-overrides AllowedOrigin=$(ORIGIN) --no-fail-on-empty-changeset
11+
@samlocal deploy --capabilities CAPABILITY_NAMED_IAM --stack-name $(STACKNAME)-$(TEMPLATE) --s3-bucket $(S3_BUCKET) --parameter-overrides AllowedOrigin=$(ORIGIN) --no-fail-on-empty-changeset --region $(REGION)
1212

1313
tests:
1414
py.test -v
1515

1616
delete:
17-
@aws cloudformation delete-stack --stack-name $(STACKNAME)-$(TEMPLATE)
17+
@awslocal cloudformation delete-stack --stack-name $(STACKNAME)-$(TEMPLATE) --region $(REGION)
1818
@echo "Waiting for stack $(STACKNAME)-$(TEMPLATE) to be deleted..."
19-
@aws cloudformation wait stack-delete-complete --stack-name $(STACKNAME)-$(TEMPLATE)
19+
@awslocal cloudformation wait stack-delete-complete --stack-name $(STACKNAME)-$(TEMPLATE) --region $(REGION)
2020

2121
.PHONY: build package deploy delete

backend/product-mock-service/get_product.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"Access-Control-Allow-Origin": os.environ.get("ALLOWED_ORIGIN"),
1414
"Access-Control-Allow-Headers": "Content-Type",
1515
"Access-Control-Allow-Methods": "OPTIONS,POST,GET",
16+
"Access-Control-Allow-Credentials": True,
1617
}
1718

1819

backend/product-mock-service/get_products.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"Access-Control-Allow-Origin": os.environ.get("ALLOWED_ORIGIN"),
1414
"Access-Control-Allow-Headers": "Content-Type",
1515
"Access-Control-Allow-Methods": "OPTIONS,POST,GET",
16+
"Access-Control-Allow-Credentials": True,
1617
}
1718

1819

backend/product-mock.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ Resources:
6060
Properties:
6161
Type: String
6262
Name: /serverless-shopping-cart-demo/products/products-api-url
63-
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod"
63+
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.localhost.localstack.cloud/Prod"
6464

6565

6666
Outputs:
6767
ProductApi:
6868
Description: "API Gateway endpoint URL for Prod stage for Product Mock Service"
69-
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod"
69+
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.localhost.localstack.cloud/Prod"

backend/shoppingcart-service.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ Resources:
426426
Properties:
427427
Type: String
428428
Name: /serverless-shopping-cart-demo/shopping-cart/cart-api-url
429-
Value: !Sub "https://${CartApi}.execute-api.${AWS::Region}.amazonaws.com/Prod"
429+
Value: !Sub "https://${CartApi}.execute-api.${AWS::Region}.localhost.localstack.cloud/Prod"
430430

431431
Outputs:
432432
CartApi:
433433
Description: "API Gateway endpoint URL for Prod stage for Cart Service"
434-
Value: !Sub "https://${CartApi}.execute-api.${AWS::Region}.amazonaws.com/Prod"
434+
Value: !Sub "https://${CartApi}.execute-api.${AWS::Region}.localhost.localstack.cloud/Prod"

frontend/scripts/fetchconfig.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ var fs = require('fs');
44
var args = process.argv.slice(2);
55
var envtype = args[0] ? args[0] : ''
66
var AWS = require('aws-sdk');
7-
var ssm = new AWS.SSM();
7+
var ssm = new AWS.SSM({
8+
endpoint: 'http://localhost:4566',
9+
accessKeyId: 'test',
10+
secretAccessKey: 'test',
11+
region: 'us-east-1',
12+
});
813

914

1015
const query = {
@@ -39,7 +44,7 @@ params
3944
fileName = "./.env." + envtype
4045
}
4146
else {
42-
fileName = "./.env"
47+
fileName = "./.env.local"
4348
}
4449
fs.writeFile(fileName, output.join('\n'), function (err) {
4550
if (err) {

frontend/src/backend/api.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export async function getCart() {
3030
return getHeaders(true).then(
3131
headers => API.get("CartAPI", "/cart", {
3232
headers: headers,
33-
withCredentials: true
3433
}))
3534
}
3635

@@ -42,7 +41,6 @@ export async function postCart(obj, quantity = 1) {
4241
quantity: quantity,
4342
},
4443
headers: headers,
45-
withCredentials: true
4644
})
4745
)
4846
}
@@ -55,7 +53,6 @@ export async function putCart(obj, quantity) {
5553
quantity: quantity,
5654
},
5755
headers: headers,
58-
withCredentials: true
5956
})
6057
)
6158
}
@@ -72,7 +69,6 @@ export async function cartMigrate() {
7269
return getHeaders(true).then(
7370
headers => API.post("CartAPI", "/cart/migrate", {
7471
headers: headers,
75-
withCredentials: true
7672
})
7773
)
7874
}
@@ -81,7 +77,6 @@ export async function cartCheckout() {
8177
return getHeaders(true).then(
8278
headers => API.post("CartAPI", "/cart/checkout", {
8379
headers: headers,
84-
withCredentials: true
8580
})
8681
)
8782
}

0 commit comments

Comments
 (0)