0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

サーバーデプロイツールの調査

Posted at

※ Hello world のFastAPIをデプロイ(API Gateway + Lambda)して比較する。 

  • Serverless Framework V.4 と AWS SAM は、サーバーレス用CFnフレームワーク
    • API GatewayとLambdaのリソースをまとめて記述できる構文
  • CDK は、CFnテンプレートを json, yaml ではなく、プログラミング言語で記述できるもの
    • プログラミング言語であることだけでなく、よりコンポーネント化した記述ができる
    • 複雑度、規模が大きくなればなるほど有効
    • 権限の設定の記述が楽
Serverless Framework V.4 AWS SAM AWS CDK
コスト サーバーレス・フレームワークCLI V.4+は無料だが、年間200万ドル以上の収入を得る組織は有料のサブスクリプションが必要 無償 無償
デプロイ ※CLIベース serverless deploy sam build, sam deploy --guided cdk synth, cdk deploy

各ツールの立ち位置

image.png

Serverless Framework V.4

※ プラグイン
※外部ライブラリ

serverless.yml

service: fastapi-apigateway-lambda
frameworkVersion: '4'

provider:
  name: aws
  runtime: python3.11

functions:
  api:
    handler: app.handler
    events:
      - httpApi: '*'

plugins:
  - serverless-python-requirements

AWS SAM

※ Transform: AWS::Serverless-2016-10-31, AWS::Serverless::Function
※ CFnの場合は、Former2で生成したもの比較してみる AWS::Lambda::Function + AWS::ApiGatewayV2::Api → AWS::Serverless::Function
※外部ライブラリ

template.yml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  sam-app

  Sample SAM Template for sam-app

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3
    MemorySize: 128

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      CodeUri: hello_world/
      Handler: app.handler
      Runtime: python3.9
      Architectures:
        - x86_64
      Events:
        HelloWorld:
          Type: HttpApi # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
              Path: /
              Method: ANY


Outputs:
  # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
  # Find out more about other implicit resources you can reference within SAM
  # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
  # HelloWorldApi:
  #   Description: "API Gateway endpoint URL for Prod stage for Hello World function"
  #   Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
  HelloWorldFunction:
    Description: "Hello World Lambda Function ARN"
    Value: !GetAtt HelloWorldFunction.Arn
  HelloWorldFunctionIamRole:
    Description: "Implicit IAM Role created for Hello World function"
    Value: !GetAtt HelloWorldFunctionRole.Arn

AWS CDK

AWS CDK 概要 (Basic #1)【AWS Black Belt】
https://pages.awscloud.com/rs/112-TZM-766/images/AWS-Black-Belt_2023_AWS-CDK-Basic-1-Overview_0731_v1.pdf

Construct
synthesize(合成する)

CDKの起源

  • 複数チームが開発、デプロイしやすくしたい
  • 繰り返し複雑なものを使うのを避けたい
  • プロラム言語の方が表現しやすい

サンプル

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?