我正在尝试部署我的第一个无服务项目,并想让它更新我的dynamodb中的一个简单项目.所以我开始在serverless.yml中创建一个简单的服务:
service: serverless
provider:
name: aws
runtime: nodejs4.3
iamRoleStatements:
- Effect: "Allow"
Resource: "*"
Action:
- "dynamodb:*"
functions:
createMovie:
handler: handler.createMovie
events:
- http:
path: movies/create
method: post
integration: lambda
cors: true
Run Code Online (Sandbox Code Playgroud)
然后我在网上找到了更多的代码链接我的应用程序的dynamodb部分,并将其添加到底部的serverless.yml:资源:
Resources:
DynamoDbTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: moviesTwo
AttributeDefinitions:
- AttributeName: movieTitle
AttributeType: S
KeySchema:
- AttributeName: movieTitle
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
DynamoDBIamPolicy:
Type: AWS::IAM::Policy
DependsOn: DynamoDbTable
Properties:
PolicyName: lambda-dynamodb
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- dynamodb:GetItem
- dynamodb:PutItem
Resource: arn:aws:dynamodb:*:*:table/moviesTwo
Roles: …Run Code Online (Sandbox Code Playgroud) 我有一个用户表和一个请求表。一个用户的许多请求。我想在用户表中有一个请求列表。但我不确定如何编写云形成调用来构建它。目前我只有一组平面属性:
resources:
Resources:
DynamoDbTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: Employee
AttributeDefinitions:
- AttributeName: employeeid
AttributeType: S
- AttributeName: name
AttributeType: S
- AttributeName: requests
AttributeType: S
KeySchema:
- AttributeName: employeeid
KeyType: HASH
Run Code Online (Sandbox Code Playgroud)
我希望请求是用户的请求 ID 列表,而不是字符串值,所以没有 S 类型,所以我可以循环浏览它们并调用我想要的。让我知道我的架构是否正常。提前致谢。