Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Amazon API Gateway Study Workshop

37108
June 18, 2020

Amazon API Gateway Study Workshop

37108

June 18, 2020
Tweet

More Decks by 37108

Other Decks in Technology

Transcript

  1. API Gateway is a fully managed service that makes it

    easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. https://go.aws/30gXhc7
  2. Resource / Method / ANY /members GET /members/{id} GET POST

    /parts/ GET method req… method req… method req… method req…
  3. Request API Flow /members GET method req integ req integ

    res method res /members/{id} POST method req integ req integ res method res
  4. Integration Types AWS Services Directly calls AWS services and fire

    the specify action. HTTP Connects via internet to a HTTP endpoint. Lambda Connects via proxy or direct integration to a Lambda. Mock Directly calls AWS services and fire the specify action. VPC Endpoint Connects to a VPC Endpoint. Access through a NLB.
  5. Lambda Resource Policy { “version”: “2012-10-17”, “statement”: { “Effect” :

    “Allow”, “Principle”: “apigateway.amazonaws.com”, “Action” : “lambda:InvokeFunction”, “Resource” : “arn:aws:lambda:…:function_name”, “Condition”: { “ArnLike”: { “AWS:SourceArn”: “arn:aws:execute-api:…:id/stage/method/resource” } } } }
  6. Lambda Resource Policy Allow every stages, resources { “version”: “2012-10-17”,

    “statement”: { “Effect” : “Allow”, “Principle”: “apigateway.amazonaws.com”, “Action” : “lambda:InvokeFunction”, “Resource” : “arn:aws:lambda:…:function_name”, “Condition”: { “ArnLike”: { “AWS:SourceArn”: “arn:aws:execute-api:…:id ” } } } }
  7. Lambda Resource Policy Allow every lambda authorizer { “version”: “2012-10-17”,

    “statement”: { “Effect” : “Allow”, “Principle”: “apigateway.amazonaws.com”, “Action” : “lambda:InvokeFunction”, “Resource” : “arn:aws:lambda:…:function_name”, “Condition”: { “ArnLike”: { “AWS:SourceArn”: “arn:aws:execute-api:…:id/authorizers ” } } } }
  8. Mapping Template before after { “FirstName”: “Alexander”, “LastName” : “Pierce”,

    “phone” : “000-0000-0000”, “address” : “xxx”, “favorite” : “eggplant” } { “Name” : “Alexander Pierce”, “phone” : “000-0000-0000”, “address” : “xxx”, “favorite”: “beef” }
  9. Request API Flow /members GET method req integ req integ

    res method res /members/{id} POST method req integ req integ res method res
  10. Request API Flow /members GET method req integ req integ

    res method res /members/{id} POST method req integ req integ res method res v1 v2
  11. Endpoint Type Edge Regional VPC Routing from CloudFront Distribution. Routing

    directly to region. Can combine with CloudFront. Routing from VPC Private Link. No public endpoint.
  12. Release it ! 1. Design API 2. Choose Protocol and

    Endpoint 3. Define Resources and Methods 4. Integrate Backend 5. Create Stage and deploy
  13. Protect API Open IAM Lambda Authorizer Cognito Authorizer No AuthN

    and AuthZ. API is Public and everybody can access. Use IAM credentials for grant access. Connect Cognito User Pool for grant access. Validate bearer token via Lambda for grant access.
  14. Lambda Authorizer input output eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXV CJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwib mFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNT E2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fw pMeJf36POk6yJV_adQssw5c {

    “principalId”: “AlexanderPierce”, “policyDocument”: { “Version”: “2012-10-17”, “Statement”: [ { “Action”: “execute-api:Invoke”, “Effect”: “Allow”, “Resource”: “………” } ] } }
  15. Throttling 10,000 reqs/sec Account: Account: API 1 API 1 method

    method method method /members GET /pets GET /parta GET
  16. Monitoring/Tracing Metrics by APIs, Stages. API Calls Latency 4xxx /

    5xx Error Cache HitCount Execution logs error/info level full req/res logs Access logs specify log destination customize log format Integrate X-Ray and trace request. Just enable tracing, analyze requests end to end.
  17. HTTP API Faster reduces up to 60% in latency. Lower

    Cost Frugality is one of the Leadership Principles. Overall, at least 71% lower cost. More Simple JWT Authorizer Features are specified, but this makes more simple. No need to write code for validating JWT.
  18. Integrations / /members GET /members/ba GET /members/ba POST /parts GET

    Invoke function private integration private integration get https://xxx.example.com
  19. stages / deploy Deploy 2020/06/18 Deploy 2020/06/05 $default v1 v2

    https://xxx.execute-api…/… https://xxx.execute-api…/v1/… https://xxx.execute-api…/v2/…