LoginSignup
1
0

More than 1 year has passed since last update.

AWS Lambda 実践ガイド 第2版でつまずいたところまとめ

Last updated at Posted at 2022-05-08

AWS Lambda 実践入門 第2版でつまずいたところを忘備録的にまとめておく。

1. 書籍のとおりにカスタムドメインのマッピングをやるとアクセスに失敗

図6-102のとおりにLambda関数をカスタムドメインにマッピングすると6-9-5が以下のエラーをCloudWatchで吐くようになって失敗する。

The IAM role configured on the integration or API Gateway doesn't have permissions to call the integration. Check the permissions and try again.

原因は、図6-102で「パス(オプション)」を設定しているため。ここに文字列を指定すると、関数を呼び出すためのURLで関数へのルートの前にこのパスが付与されてしまうため。つまり、図6-102のとおりに進めると以下のようなURLを生成してしまうことになる。

https://api.aws-bookexample.com/userregistFunction/userregistFunction

これだと、困るので図6-102で「パス(オプション)」を設定しないようにすればOK。

2. 7-6 sqs.get_queue_by_nameを実行する権限不足

Lambda関数SendqueueFunctionのポリシーとしてSQSSendMessagePolicyを割り当てているが、このポリシーだけでは、関数内で実行されるget_queue_by_nameが必要とするGetQueueUrlの権限足りていないため、以下のエラーが発生する。

[ERROR] QueueDoesNotExist: An error occurred (AWS.SimpleQueueService.NonExistentQueue) when calling the GetQueueUrl operation: The specified queue does not exist or you do not have access to it.

なので、手動でポリシーを作るようにすればOK。

  # 1. S3バケットとイベントの結び付け
  # 処理するLambda関数
  SendqueueFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: send_queue
      Handler: app.lambda_handler
      Runtime: python3.9
      Policies:
        # DynamoDBテーブルへのCURD権限
        - DynamoDBCrudPolicy:
            TableName: !Ref MailTable
        # キューへの送信権限
        # - SQSSendMessagePolicy:
        #     QueueName: !GetAtt SendQueue.QueueName
        - Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Action:
                - sqs:SendMessage*
                - sqs:GetQueueUrl*
              Resource: !GetAtt SendQueue.Arn

3. リスト7-5の変更箇所漏れ

table = dynamodb.Table('mailaddress')

table = dynamodb.Table(os.environ['MAILTABLE'])
1
0
2

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
1
0