見出し画像

#AWSウェブマガジン Twitter Bot第9回実施メモ

これまで通り、#AWSウェブマガジンのStepに忠実に実施していましたが、SAM CLIのバージョンが異なるからか、少し手順の変更が必要でした。私は少しハマってしまったので、参考までに記載します。

私が実施した日(2022年10月30日)の時点でのSAM CLIのバージョンは1.57.0でした。(#AWSウェブマガジンの記載では1.33.0。記事の日付から2ヶ月ほどしか経ってないのに、かなりアップデートされているんですね。)

$ sam --version
SAM CLI, version 1.57.0

はまりポイント1

バージョン違いのせいか、sam initコマンドの選択肢や順番に違いがありました。(最初のはまりポイント。。。)

最初の選択肢
Which template source would you like to use?

 1 - AWS Quick Start Templates
を選択するのは本文の手順と同じ。

次に順番が変わり、
Choose an AWS Quick Start application template
が聞かれるので
 1 - Hello World Example
を選択します。(順番は違うけど本文と同じ。)

続いて、
Use the most popular runtime and package type? (Python and zip) [y/N]: N
と聞かれるので、ここではNを選択。
(ここでPython and zipの記載に惑わされてyを選択し、私は少しはまってしまいました。自業自得です。。。)

Nを選択してから選択していく項目は本文と同じ(python3.7とzip)です。

続いての
Would you like to enable X-Ray tracing on the function(s) in your application?  [y/N]: N
は謎でしたが、Nを選択で支障はなさそうでした。
以下が全体的な実行結果です。

$ sam init

        SAM CLI now collects telemetry to better understand customer needs.

        You can OPT OUT and disable telemetry collection by setting the
        environment variable SAM_CLI_TELEMETRY=0 in your shell.
        Thanks for your help!

        Learn More: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-telemetry.html


You can preselect a particular runtime or package type when using the `sam init` experience.
Call `sam init --help` to learn more.

Which template source would you like to use?
        1 - AWS Quick Start Templates
        2 - Custom Template Location
Choice: 1

Choose an AWS Quick Start application template
        1 - Hello World Example
        2 - Multi-step workflow
        3 - Serverless API
        4 - Scheduled task
        5 - Standalone function
        6 - Data processing
        7 - Infrastructure event management
        8 - Lambda EFS example
        9 - Machine Learning
Template: 1

Use the most popular runtime and package type? (Python and zip) [y/N]: N

Which runtime would you like to use?
        1 - dotnet6
        2 - dotnet5.0
        3 - dotnetcore3.1
        4 - go1.x
        5 - graalvm.java11 (provided.al2)
        6 - graalvm.java17 (provided.al2)
        7 - java11
        8 - java8.al2
        9 - java8
        10 - nodejs16.x
        11 - nodejs14.x
        12 - nodejs12.x
        13 - python3.9
        14 - python3.8
        15 - python3.7
        16 - ruby2.7
        17 - rust (provided.al2)
Runtime: 15

What package type would you like to use?
        1 - Zip
        2 - Image
Package type: 1

Based on your selections, the only dependency manager available is pip.
We will proceed copying the template using pip.

Would you like to enable X-Ray tracing on the function(sin your application?  [y/N]: N

Project name [sam-app]: aws-drill-reminder-bot

Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment)

    -----------------------
    Generating application:
    -----------------------
    Name: aws-drill-reminder-bot
    Runtime: python3.7
    Architectures: x86_64
    Dependency Manager: pip
    Application Template: hello-world
    Output Directory: .
    
    Next steps can be found in the README file at ./aws-drill-reminder-bot/README.md
        

    Commands you can use next
    =========================
    [*] Create pipeline: cd aws-drill-reminder-bot && sam pipeline init --bootstrap
    [*] Validate SAM template: sam validate
    [*] Test Function in the Cloud: sam sync --stack-name {stack-name} --watch
    

SAM CLI update available (1.61.0); (1.57.0 installed)
To download: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html

はまりポイント2

二つ目のはまりポイントはsam buildコマンドの実行時です。本文内にはtwitter-bot-send-reminder-functionディレクトリで実行と記載がありましたが、なぜかそのディレクトリで実行してもうまくいかず。。。
twitter-bot-send-reminder-functionディレクトリで実行すると、「template.yaml」が見つからないというエラーが出ていたので、yamlファイルが保存されている上位フォルダ(aws-drill-reminder-botディレクトリ)に移動して実行したところ、ビルドとデプロイまでうまく行きました。

結果

出来上がったLambda関数名が本文の記載と違うところがありました。

 本文:aws-drill-reminder-bot-SendReminderFunction
 私の結果:twitter-bot-send-reminder-function

が、テストなどは正常に実行できているのでこれで問題ないのかなと思います。引き続き第10回も手順に忠実に進めていきたいと思います。

この記事が気に入ったらサポートをしてみませんか?