AWS Serverless Meetup - AppSync
AppSync๋ฅผ ํ์ฉํ ๋ฆฌ์ผํ์ ์๋ฒ๋ฆฌ์ค ์ํคํ ์ณ
Speaker : ๊นํ์ฐ https://dev.classmethod.jp/author/kim-taewoo/
์๋ฒ๋ฆฌ์ค ์ํคํ
์ณ ํน์ง
๊ด๋ฆฌํ ์๋ฒ๊ฐ ์๋ค (NoOps)
ํ์ํ ๋๋ง๋ค ํ์ํ ๋ถ๋ถ๋ง ํ์ํ ๋งํผ ์ฌ์ฉํ ์ ์๋ค
์ปดํจํ ๋ฆฌ์์ค๋
Lambda
orFargate
Lambda์ ๊ฒฝ์ฐ ์์ฒด์ ์ผ๋ก connection์ ์ ์งํ ์ ์๋ค!
Fargate
: a serverless compute engine for containers that works with both Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS)
Lambda
: a compute service that lets you run code without provisioning or managing servers
์๋ฒ๋ฆฌ์ค ์ํคํ
์ณ๋ ๋ฆฌ์ผํ์ ๊ธฐ๋ฅ ๋ง๋ค ์ ์๋ค
How?
: by using API Gateway websocket
or Pubsub
API Gateway ์์ websocket์ ์ง์ํจ
Connection ๊ธฐ๋ฐ์ solution์ ์๋์ง๋ง PubSub Solution๋ ๊ฐ๋ฅํ๊ธฐ๋ ํจ
It's possible, but
Front-end ์ Back-end ๊ฐ์ ํต์ ์ ์ํ Data structure ์ ์ ํด์ผํจ
Data ์ฃผ๊ณ ๋ฐ์ ๋์ Validation ํ์
Front & Back ์์ธก์์ ๊ฐ๋ฐ์ด ์ด๋ฃจ์ด์ ธ์ผ ํจ
Back-end ์ ๊ฒฝ์จ์ผ ํ ๊ฒ์ด ๋ง์
High availality
reliability
scalability
---> AppSync ๋ฅผ ์ฌ์ฉํ์ฌ ๊ทน๋ณต ๊ฐ๋ฅํ๋ค
AWS AppSync
Strong typing์ผ๋ก ์ธํด Validation ์ฝ๋ ๊ฑฐ์ ์๋ต ๊ฐ๋ฅ (
GraphQL
์ ํน์ง )Real-time ํต์ ์ ์ํด์ Back-end์์ ํด์ผํ ๊ฒ์
Subscription
์ ์คํค๋ง์ ์ ์ธํด๋๋ ๊ฒ ๋ฐ์ ์์Schema์ ํด๋น ๊ธฐ๋ฅ์ ์ธ๊ฑฐ๋ผ๊ณ ๋ช ์๋ง ํด๋์ผ๋ฉด ๋๋ค!
Frontend ์ธก์์๋
AppSync SDK
๋Amplify
๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐ๋จํ Subscription์ด ๊ฐ๋ฅํ๋ค!
Pros of AppSync
GraphQL์์ ๋น ๋ฅธ prototype ์์ฑ ๋ฐ ๊ฐ๋ฐ
์ค์๊ฐ ํ์ mobile & web app
์ํํ ์คํ๋ผ์ธ ์์
์์ ํ ๋ฐ์ดํฐ ์ก์ธ์ค
์ฌ๋ฌ ์๋ณธ์ ๋ฐ์ดํฐ ๊ฒฐํฉ
๋ฐ์ดํฐ ์ถฉ๋ ๊ฐ์ง ๋ฐ ์ถฉ๋ ํด๊ฒฐ
Real time Data ํต์ ์ ์ํ AppSync Architecture

Serverless Streaming Architecture

์ ํ์ ์ธ ์๋ฒ๋ฆฌ์ค ๋ฐ์ดํฐ ์คํธ๋ฆฌ๋ฐ ํจํด ์ค ํ๋
Eventual Consistency
orEvent-driven processing
๋ฑ์ ์ฒ๋ฆฌํ๊ธฐ์ ์ ํฉScalable & Reliable & Cost Effective
๋ณ๋ ฌ๋๊ฐ ๋งค์ฐ ๋์ ์์ ์ ๋ํด์๋ ์ค์๊ฐ์ฑ์ ๋ณด์ฅํ์ง ์์ผ๋ฏ๋ก
Kinesis DS
๊ฐ ์ข์DynamoDB Streams
๋ ์ต๋ 24์๊ฐ์ ๋ฐ์ดํฐ ๋ณด์กด, ๋ฐ์ดํฐ ๋ณ๊ฒฝ์ ์๋ฒ์ด ๋ณด์ฆ ๊ฐ๋ฅํ ์๋น์ค

RDS๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ์๋ ์คํธ๋ฆฌ๋ฐ ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํจ
Kinesis Data Streams ๋ ์ค๋๋ฅผ ์ ์ ํ ์ปจํธ๋กค ํ ์ ์์ด์ผํจ
์ค๋
: ์คํธ๋ฆผ์์ ๊ณ ์ ํ๊ฒ ์๋ณ๋๋ ๋ฐ์ดํฐ ๋ ์ฝ๋ ์ํ์ค
Kinesis Data Streams ์์ ๊ตณ์ด Lamda ๋ก ์ฐ๊ณํ ํ์๋ ์์
but, AppSync ์ฐ๊ณ๋ฅผ ์ํ ์ฉ๋๋ก๋ Lambda ๋ก ์ถฉ๋ถํ๋ค!
DB(MySQL, PostgreSQL etc.) ์ผ๋ก ๋ถํฐ ์ง์ Lambda ๋ฅผ ์คํ์ํค๋ ๋ฐฉ๋ฒ๋ ์กด์ฌํจ

SQL ์์ Lambda ๋ก ์ฐ๊ณ๋๋ ํจํด
Kinesis ์์ Lambda ๋ก ์ฐ๊ณ๋๋ ํจํด
API Gateway ์์ Lambda ๋ก ์ฐ๊ณ๋๋ ํจํด
CloudWatch Alarms ์์ Lambda ๋ก ์ฐ๊ณ๋๋ ํจํด
CloudWatch Events ์์ Lambda ๋ก ์ฐ๊ณ๋๋ ํจํด
... and a lot more!
Lambda๋ก ๋ถ๋ฌ์จ ํ

Demo Project Architecture

AppSync๋ฅผ Subscription์ ์ฉ๋๋ก๋ง ์ธ๊ฑฐ๋ผ๋ฉด ๊ตณ์ด Appsync์ฉ DB ์ฐ๊ฒฐํ ํ์ ์์ด DynamicDB Stream๋ฅผ ์ฐ๋ฉด ๋จ!
Microservice
API Gateway
->Lambda
->DynamoDB
๊ตฌ์ฑ๊ฐ์ฅ ๋ง์ด ์ฐ์ด๋ Serverless Architecture API back-end pattern
๊ฐ๋จํ input form์ ์ฒ๋ฆฌํ๋ ์๋น์ค๋ฅผ ์๋ก ๋ค์ด ๋ฐ๋ชจ์ฝ๋ ์์ฑ
AWS AppSync
AppSync ๊ตฌ์ถ ์์๋ Serverless Framework๋ฅผ ์ถ์ฒ
Subscription ์ Schema์ ์ถ๊ฐํ๋ ๊ฒ๋ง์ผ๋ก๋ client ์ธก์์ Subscription์ด ๊ฐ
๋ฐฑ์ค๋ ์์ ๋ฐ์ x
ํ์ํ ๊ธฐ๋ฅ์ mutation, subscription ๋ฟ์ด์ง๋ง, query๋ฅผ schema์ ๋ฑ๋กํ์ง ์์ผ๋ฉด
GraphQL schema error
๊ฐ ๋๋ฏ๋ก ๊ฐ๋จํ query ํ๋๋ฅผ ์ถ๊ฐํด์ผํจgetOrder ์์ฑ
Mutation ํ๊ธฐ ์ํด์์ DynamoDB ๋ฅผ Data source๋ก์ ์์ฑํ๊ณ ,
TTL (Time-To-Live)
๋ฅผ ์ค์ ํ๋คexpiresAt์ AWSTimestamp ํ์ ์ผ๋ก ์ ์ธํ๋ค
DynamoDB Streams -> Lambda
DynamoDB Streams ๋ ์ต๋ 24 ์๊ฐ์ ๋ฐ์ดํฐ ๋ณด์กด, ๋ฐ์ดํฐ ๋ณ๊ฒฝ์ ์๋ฒ์ด ๋ณด์ฆ๊ฐ๋ฅํ ์๋น์ค
but, Realtime Service ์์๋ ์ต๋ 24 ์๊ฐ์ ๋ฐ์ดํฐ ๋ณด์กด์ ๋ณ ์๋ฏธ๊ฐ ์๊ธด ํจ
๋ณ๋ ฌ๋๋ฅผ ๋์ด๋ ค๋ฉด ๋ฐฐ์น ์ฌ์ด์ฆ๋ฅผ ์กฐ์ ํ๋ฉด ๋จ!
Lambda -> Appsync
์ค์๋น์ค์ฉ์ผ๋ก releaase ๋ AppSync Client SDK ๋ JavaScript version ๋ฟ์ด๋ฏ๋ก Amplify๋ฅผ ๊ถ์ฅ
AppSync Clinet SDK๋ฅผ Lambda ์์์ ๋์ฅ์ํค๊ธฐ ์ํด ์ฃผ์ํ ์
ismorphic-fetch
๋ฅผ import ํด์ผ ํจdisableOffline
์ true๋ก ๋ณ๊ฒฝํด์ผ ํจ
AppSync๋ก ์ด๋ฐ๊ฒ๋ ๋์ง ์์๊น?
State Management by AppSync
Serverless Architecture pattern ์์๋ Rich Client๋ฅผ ์งํฅ
but, Front-end code์ complexity๊ฐ ์ง๋์น๊ฒ ์ฆ๊ฐํ๋ ๊ฒ์ ์ข์ง์์
Front-end ์ code complexity ์ ์๋น ๋ถ๋ถ์ ๊ธฐ์ฌํ๋ State Management
State Mangement ๋ฅผ ๋์ ํ๊ธฐ ์ํ code์ complexity๋ฅผ
AppSync Subscription
์ ์์กดํด์ ํด๊ฒฐํ ์๋ ์์ง ์์๊น?but, Network์ ์๋/์์ ์ฑ ๋ฑ์ ์์กด์ฑ์ด ์๊น
๊ทธ๋ฌ๋ 5G ์๋์๋ ํฐ ๋ฌธ์ ์์ง ์์๊น?
+
GraphQL์ด ๋๋ฆฐ ์ด์
http ๋ผ์
resolver ๋๋ฌธ
์ด ๋ถ๋ถ์ ํด๊ฒฐ ๊ฐ๋ฅ
โ
๋น๊ทผ๋ง์ผ๋ GraphQL ์ด๋ค๊ณ ํจ! ์๋ฅ์๋ฅ
-> admin ๋ง๋ค ๋ ์ข๋ค๊ณ ํจ! ํ๋ฒ์ ๋ชจ๋ ๋ฐ์ดํฐ ๋ฐ์์ฌ ์ ์์ด์!
-> GraphQL ์ฐ๋ฉด node.js์์ data๋ฅผ ์ ์ฅํ๋ ๋ฐฉ์์ด ๋น ๋ฅผ ์๊ฐ ์๋ ๋ฐฉ์์!
๋น๊ทผ๋ง์ผ์ด gRPC ์ฐ๋ ์ด์ == ์๋๊ฐ ์์ฒญ ๋น ๋ฆ
+
Looked up after the meetup
gRPC
image-20200307032408544 gRPC (gRPC Remote Procedure Calls) is an open source remote procedure call (RPC) system initially developed at Google in 2015
In gRPC, a client application can directly call a method on a server application on a different machine as if it were a local object, making it easier for you to create distributed applications and services.
As in many RPC systems, gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters and return types.
On the server side, the server implements this interface and runs a gRPC server to handle client calls.
On the client side, the client has a stub (referred to as just a client in some languages) that provides the same methods as the server.
apollo gateway
image-20200307032923930 Apollo is an implementation of
GraphQL
designed for the needs of product engineering teams building modern, data-driven applications.It encourages an
agile
, incremental approach and takes special care to avoid requiring any changes to existing APIs and services.Apollo puts particular emphasis on tooling and workflows.
Apollo is best used as a new layer in your stack that sits between your services and your applications.
It's a combination of open source components, commercial extensions, and cloud services.
3factor app
3factor app is an architecture pattern for modern full-stack apps.
Today, it is possible to build apps that have high feature velocity and scalability from the get go.
An architecture pattern which is composed of 3 factors:
Realtime GraphQL
Reliable eventing
Async serverless
Last updated
Was this helpful?