c# - AWS StepFunctions...模板错误:Fn::Sub 的实例引用了无效的资源属性
问题描述
我在 StepFunctions 状态机中使用 AWS Lambda。
下面的模板运行良好,直到我不得不更改 LogToDatabase 函数的名称。
现在 VS2019 中的 Publish to AWS 向导给出了这个错误:
未能创建 CloudFormation 更改集:模板错误:Fn::Sub 的实例引用了无效的资源属性 LogToDatabase.Arn
有任何想法吗?
这是我的 StepFunctions 状态机:
{
"Comment": "Billing Portal Email - State Machine",
"StartAt": "SendEmail",
"States": {
"SendEmail": {
"Type": "Task",
"Resource": "${SendEmail.Arn}",
"Next": "WaitToActivate"
},
"WaitToActivate": {
"Type": "Wait",
"SecondsPath": "$.WaitInSeconds",
"Next": "LogToDatabase"
},
"LogToDatabase": {
"Type": "Task",
"Resource": "${LogToDatabase.Arn}",
"End": true
}
}
}
CloudFormation 模板:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "APC Serverless Application for Billing Portal",
"Resources": {
"SendEmailTask": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Handler": "APC.AWS.SAM::APC.AWS.SAM.StepFunctionTasks::SendEmail",
"Role": {
"Fn::GetAtt": [
"LambdaRole",
"Arn"
]
},
"Runtime": "dotnetcore3.1",
"MemorySize": 128,
"Timeout": 60,
"Code": {
"S3Bucket": "",
"S3Key": ""
}
}
},
"LogToDatabaseTask": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Handler": "APC.AWS.SAM::APC.AWS.SAM.StepFunctionTasks::LogToDatabase",
"Role": {
"Fn::GetAtt": [
"LambdaRole",
"Arn"
]
},
"Runtime": "dotnetcore3.1",
"MemorySize": 128,
"Timeout": 30,
"Code": {
"S3Bucket": "",
"S3Key": ""
}
}
},
"StateMachine": {
"Type": "AWS::StepFunctions::StateMachine",
"Properties": {
"RoleArn": {
"Fn::GetAtt": [
"StateMachineRole",
"Arn"
]
},
"DefinitionString": {
"Fn::Sub": ""
}
}
},
"LambdaRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
]
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
}
},
"StateMachineRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": {
"Fn::Sub": "states.${AWS::Region}.amazonaws.com"
}
},
"Action": "sts:AssumeRole"
}
]
},
"Policies": [
{
"PolicyName": "StepFunctionLambdaInvoke",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction"
],
"Resource": "*"
}
]
}
}
]
}
}
},
"Outputs": {},
"Metadata": {
"AWS::CloudFormation::Designer": {}
}
}
最后,我的 C# lambda 函数签名...
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace APC.AWS.SAM
{
public partial class StepFunctionTasks
{
public StepFunctionTasks() { }
public State SendEmail(State state, ILambdaContext context)
{
//code here
return state;
}
public State LogToDatabase(State state, ILambdaContext context)
{
//more code here
return state;
}
}
}
解决方案
您只需要更改${LogToDatabase.Arn}
为${LogToDatabaseTask.Arn}
. lambda 函数的逻辑 ID 是LogToDatabaseTask
.
推荐阅读
- java - 如何使用 itext 从具有内置编码的 pdf 中提取 PRStream?
- asp.net-web-api - WebAPI 方法应该如何返回错误响应?
- python - pandas:INT系列,为什么转换成字符串后有“.0”?
- javascript - TypeError: Cannot read property 'map' of undefined, in react hooks crud application
- angular - Angular 9 routerLinkActive not working properly
- python - 如何使用 gensim 从 ldamodel 中获取主题概率?
- hangfire - How can I publish Hangfire Dashboard for a custom web page?
- android - 如何在 viewModel MVVM Kotlin 中调用 notifydatachanged?
- node.js - 将 Shell 脚本转换为 nodejs 之一
- node.js - 当我使用 [] 设置对象时,为什么对象在 Express 中不起作用