我想将我的 SAM 应用程序拆分为多个部分。
我想在根堆栈中创建一个 API ( AWS::Serverless::Api )。
我正在我的子堆栈中创建 lambda 函数,我想在其中提供从根堆栈到 API 事件的 API 引用。
这可行吗?我没有找到任何从根堆栈访问 API 到子堆栈的好例子?
我尝试使用以下模板 -
parenttemplateapi:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:account_id:applications/parent-template
SemanticVersion: 1.0.0
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python2.7
Events:
HelloWorld:
Type: Api
Properties:
Method: get
Path: /hello
RestApiId: !GetAtt parenttemplateapi.Outputs.ServerlessGW-restApiId
Run Code Online (Sandbox Code Playgroud)
当我尝试部署此模板时,出现以下错误 -
错误:无法为堆栈创建变更集:子模板,例如:Water ChangeSetCreateComplete 失败:Water 遇到终端故障状态状态:FAILED。原因:转换 AWS::Serverless-2016-10-31 失败:内部转换失败。
任何指示/建议?
我指的是以下链接 -
此处可以使用来自根堆栈的 API 网关 ID (AWS::ApiGateway::RestApi) 吗?
https://dev.to/grahamcox82/building-a-larger-serverless-application-part-3-modular-monorepos-3mon
这可以使用无服务器框架来实现吗?
amazon-web-services aws-cloudformation aws-api-gateway serverless-framework aws-sam
我正在尝试使用 DynamoDB 操作BatchWriteItem,其中我想将多条记录插入到一个表中。
该表有一个分区键和一个排序键。
我正在使用 AWS lambda 和 Go 语言。
我将元素插入到切片中。
我正在遵循这个程序。
创建PutRequest结构并为列表中的第一条记录添加 AttributeValues。
我正在创造WriteRequest这个PutRequest
我将此添加WriteRequest到array of WriteRequests
我正在创建BatchWriteItemInput它由 组成RequestItems,它基本上是一个Tablename的映射和WriteRequests.
之后,我调用BatchWriteItem,这会导致错误 - 提供的项目键列表包含重复项。
任何指针,为什么会发生这种情况?
我们正在使用MongoDB.在我们的应用中,我们需要为每个用户存储多个文件.我们的应用程序将部署在AWS上.我正在考虑使用以下选项之一来存储文件 -
以上哪种方法更好?在性能,可扩展性方面?哪种方法更具可扩展性?我还想使用CDN来缓存文件.我的首选是AWS S3,因为我可以使用CDN来缓存文件,我的文件存储将与数据库无关.此外,由于我将文件存储在数据库外部,因此我的数据库大小不会显着增长.
我在 Golang 中开发了一组 Lambda 函数,并尝试使用 SAM 部署这些函数和 API 网关。
我正在本地创建可执行文件,为每个 lambda 函数创建 zip 文件,并将这些 zip 文件上传到 s3 存储桶。
我在 SAM 模板文件中给出了这个 S3 存储桶的参考。
我的 SAM 模板文件如下所示
myfunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://<<my-bucket>>/bin/handlers/myfunction.zip
Handler: myfunction
Role: !GetAtt CFLambdaExecutionRole.Arn
Events:
Getcfdemoapi:
Type: Api
Properties:
Path: /myfunction
Method: get
CreateCustomer:
Type: Api
Properties:
Path: /myfunction
Method: post
UpdateCustomer:
Type: Api
Properties:
Path: /customer
Method: put
DeleteCustomer:
Type: Api
Properties:
Path: /myfunction
Method: delete
Run Code Online (Sandbox Code Playgroud)
部署成功。
我通过 API 网关调用了 lambda 函数。
我检查了 Cloud watch 日志并看到以下错误 …
我正在尝试使用 go sdk 为我的 S3 存储桶中的文件创建预签名 URL。
当我从命令行运行程序时,我得到了不包含 X-Amz-Security-Token 的预签名 URL。
但是如果我使用来自 lambda 函数的相同代码,我总是在 URL 中获得 X-Amz-Security-Token。
我不确定为什么这种行为是不同的。
这是代码 -
func CreatePreSignedURL(bucketName string, path string) (string, error) {
sess, err := session.NewSession(&aws.Config{
Region: aws.String("us-east-1")},
)
svc := s3.New(sess)
req, _ := svc.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String(bucketName),
Key: aws.String(path),
})
urlStr, err := req.Presign(60 * time.Minute)
if err != nil {
fmt.Println("error in generarting presigned URL is ", err)
return urlStr, err
}
return urlStr, nil
}
Run Code Online (Sandbox Code Playgroud)
由 lambda 生成的 URL 很长,对于我的应用程序,我期待一个没有 X-Amz-Security-Token …
我正在尝试使用 Serverless.yml 文件创建认知用户池 ID 和应用程序客户端
我指的是这个链接 -
https://serverless-stack.com/chapters/configure-cognito-user-pool-in-serverless.html
我想在我的 lambda 函数代码中使用这个 Cognito 用户池 ID。
有什么方法可以在我的 lambda 代码中获取此用户池 ID 和应用程序客户端 ID 吗?
无服务器有什么方法可以创建一些环境变量等来保存用户池 ID 和应用程序客户端 ID 的值?
amazon-web-services amazon-cognito aws-lambda serverless-framework
我正在尝试使用 Go lang 通过 lambda 函数创建 Cognito 用户池。
已成功创建 IAM 角色、IAM 策略和信任关系策略。
但是当我尝试创建 Cognito 池时,出现错误,
InvalidSmsRoleTrustRelationshipException: Role does not have a trust relationship allowing Cognito to assume the role.
信任关系政策是
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "cognito-idp.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Run Code Online (Sandbox Code Playgroud)
创建用户池 API 调用如下 -
newUserPoolData := &cognitoidentityprovider.CreateUserPoolInput{
PoolName: aws.String(poolName),
Policies: &userPoolPolicyType,
AutoVerifiedAttributes: autoVerifiedAttributes,
UsernameAttributes: userNameAttributes,
SmsConfiguration: &smsConfingType,
}
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?
我正在使用无服务器框架在 AWS 云上部署我的应用程序。
https://serverless.com/
Run Code Online (Sandbox Code Playgroud)
我想在 serverless.yml 文件中使用 AWS 账户 ID 的值,并且我想将账户 ID 作为环境变量导出,以便可以从 Lambda 函数访问它。
基于这个 lambda 函数的值,我想创建一些资源(比如 IAM 角色等),这些资源引用这个 accountId 变量。
但是当我尝试部署堆栈时,出现以下错误,
尝试将非字符串值填充到变量 ${self:custom.accountId} 的字符串中。请确保该属性的值是一个字符串。
我的 Serverless.yml 文件如下
custom:
accountId : !Ref "AWS::AccountId"
provider:
name: aws
runtime: go1.x
stage: dev
region: us-east-1
environment:
ACCOUNT_ID : ${self:custom.accountId}
myRoleArn: arn:aws:iam::${self:custom.accountId}:role/xxxxxxxx
Run Code Online (Sandbox Code Playgroud)
有什么办法可以引用 serverless.yml 文件中的 Account Id 的值吗?
amazon-web-services aws-cloudformation serverless-framework aws-serverless