C# AWS步进函数。。。模板错误:Fn::Sub的实例引用了无效的资源属性
我在状态机中使用AWS Lambda 在我不得不更改LogToDatabase函数的名称之前,下面的模板工作得很好 现在,VS2019中的“发布到AWS向导”出现以下错误: 未能创建CloudFormation更改集:模板错误:Fn::Sub引用的实例无效资源属性LogToDatabase.Arn 有什么想法吗 这是我的状态机:C# AWS步进函数。。。模板错误:Fn::Sub的实例引用了无效的资源属性,c#,amazon-web-services,aws-lambda,C#,Amazon Web Services,Aws Lambda,我在状态机中使用AWS Lambda 在我不得不更改LogToDatabase函数的名称之前,下面的模板工作得很好 现在,VS2019中的“发布到AWS向导”出现以下错误: 未能创建CloudFormation更改集:模板错误:Fn::Sub引用的实例无效资源属性LogToDatabase.Arn 有什么想法吗 这是我的状态机: { "Comment": "Billing Portal Email - State Machine", "S
{
"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
}
}
}
云形成模板:
{
"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}
更改为${LogToDatabase.Arn}
。lambda函数的逻辑ID是LogToDatabaseTask
,完全就是这样。非常感谢!