【问题标题】:What is SourceArn when create lambda function through cloudformation template通过cloudformation模板创建lambda函数时SourceArn是什么
【发布时间】:2021-09-16 16:46:12
【问题描述】:

我想通过cloudformation模板创建一个lambda函数,我有ConfigurationLambdaRole、ConfigurationLambdaFunction和ConfigurationLambdaInvokePermission,在ConfigurationLambdaInvokePermission部分,SourceArn应该是什么?我的模板有什么不正确的地方吗?

Resources:
  ConfigurationLambdaRole:
    Type: "AWS::IAM::Role"
    Properties:
      RoleName: 'configuration-lambda'
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - events.amazonaws.com
                - s3.amazonaws.com
            Action:
              - sts:AssumeRole
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/AmazonSQSFullAccess
        - arn:aws:iam::aws:policy/CloudWatchLogsFullAccess

  ConfigurationLambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      Description: 'configuration service with lambda'
      FunctionName: 'configuration-lambda1'
      Handler: lambda.handler.EventHandler::handleRequest
      Runtime: Java 11
      MemorySize: 128
      Timeout: 120
      Code:
        S3Bucket: configurationlambda
        S3Key: lambda-service-1.0.0-SNAPSHOT.jar
      Role: !GetAtt ConfiguratioLambdaRole.Arn

  ConfigurationLambdaInvokePermission:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName:
        Fn::GetAtt:
          - ConfigurationLambdaFunction
          - Arn
      Action: 'lambda:InvokeFunction'
      Principal: "s3.amazonaws.com"
      SourceArn: 'arn of jar file in s3(configurationlambda)'

【问题讨论】:

    标签: amazon-web-services aws-lambda amazon-cloudformation


    【解决方案1】:

    SourceArn 是一个资源的 arn,它将调用你的函数。例如,如果您的 lambda 将通过 S3 事件通知调用,SourceArn 将是您的存储桶的 ARN。

    在你的情况下,我不明白你为什么需要 AWS::Lambda::Permission。所以我会删除整个资源。

    【讨论】:

    • 你好,我编辑了代码,我想把我的jar文件上传到s3,然后通过s3上传到lambda,所以代码应该是这样的,对吗?
    • @WCY 您需要存储桶的 ARN,而不是 jar 文件。此外,您还没有在代码中定义任何 S3 事件,因此无论如何它都不起作用。此外,您的 lambda 角色缺少 s3 权限。
    • 您能告诉我将 S3 事件放在代码中的什么位置吗?我以为我在 ConfigurationLambdaFunction 部分定义的是 s3 事件,它包含 s3 存储桶和密钥
    • @WCY 你 define 用你的桶。但这对于新问题会更好,因为它与您发布的“什么是 SourceArn”问题大相径庭。
    猜你喜欢
    • 2021-09-12
    • 1970-01-01
    • 2017-05-12
    • 2017-05-12
    • 2019-06-29
    • 2020-10-25
    • 2020-03-27
    • 2020-07-19
    • 1970-01-01
    相关资源
    最近更新 更多