cloudformation template build fails when trying to pass the ARN of another resource

32 views Asked by At

I'm trying to pass the state machine arn as a variable to the lambda function so I can retry if a condition is met. Here are the resources:

    Resources:
  WebHookStateMachine:
      Type: AWS::StepFunctions::StateMachine
      Properties:
        StateMachineName: WebHookStateMachine
        RoleARN: !Sub arn:aws:iam::${AWS::AccountId}:role/aws-service-role/lambda.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_LambdaConcurrency
        DefinitionString:
          !Sub |
            {
              "Comment": "Retry workflow with 1 minute delay",
              "StartAt": "WaitState",
              "States": {
                "WaitState": {
                  "Type": "Wait",
                  "Seconds": 60,
                  "Next": "InvokeLambda"
                },
                "InvokeLambda": {
                  "Type": "Task",
                  "Resource": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${MafPayWebHookFunction}",
                  "End": true
                }
              }
            }

MafPayWebHookFunction:
Type: AWS::Serverless::Function
Properties:
  FunctionName: !FindInMap [FunctionNameMap, !Ref EnvironmentName, MafPayWebHookFunction]
  Environment:
    Variables:
      StateMachineArnVar: !Ref WebHookStateMachine 
      WEB_URL_DXB: !Ref WebUrlDBX
      BACKEND_URL: !Ref BackendURL
      APPLE_PAY_DXB_MERCHANT_IDENTITY_CERT_ARN: !Ref ApplePayDxbMerchantIdentityCertARN
      APPLE_PAY_DXB_MERCHANT_ID: !Ref ApplePayDxbMerchantID
      APPLE_PAY_ABD_MERCHANT_IDENTITY_CERT_ARN: !Ref ApplePayAbdMerchantIdentityCertARN
      APPLE_PAY_ABD_MERCHANT_ID: !Ref ApplePayAbdMerchantID
  CodeUri: lec-global/
  MemorySize: 256
  Handler: mpayWebHook_handler.webHook
  Policies:
    - LambdaInvokePolicy:
        FunctionName: !FindInMap [FunctionNameMap, !Ref EnvironmentName, LogServiceFunction]
    - S3CrudPolicy:
        BucketName: !Ref BeS3BucketName
    - AWSSecretsManagerGetSecretValuePolicy:
        SecretArn: !Ref MafPayAuthBasicPasswordARN
    - AWSSecretsManagerGetSecretValuePolicy:
        SecretArn: !Ref OmanMafPayAuthBasicPasswordARN
    - AWSSecretsManagerGetSecretValuePolicy:
        SecretArn: !Ref AbuDhabiMafPayAuthBasicPasswordARN
    - AWSSecretsManagerGetSecretValuePolicy:
        SecretArn: !Ref ApplePayDxbMerchantIdentityCertARN
    - AWSSecretsManagerGetSecretValuePolicy:
        SecretArn: !Ref ApplePayAbdMerchantIdentityCertARN
    - AWSSecretsManagerGetSecretValuePolicy:
        SecretArn: !Ref ShareCertARN
    - AWSSecretsManagerGetSecretValuePolicy:
        SecretArn: !Ref ShareKeyARN
    - LambdaInvokePolicy:
        FunctionName: !FindInMap [FunctionNameMap, !Ref EnvironmentName, CreateOrderAuditFunction]
    - LambdaInvokePolicy:
        FunctionName: !FindInMap [FunctionNameMap, !Ref EnvironmentName, CloseOrderInVivaFunction]
  Architectures:
    - x86_64
  Events:
    calcualteSignature:
      Type: Api
      Properties:
        Path: /maf-pay/webhook
        Method: post

  Outputs:
StateMachineArn:
  Value: !GetAtt WebHookStateMachine.Arn

Its failing with this reason: ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Invalid template resource property 'StateMachineArn'

I tried replacing !Ref WebHookStateMachine with !Ref StateMachineArn but it keeps failing.

In the code, after a condition is met, I call this function:

async function initiateRetryWorkflow(event) {
  log.info('*** Calling retry workflow ***');

  const params = {
    stateMachineArn: process.env.StateMachineArnVar,
    input: JSON.stringify(event),
  };

  await stepfunctions.startExecution(params).promise();
}
0

There are 0 answers