我们正在评估是否对我们的一些新的 AWS 应用程序基础设施使用无服务器。我们大量使用 Cloudformation(由 Ansible 部署),因此我们需要能够干净地引用现有 Cloudformation 堆栈的输出 - 一个直接的例子是获取现有 AWS 网络基础设施的子网 ID 以供 lambda 函数使用。
经过大量浏览后,我还没有找到一种开箱即用的方法来做到这一点。我们现有的 Cloudformation 堆栈的命名方式是这样的:如果我只需输入堆栈的名称和所需的输出变量,我就可以在各种环境中可靠地获得所需的输出。我看到的一个可能的解决方案是使用 aws cli 提取变量并将它们作为环境变量传递给无服务器,但如果可能的话,我希望有一种更干净的方法。
我有一些不同的服务(由无服务器框架生成)需要相互通信。数据敏感,需要身份验证。
我当前的策略是为每个服务创建一个 api 密钥,使用 json web 令牌在服务之间进行通信,如下所示的令牌。
fM61kaav8l3y_aLC/3ZZF7nlQGyYJsZVpLLiux5d84UnAoHOqLPu4dw3W7MiGwPiyN
Run Code Online (Sandbox Code Playgroud)
服务之间通信还有哪些其他选项?这种方法有什么缺点吗?重申一下,请求需要经过身份验证并适当处理敏感数据。
amazon-web-services aws-lambda aws-api-gateway serverless-framework
我有一个无服务器功能,看起来像
functions:
ScooterExecution:
handler: ScooterExecution.hello
name: scooter-execution
memorySize: 256
timeout: 300
events:
- s3:
bucket: ScooterData
event: s3:ObjectCreated:*
Run Code Online (Sandbox Code Playgroud)
文档说运行这个应该创建一个 s3 存储桶并在创建对象时触发它。
但是,它创建的模板没有提及 S3 存储桶,也不会创建名为 scooterdata 的 s3 存储桶,也不会尝试向 lambda 注册任何触发器。
这里发生了什么事?
最奇怪的事情正在发生。我\xe2\x80\x99m 使用打字稿,并不是单个目录中的所有打字稿文件都被编译,即我的源代码树中有一个目录\xe2\x80\x99s,其中一些 .ts 文件被编译为 . js 和其他的是\xe2\x80\x99t。
\n\n当我运行简单的 tsc 时,所有文件都会被编译,但是当我运行 \xe2\x80\x98serverless offline start\xe2\x80\x99 时,并非所有文件都会被编译。
\n\n有人知道如何修复吗?
\n\n我的 serverless.yml 的基础知识:
\n\npackage:\n include:\n - src/**/*\n\nfunctions:\n graphql:\n handler: src/graphql.handler\n events:\n - http:\n path: graphql\n method: post\n cors: true\n\nplugins:\n - serverless-plugin-typescript\n - serverless-offline\nRun Code Online (Sandbox Code Playgroud)\n\ntsconfig.json:
\n\n{\n "compilerOptions": {\n /* Basic Options */\n "target": "es2016", /* Specify ECMAScript target version: \'ES3\' (default), \'ES5\', \'ES2015\', \'ES2016\', \'ES2017\',\'ES2018\' or \'ESNEXT\'. */\n "module": "commonjs", /* Specify module code generation: \'none\', \'commonjs\', \'amd\', \'system\', \'umd\', …Run Code Online (Sandbox Code Playgroud) 使用无服务器框架时如何为 DynamoDB 表启用连续备份?
理想情况下,我会定义一些serverless.yml可以启用自动 DynamoDB 备份的内容
amazon-dynamodb serverless-framework serverless-plugins aws-serverless
我正在 AWS 中使用无服务器框架创建一个应用程序。我正在使用 NodeJS 编写 Lambda。在应用程序中我想创建两个不同的角色
在我的serverless.yaml文件中,我为这些用户类型创建了两个不同的 Cognito 用户池组
AdminUserPoolGroup:
Type: AWS::Cognito::UserPoolGroup
Properties:
GroupName: "admins"
Precedence: 0
UserPoolId:
Ref: CognitoUserPool
NormalUserPoolGroup:
Type: AWS::Cognito::UserPoolGroup
Properties:
GroupName: users
Precedence: 1
UserPoolId:
Ref: CognitoUserPool
Run Code Online (Sandbox Code Playgroud)
我想向这两个组授予不同的访问级别,例如管理员可以创建帖子,用户只能查看它们。经过一些研究后,我发现这可以通过将策略附加到组来完成。但我找不到使用无服务器框架来做到这一点的方法。
amazon-web-services node.js amazon-cognito aws-lambda serverless-framework
不知道为什么,但是无服务器 GCP 的成功部署停止了错误:
team27> serverless deploy -c serverless_stage.yml
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Compiling function "user"...
Serverless: Compiling function "volunteer"...
Serverless: Compiling function "clear"...
Serverless: Uploading artifacts...
Serverless: Artifacts successfully uploaded...
Serverless: Updating deployment...
Serverless: Checking deployment update progress...
..
Error --------------------------------------------------
Error: Deployment failed: RESOURCE_ERROR
{"ResourceType":"cloudfunctions.v1beta2.function","ResourceErrorCode":"403","ResourceErrorMessage":{"code":403,"message":"The GCF v1beta2 API is deprecated. See https://cloud.google.com/functions/docs/migrating","status":"PERMISSION_DENIED","details":[],"statusMessage":"Forbidden","requestPath":"https://cloudfunctions.googleapis.com/v1beta2/projects/stageteam27/locations/us-central1/functions","httpMethod":"POST"}}
at throwErrorIfDeploymentFails (xxx\team27\node_modules\serverless-google-cloudfunctions\shared\monitorDeployment.js:71:11)
at xxx\team27\node_modules\serverless-google-cloudfunctions\shared\monitorDeployment.js:42:17
at processTicksAndRejections (internal/process/task_queues.js:93:5)
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Get Support --------------------------------------------
Docs: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用无服务器框架创建一个 AWS SQS 死信队列
这个想法是有一个 SQS 来触发 Lambda 函数,
并有另一个 SQS 作为 DeadLetterQueue,即。在 Lambda 失败或超时的情况下接收消息
我做了以下操作来创建一个测试项目 -
mkdir dlq
cd dlq/
serverless create --template aws-nodejs
Run Code Online (Sandbox Code Playgroud)
以下是我的 serverless.yaml -
service: dlq
provider:
name: aws
runtime: nodejs12.x
region: ap-southeast-1
role: arn:aws:iam::xxxx:role/dlqLambdaRole
plugins:
- serverless-plugin-lambda-dead-letter
functions:
dlq:
handler: handler.hello
events:
- sqs:
arn:
Fn::GetAtt:
- MainQueue
- Arn
deadLetter:
targetArn:
GetResourceArn: DeadLetterQueue
resources:
Resources:
MainQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: main
DeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: dlq
Run Code Online (Sandbox Code Playgroud)
我也尝试了以下 -
service: dlq
provider:
name: aws …Run Code Online (Sandbox Code Playgroud) 我是 dynamodb 和 serverless 的新手,我已经阅读了复合排序键。我认为它们可以解决我的问题,但我不完全确定如何实施它们。在我的例子中,我有一个带有Post实体的表,它具有以下字段,它看起来像这样:
post_id <string> | user_id <string> | tags <string[]> | public <boolean>| other post data attributes...
Run Code Online (Sandbox Code Playgroud)
我需要做的查询是:
我只能将 public 属性设置为标记为 public 的实体。如何使用无服务框架定义复合排序键。
因此,例如:
sort key: tag#public
Run Code Online (Sandbox Code Playgroud)
这是我之前设置的。
PostsDynamoDBTable:
Type: 'AWS::DynamoDB::Table'
Properties:
AttributeDefinitions:
- AttributeName: postId
AttributeType: S
- AttributeName: userId
AttributeType: S
- AttributeName: createdAt
AttributeType: S
KeySchema:
- AttributeName: postId
KeyType: HASH
- AttributeName: userId
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
TableName: ${self:provider.environment.POSTS_TABLE}
GlobalSecondaryIndexes:
- IndexName: ${self:provider.environment.USER_ID_INDEX}
KeySchema:
- …Run Code Online (Sandbox Code Playgroud) 背景:-我有一个网关帐户(没有权限),其中创建了用户,为了访问 aws 资源,我们使用具有管理员访问权限的角色。
配置文件
[profile gateway]
region = ap-southeast-1
output = json
[profile DA]
region = ap-south-1
output = json
role_arn = arn:aws:iam::xxxxxxxxxxxxx:role/jatin
mfa_serial = arn:aws:iam::xxxxxxxxxx:mfa/atin
source_profile = gateway
Run Code Online (Sandbox Code Playgroud)
凭证文件
[gateway]
aws_access_key_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
aws_secret_access_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试使用无服务器部署 --aws-profile "DA" 来部署我的 lambda,它说 AWS profile "DA" doesn't seem to be configured
但是,如果我aws s3 ls --profile "DA"完美地运行它的作品,那么我想配置文件和凭据的配置没有问题