无服务器部署未将 AWS Lambda 与 SQS 事件集成
Serverless deploy doesn't integrate AWS Lambda with SQS event
我正在尝试使用无服务器框架创建一个与名为 'sendExportJob' 的 AWS Lambda 函数关联的 AWS SQS 事件,但在部署之后我无法在 AWS 控制台中看到 SQS 触发器。显然,我可以通过控制台手动添加此事件,它按预期工作。
这是serverless.yml中的Lambda函数配置:
sendExportJob:
handler: src/sendExportJob.handler
role: sendExportJobIAM
memorySize: ${self:custom.config.send-exportjob-lambda-settings.memorySize}
timeout: ${self:custom.config.send-exportjob-lambda-settings.timeout}
environment:
lambdaName: ${self:custom.config.send-exportjob-lambda-settings.name}
pendingqueueUrl: https://sqs.${self:custom.config.region}.amazonaws.com/${self:custom.config.account-id}/${self:custom.config.sqs-pending-exports-queue-name}
region: ${self:custom.config.region}
events:
- schedule: rate(${self:custom.config.send-exportjob-lambda-settings.schedule-rate-minutes} minutes)
- pendingsqs:
arn: arn:aws:sqs:${self:custom.config.region}:${self:custom.config.account-id}:${self:custom.config.sqs-pending-exports-queue-name}
batchSize: 1
这是此特定功能的 IAM 配置:
sendExportJobIAM:
Type: AWS::IAM::Role
Properties:
RoleName: sendExportJobRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: sendExportJobIAMAll
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
- logs:CreateLogGroup
Resource: '*'
- Effect: Allow
Action:
- sqs:ChangeMessageVisibility
- sqs:ChangeMessageVisibilityBatch
- sqs:DeleteMessage
- sqs:DeleteMessageBatch
- sqs:GetQueueAttributes
- sqs:ReceiveMessage
Resource: arn:aws:sqs:${self:custom.config.region}:${self:custom.config.account-id}:${self:custom.config.sqs-pending-exports-queue-name}
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource: '*'
我使用的是最新版本的Serverless框架,我检查了配置文件中的缩进。
SQS 资源之前已部署,因此在将其添加为事件之前它已经存在。
您的 events
部分下缺少 sqs
属性。我不太确定 pendingsqs
是什么意思,因为那不是有效的无服务器框架关键字
sendExportJob:
handler: src/sendExportJob.handler
role: sendExportJobIAM
memorySize: ${self:custom.config.send-exportjob-lambda-settings.memorySize}
timeout: ${self:custom.config.send-exportjob-lambda-settings.timeout}
environment:
lambdaName: ${self:custom.config.send-exportjob-lambda-settings.name}
pendingqueueUrl: https://sqs.${self:custom.config.region}.amazonaws.com/${self:custom.config.account-id}/${self:custom.config.sqs-pending-exports-queue-name}
region: ${self:custom.config.region}
events:
- schedule: rate(${self:custom.config.send-exportjob-lambda-settings.schedule-rate-minutes} minutes)
- sqs: arn:aws:sqs:${self:custom.config.region}:${self:custom.config.account-id}:${self:custom.config.sqs-pending-exports-queue-name}
如果你想像上面那样配置批量大小,只需将其放在 events
列表中的 sqs
项下,如下所示:
sendExportJob:
handler: src/sendExportJob.handler
role: sendExportJobIAM
memorySize: ${self:custom.config.send-exportjob-lambda-settings.memorySize}
timeout: ${self:custom.config.send-exportjob-lambda-settings.timeout}
environment:
lambdaName: ${self:custom.config.send-exportjob-lambda-settings.name}
pendingqueueUrl: https://sqs.${self:custom.config.region}.amazonaws.com/${self:custom.config.account-id}/${self:custom.config.sqs-pending-exports-queue-name}
region: ${self:custom.config.region}
events:
- schedule: rate(${self:custom.config.send-exportjob-lambda-settings.schedule-rate-minutes} minutes)
- sqs:
arn: aws:sqs:${self:custom.config.region}:${self:custom.config.account-id}:${self:custom.config.sqs-pending-exports-queue-name}
batchSize: 1
这都记录在案了here
我正在尝试使用无服务器框架创建一个与名为 'sendExportJob' 的 AWS Lambda 函数关联的 AWS SQS 事件,但在部署之后我无法在 AWS 控制台中看到 SQS 触发器。显然,我可以通过控制台手动添加此事件,它按预期工作。
这是serverless.yml中的Lambda函数配置:
sendExportJob:
handler: src/sendExportJob.handler
role: sendExportJobIAM
memorySize: ${self:custom.config.send-exportjob-lambda-settings.memorySize}
timeout: ${self:custom.config.send-exportjob-lambda-settings.timeout}
environment:
lambdaName: ${self:custom.config.send-exportjob-lambda-settings.name}
pendingqueueUrl: https://sqs.${self:custom.config.region}.amazonaws.com/${self:custom.config.account-id}/${self:custom.config.sqs-pending-exports-queue-name}
region: ${self:custom.config.region}
events:
- schedule: rate(${self:custom.config.send-exportjob-lambda-settings.schedule-rate-minutes} minutes)
- pendingsqs:
arn: arn:aws:sqs:${self:custom.config.region}:${self:custom.config.account-id}:${self:custom.config.sqs-pending-exports-queue-name}
batchSize: 1
这是此特定功能的 IAM 配置:
sendExportJobIAM:
Type: AWS::IAM::Role
Properties:
RoleName: sendExportJobRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: sendExportJobIAMAll
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
- logs:CreateLogGroup
Resource: '*'
- Effect: Allow
Action:
- sqs:ChangeMessageVisibility
- sqs:ChangeMessageVisibilityBatch
- sqs:DeleteMessage
- sqs:DeleteMessageBatch
- sqs:GetQueueAttributes
- sqs:ReceiveMessage
Resource: arn:aws:sqs:${self:custom.config.region}:${self:custom.config.account-id}:${self:custom.config.sqs-pending-exports-queue-name}
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource: '*'
我使用的是最新版本的Serverless框架,我检查了配置文件中的缩进。
SQS 资源之前已部署,因此在将其添加为事件之前它已经存在。
您的 events
部分下缺少 sqs
属性。我不太确定 pendingsqs
是什么意思,因为那不是有效的无服务器框架关键字
sendExportJob:
handler: src/sendExportJob.handler
role: sendExportJobIAM
memorySize: ${self:custom.config.send-exportjob-lambda-settings.memorySize}
timeout: ${self:custom.config.send-exportjob-lambda-settings.timeout}
environment:
lambdaName: ${self:custom.config.send-exportjob-lambda-settings.name}
pendingqueueUrl: https://sqs.${self:custom.config.region}.amazonaws.com/${self:custom.config.account-id}/${self:custom.config.sqs-pending-exports-queue-name}
region: ${self:custom.config.region}
events:
- schedule: rate(${self:custom.config.send-exportjob-lambda-settings.schedule-rate-minutes} minutes)
- sqs: arn:aws:sqs:${self:custom.config.region}:${self:custom.config.account-id}:${self:custom.config.sqs-pending-exports-queue-name}
如果你想像上面那样配置批量大小,只需将其放在 events
列表中的 sqs
项下,如下所示:
sendExportJob:
handler: src/sendExportJob.handler
role: sendExportJobIAM
memorySize: ${self:custom.config.send-exportjob-lambda-settings.memorySize}
timeout: ${self:custom.config.send-exportjob-lambda-settings.timeout}
environment:
lambdaName: ${self:custom.config.send-exportjob-lambda-settings.name}
pendingqueueUrl: https://sqs.${self:custom.config.region}.amazonaws.com/${self:custom.config.account-id}/${self:custom.config.sqs-pending-exports-queue-name}
region: ${self:custom.config.region}
events:
- schedule: rate(${self:custom.config.send-exportjob-lambda-settings.schedule-rate-minutes} minutes)
- sqs:
arn: aws:sqs:${self:custom.config.region}:${self:custom.config.account-id}:${self:custom.config.sqs-pending-exports-queue-name}
batchSize: 1
这都记录在案了here