我在使用无服务器框架将堆栈部署到 AWS 时遇到问题。
我正在运行这个
serverless deploy --stage tst --region eu-west-3 --verbose
然后我的 2 个函数陷入“CREATE_IN_PROGRESS”状态,然后 1 小时后,我出现“UPDATED_FAILED_ROLLBACK_IN_PROGRESS”和“UPDATED_FAILED_ROLLBACK_COMPLETED”状态。
CREATE_IN_PROGRESS - Custom::S3 - MyFunctionDataListenerLambdaCustomS31
CREATE_IN_PROGRESS - Custom::S3 - MyFunctionData2ListenerLambdaS31
这是我的 yaml 函数定义之一:
MyFunctionDataListenerLambda:
name: myapp-${sls:stage}-entry-data-listener
description: 'Triggered by S3 event and start a new step function execution'
handler: src/features/entry/infrastructure/lambda/myapp-files-listener/handler.handle
role: MyAppDataListenerLambdaRole
layers:
- ${ssm:/${sls:stage}/utils-lambda-layer-arn}
events:
- s3:
bucket: myapp-${sls:stage}-data
event: s3:ObjectCreated:*
existing: true
forceDeploy: true
rules:
- prefix: xxx/
- suffix: .csv
environment:
ONE: ${self:custom.redshift.stage.${sls:stage}}
TWO: myapp-${self:custom.redshift.stage.${sls:stage}}-redshift-cluster
THREE: myapp
FOUR: ${self:custom.redshift.stage.${sls:stage}}_myapp
FIVE: arn:aws:states:${aws:region}:${aws:accountId}:stateMachine:myapp-${sls:stage}-workflow
SIX: myapp-${sls:stage}-myapp/data
其他功能几乎相同
所以当我放置节点“events”时就会出现这个问题
- s3:
bucket: myapp-${sls:stage}-data
event: s3:ObjectCreated:*
existing: true
forceDeploy: true
rules:
- prefix: xxx/
- suffix: .csv`
当我删除它时,一切正常,角色“MyAppDataListenerLambdaRole”在 serverless.yaml 中包含的另一个文件中定义如下
Resources:
MyAppDataListenerLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: myapp-${sls:stage}-listener-role
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: myapp-${sls:stage}-listener-policy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- states:StartExecution
Resource: arn:aws:states:${aws:region}:${aws:accountId}:stateMachine:myapp-${sls:stage}-workflow
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
- s3:ListBucket
Resource:
- arn:aws:s3:::myapp-${sls:stage}-data
- arn:aws:s3:::myapp-${sls:stage}-data/*
我尝试输入我的配置
提供商: 部署方法:直接#也尝试过,但变更集仍然卡住
我在网上没有找到任何有用的信息,这是我第一次在这里写作,因为我真的很困惑,如果您需要更多信息,请告诉我。 S3 存储桶是使用 CDK 在另一个项目上创建的
在 CloudFormation 事件中,我收到“CloudFormation 未收到来自您的自定义资源的响应。”
好吧,我找到了答案,从这里开始回答https://github.com/serverless/serverless/issues/6771#issuecomment-1916211820所以当我们放置事件节点时,无服务器创建一个特定的 lambda 来执行它,名为“custom-resource-existing-s3”使用节点作为运行时。但是,如果我们强制节点版本高于 16,则 aws-sdk 将在此 lambda 中不可用,这将导致错误。问题出在框架方面。我使用自定义插件强制 custom-resource-existing-s3 lambda 在禁用它后使用节点 20,它有效。