我需要扫描 dynamodb 数据库,但我不断收到此错误:
“errorMessage”:“调用扫描操作时发生错误 (AccessDeniedException):用户:arn:aws:sts::747857903140:assumed-role/test_role/TestFunction 无权执行:dynamodb:Scan on resource:arn:aws :dynamodb:us-east-1:747857903140:table/HelpBot"
这是我的 Lambda 代码(index.py):
import json
import boto3
client = boto3.resource('dynamodb')
table = client.Table('HelpBot')
def handler(event, context):
table.scan()
return {
"statusCode": 200,
"body": json.dumps('Hello from Lambda!')
}
这是我的 SAM 模板(template.yml):
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
MyFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: index.handler
Runtime: python3.6
Policies:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- dynamodb:Scan
Resource: arn:aws:dynamodb:us-east-1:747857903140:table/HelpBot