Instruction
Do not communicate directly with DynamoDB from your Javascript code. Instead, you will need to create an API that accepts requests from your web app and communicates with the database.
Service
Lambda
Language
Python
1. Lambda 생성
- Enable Function URL : a public url that you can invoke your lambda functions through
Auth type - 'NONE' it means anybody can call this API so.... - check Configure course : which stands for cross originn resource sharing and with that we will only white list our own domain. that web url is the the whitelist = only url that will be able to fetch data from my api
2. Lambda function URL 확인
3. Configuration 들어가서 Timeout 늘리기
4. 코드 작성
import json
import boto3
db = boto3.resource('dynamodb')
tb = db.Table('cloudresume-test')
def lambda_handler(event, context):
# TODO implement
response = tb.get_item(
Key = {
'id':'1' #pk
}
)
views = response['Item']['views']
views = views+1
print(views)
response = tb.put_item(
Item={
'id':'1', #pk
'views':views
}
)
return views
5. Lambda 에 Dynamo DB 접근 permission 주기
6. Next Step
js 와 연동하여 방문자 수 확인
'[AWS] CloudResumeChallenge' 카테고리의 다른 글
[Step 15] CICD(FrontEnd) - Github action (0) | 2024.04.08 |
---|---|
[STEP 7] Javascript (0) | 2024.04.07 |
STEP 8 Database (0) | 2024.03.24 |
STEP 6 DNS (0) | 2024.03.23 |
STEP 5 HTTPS (0) | 2024.03.23 |