我尝试从 Rekognition 框架调用 detectorText 方法,但无法调用 S3 存储桶。我不确定如何在 SAM 模板中分配角色。下面是我的 SAM 模板
GetTextFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: gettextfn/
Handler: text.handler
Runtime: nodejs12.x
Timeout: 3
MemorySize: 128
Environment:
Variables:
imagebucket: !Ref s3bucket
Events:
TextApiEvent:
Type: HttpApi
Properties:
Path: /gettext
Method: get
ApiId: !Ref myapi
最佳答案
看起来您的 lambda 需要 RekognitionDetectOnlyPolicy
并且您似乎也错过了从 S3 存储桶读取/写入数据的策略。看看下面添加在环境之后的Policies:
:
Environment:
Variables:
imagebucket: !Ref s3bucket
Policies:
- S3ReadPolicy:
BucketName: !Ref s3bucket
- RekognitionDetectOnlyPolicy: {}
Events:
您可以在此处引用 AWS SAM 策略模板的完整列表 https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html
另请查看此处的示例模板 https://github.com/rollendxavier/serverless_computing/blob/main/template.yaml
关于amazon-web-services - AWS SAM 无法调用 Rekognition 并从 Lambda 访问 S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66978234/