Infra/AWS

[번역] AWS SAM Template Concepts

하우아유두잉 2019. 8. 30. 13:14

 

원문

 

 

AWS SAM 사용하여 Serverless 어플리케이션을 만들때, 목표는 Serverless 어플리케이션의 구조를 표현하는 AWS SAM 파일을 작성하는 것이다.

 

AWS SAM 템플릿 파일은 YAML과 JSON으로 구성되어지며  AWS Serverless Model Specification 에서 확인 할 수 있다. Serverless 어플리케이션을 이루는 모든 AWS 리소스들의 선언을 위한 템플릿으로 사용한다.

 

AWS SAM 템플릿은 AWS CloudFormation 템플릿의 확장이다. 그 말은, AWS CloudFormation 템플릿에서 선언할 수 있는 어떤 리소스들도 AWS SAM 템플릿에서 또한 선언 할 수 있다. 추가적으로, AWS SAM으로부터 제공되는 추가적인 리소스 타입들도  Serverless 어플리케이션의 일부 구성요서의 바로가기로써 사용 할 수 있다.(예를들면, 그 리소스는 Declaring Serverless Resources 에 기술되어있다.)

 

AWS CloudFormation 템플릿의 소개를 위해선, Learn Template Basics 를 보라.

 

AWS SAM 템플릿 명세에 대한 정보는, AWS Serverless Application Model Specification 를 보라.

 

앞으로의 섹션에서는 AWS SAM 템플릿 파일에서 선언 될 수 있는 AWS 리소스의 타입들을 설명한다.

 

주제

 

 - Serverless 리소스 선언

 - AWS CloudFormation 리소스 선언

 - 중첩된 어플리케이션

 - API Gateway API들의 접근 제어

 

예제

 

아래 예제인 AWS SAM 탬플릿은 하나의 Lambda 함수와 하나의 API Gateway endpoint의 구성을 기술한다.

Transform: 'AWS::Serverless-2016-10-31'

Resources:



  ThumbnailFunction:

    # This resource creates a Lambda function.

    Type: 'AWS::Serverless::Function'

    

    Properties:

      

      # This function uses the Nodejs v8.10 runtime.

      Runtime: nodejs8.10

        

      # This is the Lambda function's handler.

      Handler: index.handler

      

      # The location of the Lambda function code.

      CodeUri: ./src

      

      # Event sources to attach to this function. In this case, we are attaching

      # one API Gateway endpoint to the Lambda function. The function is

      # called when a HTTP request is made to the API Gateway endpoint.

      Events:



        ThumbnailApi:

            # Define an API Gateway endpoint that responds to HTTP GET at /thumbnail

            Type: Api

            Properties:

                Path: /thumbnail

                Method: GET