简体   繁体   English

aws cloud9 lambda 导入失败

[英]aws cloud9 lambda import failed

I have a working production environment with several Lambda deployed from my PC using AWS SAM.我有一个工作生产环境,其中使用 AWS SAM 从我的 PC 部署了多个 Lambda。

I want to transition my lambda to Cloud9 and debug from there but...我想将我的 lambda 转换为 Cloud9 并从那里进行调试,但是...

Some of the functions import well and I can run the debugger while others don't even show up after importing.一些函数导入良好,我可以运行调试器,而其他函数在导入后甚至不显示。 This leads me to believe there might be a config issue that Cloud9 doesn't like.这让我相信可能存在 Cloud9 不喜欢的配置问题。

I'll take a fairly simple lambda called uploaddirect and this is what it looks like:我将采用一个名为 uploaddirect 的相当简单的 lambda,它是这样的:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: add docs directly from s3

Parameters:

  Environment:
    Type: String
    Default: staging
  DocumentMetadataBucketName:
    Type: String
  DocumentSourceBucketName:
    Type: String
  DocumentMetadataBucketArn:
    Type: String
  DocumentSourceBucketArn:
    Type: String

Resources:
  UploaddirectFunction:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub leopro-uploaddirect-function-${Environment}
      Handler: uploaddirect.handler
      Runtime: nodejs10.x
      Timeout: 300
      Role: !GetAtt UploaddirectExecutionRole.Arn
      Environment:
        Variables:
          DOCUMENT_METADATA_BUCKET: !Ref DocumentMetadataBucketName
          DOCUMENT_SOURCE_BUCKET: !Ref DocumentSourceBucketName
      CodeUri: .

  UploaddirectExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Sub leopro-uploaddirect-exec-role-${Environment}
      ManagedPolicyArns:
        - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
      Policies:
        -
          PolicyName: !Sub leopro-uploaddirect-access-s3-${Environment}
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              -
                Effect: "Allow"
                Action:
                  - "s3:GetObject"
                  - "s3:PutObject"
                Resource: 'arn:aws:s3:::*/*'
            Statement:
              -
                Effect: "Allow"
                Action:
                  - "s3:*"
                Resource: '*'
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          -
            Effect: "Allow"
            Principal:
              Service:
                - "lambda.amazonaws.com"
            Action:
              - "sts:AssumeRole"

  UploaddirectBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub leopro-uploaddirect-dropbox-bucket-${Environment}
      NotificationConfiguration:
        LambdaConfigurations:
          -
            Event: 's3:ObjectCreated:*'
            Function: !GetAtt UploaddirectFunction.Arn

  UploaddirectBucketPolicy:
      Type: AWS::S3::BucketPolicy
      Properties:
        Bucket: !Ref UploaddirectBucket
        PolicyDocument:
          Statement:
            -
              Action:
                - "s3:GetObject"
              Effect: "Allow"
              Resource: !Sub "arn:aws:s3:::leopro-uploaddirect-dropbox-bucket-${Environment}/*"
              Principal: "*"

  InvokeFromS3Permission:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName: !GetAtt UploaddirectFunction.Arn
      Action: "lambda:InvokeFunction"
      Principal: "s3.amazonaws.com"
      SourceArn: !Join [ "", [ "arn:aws:s3:::", !Sub "leopro-uploaddirect-dropbox-bucket-${Environment}" ] ]

I tried plenty of things including changing the function name, redeploying, clearing my cache, restarting cloud9, deleting folders ...我尝试了很多方法,包括更改函数名称、重新部署、清除缓存、重新启动 cloud9、删除文件夹......

Any ideas?有任何想法吗?

If anyone bumps in to this issue, the way I solved it was to create another project with exactly same settings and code (diff compare if you want) but just change the names of the stack, the app, the functions and the policies.如果有人遇到这个问题,我解决它的方法是创建另一个具有完全相同设置和代码的项目(如果需要,可以进行差异比较),但只需更改堆栈、应用程序、函数和策略的名称。

The initial version of this app was deployed using Node 8.10 which was recently deprecated.此应用程序的初始版本是使用最近弃用的 Node 8.10 部署的。 Maybe that was part of the problem.也许这是问题的一部分。

If this helps you, like this post , I probably saved you a day of productivity :p如果这对您有帮助,就像这篇文章一样,我可能会为您节省一天的工作效率:p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM