gpt4 book ai didi

javascript - aws cloud9 lambda 导入失败

转载 作者:行者123 更新时间:2023-12-02 22:00:40 24 4
gpt4 key购买 nike

我有一个工作生产环境,其中使用 AWS SAM 从我的 PC 部署了多个 Lambda。

我想将 lambda 转换到 Cloud9 并从那里进行调试,但是...

一些函数导入得很好,我可以运行调试器,而另一些函数在导入后甚至不显示。这让我相信可能存在 Cloud9 不喜欢的配置问题。

我将使用一个相当简单的名为 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}" ] ]

我尝试了很多事情,包括更改函数名称、重新部署、清除缓存、重新启动cloud9、删除文件夹......

有什么想法吗?

最佳答案

函数的命名约定在导入时可能会出现问题,特别是在有条件参数的情况下。

我解决这个问题的方法是创建另一个具有完全相同的设置和代码(差异比较)的项目,并更改堆栈、应用程序、函数和策略的名称。

关于javascript - aws cloud9 lambda 导入失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59889088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com