2016-08-08 9 views
0

clouduing에서 SNS 주제에 의해 트리거되는 이메일 전송 람다 함수를 설정하려고하지만 어떤 이유로 작동하지 않습니다. 내가 들어가서 람다 & sns가 올라간 후에 모든 의존성/허가를 확인했는데 모든 것이 순서대로되어있는 것 같지만 주제가 나오지 않을 때 아무 일도 일어나지 않습니다. Lambda 콘솔에서 수동으로 람다를 테스트하면 완벽하게 작동합니다.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

AWS::Lambda::Permission 자원 유형에 대한 SourceAccount은 CloudWatch를 기록, CloudWatch는 규칙, S3 및 SES와 함께 사용하기위한 것입니다.
템플릿의 CloudformationEventHandlerLambdaInvokePermission 리소스에서이 필드를 제거한 후 SNS 주제에 게시하여 람다 함수를 호출 할 수 있습니다.

람다 권한에 대한 자세한 내용은 this 설명서를 참조하십시오.

관련 문제