2016-08-08 8 views
0

SNSトピックによって引き起こされる電子メール送信ラムダ機能を、クラウド情報内にセットアップしようとしていますが、何らかの理由でそれが機能していません。ラムダ& snsが起動し、すべてが順番になっているように見えるが、すべての依存関係/アクセス許可をチェックしたが、トピックに公開すると何も起こりません。ラムダコンソールでラムダを手動でテストすると、完璧に動作します。 AWS::Lambda::PermissionリソースタイプのSNSトピックがラムダをトリガーしない

Cloudformation

"Resources": { 
    "CloudformationEventHandlerLambdaExecutionRole": { 
     "Type": "AWS::IAM::Role", 
     "Properties": { 
     "Path": "/", 
     "Policies": [ 
      { 
      "PolicyName": "CloudformationTrigger", 
      "PolicyDocument": { 
       "Statement": [ 
       { 
        "Effect": "Allow", 
        "Action": [ 
         "ses:*" 
        ], 
        "Resource": [ 
        "arn:aws:ses:*" 
        ] 
       } 
       ] 
      } 
      } 
     ], 
     "AssumeRolePolicyDocument": { 
      "Statement": [ 
      { 
       "Action": [ 
       "sts:AssumeRole" 
       ], 
       "Effect": "Allow", 
       "Principal": { 
       "Service": [ 
        "lambda.amazonaws.com" 
       ] 
       } 
      } 
      ] 
     } 
     } 
    }, 
    "CloudformationEventHandlerLambdaFunction": { 
     "Type": "AWS::Lambda::Function", 
     "Properties": { 
     "Handler": "lambda_function.lambda_handler", 
     "Role": { 
      "Fn::GetAtt": [ 
      "CloudformationEventHandlerLambdaExecutionRole", 
      "Arn" 
      ] 
     }, 
     "Code": { 
      "S3Bucket": { 
      "Ref": "Bucket" 
      }, 
      "S3Key": "CloudformationEventHandler.zip" 
     }, 
     "Runtime": "python2.7", 
     "Timeout": "30" 
     }, 
     "DependsOn": [ 
     "CloudformationEventHandlerLambdaExecutionRole" 
     ] 
    }, 
    "CloudformationEventHandlerLambdaInvokePermission": { 
     "Type": "AWS::Lambda::Permission", 
     "Properties": { 
     "Action": "lambda:InvokeFunction", 
     "SourceAccount": { 
      "Ref": "AWS::AccountId" 
     }, 
     "Principal": "sns.amazonaws.com", 
     "SourceArn": { 
      "Ref": "CloudformationTopic" 
     }, 
     "FunctionName": { 
      "Fn::GetAtt": [ 
      "CloudformationEventHandlerLambdaFunction", 
      "Arn" 
      ] 
     } 
     } 
    }, 
    "CloudformationTopic": { 
     "Type": "AWS::SNS::Topic", 
     "Properties": { 
      "DisplayName": "CloudformationIngestTopic", 
      "Subscription": [ 
       { 
        "Endpoint": { 
         "Fn::GetAtt": [ 
          "CloudformationEventHandlerLambdaFunction", 
          "Arn" 
         ] 
        }, 
        "Protocol": "lambda" 
       } 
      ] 
     }, 
     "DependsOn": [ "CloudformationEventHandlerLambdaFunction" ] 
    } 
    } 

パイソンSESラムダ

import boto3 

client = boto3.client('ses') 

def lambda_handler(event, context): 
    message = """ 
     Event: 
     {} 

     Context: 
     {} 
    """.format(event, context) 

    response = client.send_email(
      Source='***censored***', 
      Destination={ 'ToAddresses': [ ***censored***' ] }, 
      Message={ 
        'Subject': { 
          'Data': 'CFMTest' 
         }, 
        'Body': { 
          'Text': { 
            'Data': message 
           } 
         } 
       } 
      ) 

答えて

1

SourceAccountのみCloudWatchのログ、CloudWatchのルール、S3およびSESで使用することを意味します。
テンプレートのCloudformationEventHandlerLambdaInvokePermissionリソースからこのフィールドを削除した後、SNSトピックにパブリッシュしてラムダ関数を呼び出すことができます。

ラムダ許可の詳細については、thisのマニュアルを参照してください。

関連する問題