amazon-s3 - 无服务器框架 - 创建 Lambda 和 S3 并在 S3 中上传文件。然后,使用 Lambda 提取到 DynamoDB
问题描述
这是我第一次使用 serverless 框架,我的任务是使用 serverless 创建 lambda、s3 和 dynamodb,然后调用 lambda 从 s3 转移到 dynamo。我试图让无服务器生成的名称到我的 S3 以在我的 Lambda 中使用它,但我没有运气。这就是我的 serverless.yml 的样子:
service: fetch-file-and-store-in-s3
frameworkVersion: ">=1.1.0"
custom:
bucket:
Ref: Outputs.AttachmentsBucketName
provider:
name: aws
runtime: nodejs12.x
stage: dev
region: us-east-1
iamRoleStatements:
- Effect: Allow
Action:
- s3:PutObject
- s3:PutObjectAcl
Resource: "arn:aws:s3:::${self:custom.bucket.Ref}/*"
functions:
save:
handler: handler.save
environment:
BUCKET: ${self:custom.bucket.Ref}
resources:
# S3
AttachmentsBucket:
Type: AWS::S3::Bucket
Properties:
# Set the CORS policy
CorsConfiguration:
CorsRules:
-
AllowedOrigins:
- '*'
AllowedHeaders:
- '*'
AllowedMethods:
- GET
- PUT
- POST
- DELETE
- HEAD
MaxAge: 3000
# Print out the name of the bucket that is created
Outputs:
AttachmentsBucketName:
Value:
Ref: AttachmentsBucket
这是它创建 s3 存储桶的部分
Resources:
# S3
AttachmentsBucket:
Type: AWS::S3::Bucket
Properties:
# Set the CORS policy
CorsConfiguration:
CorsRules:
- AllowedOrigins:
- '*'
- AllowedHeaders:
- '*'
- AllowedMethods:
- GET
- PUT
- POST
- DELETE
- HEAD
- MaxAge: 3000
# Print out the name of the bucket that is created
Outputs:
AttachmentsBucketName:
Value:
Ref: AttachmentsBucket
这是我目前得到的错误:
λ sls deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service fetch-file-and-store-in-s3.zip file to S3 (7.32 MB)...
Serverless: Validating template...
Error --------------------------------------------------
Error: The CloudFormation template is invalid: Invalid template property or properties [AttachmentsBucket, Type, Properties]
解决方案
你有一些缩进问题:
resources:
Resources:
# S3
AttachmentsBucket:
Type: AWS::S3::Bucket
Properties:
# Set the CORS policy
CorsConfiguration:
CorsRules:
- AllowedOrigins:
- '*'
- AllowedHeaders:
- '*'
- AllowedMethods:
- GET
- PUT
- POST
- DELETE
- HEAD
- MaxAge: 3000
# Print out the name of the bucket that is created
Outputs:
AttachmentsBucketName:
Value:
Ref: AttachmentsBucket
推荐阅读
- node.js - 属性 id 后的 MongoDb Shell 语法错误
- javascript - 为什么 vuelidate 验证器不再对输入更改做出反应?
- java - 在 Android 中的活动之间保持 Websocket 活动
- c# - 将字符串值转换为浮点值
- php - IIS Plesk - 将 PHP 的 FastCGI 协议从命名管道更改为 TCP
- c - 致命错误:sodium.h:没有这样的文件或目录
- python - 有人可以向我解释这段代码 - python 3
- javascript - 将 xml 标签加载到 javascript 数组中
- delphi - Delphi中如何将组件作为过程的参数传递?
- java - 在要求告知日期的问题中获得意外输出