LoginSignup
0
0

More than 1 year has passed since last update.

re:Invent 2022 サーバーレス関連の新サービス、アップデートまとめ

Last updated at Posted at 2023-01-06

re:Invent 2022で発表されたサーバーレス関連のアップデートをまとめました

AWS Lambda SnapStart

  • Lambda ファンクションのコールドスタート時のレイテンシを大幅に短縮する新機能
  • Corretto ( ランタイムのファンクションをサポートし、最大 90% のレイテンシを削減
  • Firecracker のスナップショット機能と、その他いくつかの機能改善によって実現。実行環境
    の初期化終了時点のスナップショットを使うことで、初期化時間を削減
  • 東京を始めはじめ 9 リージョンで一般利用開始に

試してみました

上記のブログの通り、springboot2のサンプルアプリケーションを使用することで簡単に試すことができます。

事前に以下のインストールが必要です。
※インストールが面倒な人(主に自分)のために、Dockerイメージ作成しておきました
※docker-composeとプログラムも一緒にしてGitHubにアップしておきました

  • AWS CLI install guide
    1. curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
    2. unzip awscliv2.zip
    3. sudo ./aws/install
    4. aws --version -> aws-cli/2.9.5 Python/3.9.11 Linux/5.10.16.3-microsoft-standard-WSL2 exe/x86_64.ubuntu.20 prompt/off
  • SAM CLI install guide
    1. download
    2. sha256sum aws-sam-cli-linux-x86_64.zip
    3. unzip aws-sam-cli-linux-x86_64.zip -d sam-installation
    4. sudo ./sam-installation/install
    5. sam --version -> SAM CLI, version 1.68.0
  • Gradle install guide
    1. sudo apt-get install gradle -y
    2. gradle --version -> Gradle 4.4.1

デプロイ

  • リポジトリをクローンしましょう
    git clone https://github.com/awslabs/aws-serverless-java-container.git

  • cd samples/springboot2/pet-store

  • sam build

  • sam deploy --guided

      Configuring SAM deploy
      ======================
    
      Looking for config file [samconfig.toml] :  Not found
    
      Setting default arguments for 'sam deploy'
      =========================================
      Stack Name [sam-app]: snapstart-sample
      AWS Region [ap-northeast-1]:
      #Shows you resources changes to be deployed and require a 'Y' to initiate deploy
      Confirm changes before deploy [y/N]:
      #SAM needs permission to be able to create roles to connect to the resources in your template
      Allow SAM CLI IAM role creation [Y/n]:
      #Preserves the state of previously provisioned resources when an operation fails
      Disable rollback [y/N]:
      PetStoreFunction may not have authorization defined, Is this okay? [y/N]: y
      Save arguments to configuration file [Y/n]:
      SAM configuration file [samconfig.toml]:
      SAM configuration environment [default]:
    

色々と聞かれますが、Stack NameとPetStoreFunction may not have authorization defined, Is this okay? [y/N]: y
を回答すればデプロイできます。

  • SnapStartなしの状態でデプロイされました
    image.png

  • デプロイ出来たらアクセスしてみます
    curl https://iu7kswmw1c.execute-api.ap-northeast-1.amazonaws.com/pets

Lambdaのログを見ると、Init Duration: 6497.82 ms となっていて、約6秒ほど初期化処理に時間がかかっていることがわかります。

	REPORT RequestId: e94e20a2-01eb-43ad-8b08-b7c80fbba11d Duration: 149.44 ms Billed Duration: 150 ms Memory Size: 1512 MB Max Memory Used: 184 MB Init Duration: 6497.82 ms
  • SnapStartの有効化
    • template.ymlに SnapStart の設定を追加します
    • AutoPublishAlias: live も追加して、Lambda関数のバージョンが作成されるようにしておきましょう。
      ※SnapStartを使用するにはバージョンの作成が必要です
template.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Example Pet Store API written with SpringBoot with the aws-serverless-java-container library

Globals:
  Api:
    # API Gateway regional endpoints
    EndpointConfiguration: REGIONAL

Resources:
  PetStoreFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: com.amazonaws.serverless.sample.springboot2.StreamLambdaHandler::handleRequest
      Runtime: java11
      CodeUri: .
      MemorySize: 1512
      Policies: AWSLambdaBasicExecutionRole
      Timeout: 60
      SnapStart:
        ApplyOn: PublishedVersions
      AutoPublishAlias: live
      Events:
        HttpApiEvent:
          Type: HttpApi
          Properties:
            TimeoutInMillis: 20000
            PayloadFormatVersion: '1.0'

Outputs:
  SpringBootPetStoreApi:
    Description: URL for application
    Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/pets'
    Export:
      Name: SpringBootPetStoreApi
  • 再度、ビルド&デプロイします
    sam build && sam deploy

  • デプロイ出来たらアクセスしてみます
    curl https://iu7kswmw1c.execute-api.ap-northeast-1.amazonaws.com/pets

Lambdaのログを見ると、Restore Duration: 287.81 ms という表記がありました。Initの処理はデプロイ時にスナップショットがとられていて、復元時間+実行時間ということになることがわかりますね!
時間も6秒から287ミリ秒まで短縮しました!

    REPORT RequestId: 007fe8a3-163f-4eec-a1e2-10911b6e54d4 Duration: 224.65 ms Billed Duration: 409 ms Memory Size: 1512 MB Max Memory Used: 150 MB Restore Duration: 287.81 ms

以上

AWS Step Functions Distribution Map

  • 従来 40 並列処理が上限だったが、最大 10,000並列まで対応可能な Distribution Map が利用可能に。
  • ユースケース
    • Amazon S3 に格納された数百万のログデータや画像データを並列反復処理する等
  • Map に渡す入力情報を S3 からシームレスに読み込み可能
  • AWS Lambda など、処理をする側が対応可能な並列度には注意。
    • Step Function は対応可能な並列度でも、処理側が OK か要確認
  • 東京をはじめ 10 のリージョンで利用可能

Amazon EventBridge Pipes

  • イベントドリブンなアプリケーション構築時に、発行側と受取側同士の連携を実現する、シンプルで信頼性の高い方法を提供。
  • つなぎ込むためのコード開発の手間を最小化
  • イベントソース
    • DynamoDB
    • Kinesis
    • MSK(自己管理のKafkaも含む)
    • SQS
    • MQ(ActiveMQ/RabbitMQ)
  • イベントターゲット
    • 15 種類の EventBridge ターゲット
    • Lambda
    • API Gateway
    • SNS
    • SQS
    • Step Functions
  • 一般的な HTTPS エンドポイント
  • Lambda や Step Functions などによるデータ加工・変換も
  • 一般利用開始。ハイデラバード、チューリッヒを除くすべての AWS 商用リージョン

re:Capのご案内

2023/1/7(土) JAWS-UG横浜 #51 AWS re:Invent 2022 Recap Serverlessでキャッチアップを行いますのでぜひぜひご参加ください!
SnapStartのハンズオンやるかも。

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