Serverless Framework中Lambda创建后再建资源报错求助
问题原因
你用DependsOn: defineAuthChallenge报错,是因为CloudFormation找不到名为defineAuthChallenge的资源——Serverless框架会把你在functions里定义的函数转换成CloudFormation的AWS::Lambda::Function资源,它的逻辑资源名称不是你写的function键名,而是遵循默认命名规则:把function名转成大驼峰格式,再加上LambdaFunction后缀。你的function叫defineAuthChallenge,对应的CloudFormation逻辑资源名是DefineAuthChallengeLambdaFunction。
解决方案
把DependsOn的值改成Serverless自动生成的Lambda逻辑资源名,同时推荐用!Ref引用该资源来指定FunctionName,避免手动拼接ARN出错:
resources: # CloudFormation template syntax Resources: DefineLambdaInvokePermission: DependsOn: DefineAuthChallengeLambdaFunction Type: 'AWS::Lambda::Permission' Properties: Action: "lambda:InvokeFunction" FunctionName: !Ref DefineAuthChallengeLambdaFunction Principal: "cognito-idp.amazonaws.com" SourceArn: !Sub "arn:aws:cognito-idp:${opt:region}:${self:custom.service.accountId}:userpool/*"
额外验证方法
如果你不确定Serverless生成的逻辑资源名是什么,可以运行serverless package命令,在.serverless/cloudformation-template-update-stack.json文件里找到对应的Lambda资源,查看它的逻辑ID(即JSON里的键名)。
内容的提问来源于stack exchange,提问作者Kannan T
相关产品推荐
相关产品推荐

