【问题标题】:serverless step function state machine not created on sls deploy未在 sls deploy 上创建无服务器步进功能状态机
【发布时间】:2020-09-07 13:01:33
【问题描述】:

我正在尝试在我的无服务器应用程序中设置步进函数,但是当我将应用程序部署到 aws 时,没有为步进函数创建状态机。这是我的 lambda 文件。我不知道我在这方面做错了什么,但我的设置中肯定有一些东西导致状态机创建失败。

service: help-please

provider:
  name: aws
  versionFunctions: false
  runtime: nodejs12.x
  vpc:
    securityGroupIds:
      - sg
    subnetIds:
      - subnet
      - subnet
  stage: dev
  region: us-west-2
  iamRoleStatements:
    - Effect: 'Allow'
      Action:
        - 'xray:PutTraceSegments'
        - 'xray:PutTelemetryRecords'
        - 'sns:*'
        - 'states:*'
      Resource: '*'

functions:
upsertNewCustomerRecord:
    handler: .build/handler.upsertNewCustomerRecord
    iamRoleStatements:
      - Effect: 'Allow'
        Action:
          - logs:CreateLogGroup
          - logs:CreateLogStream
          - logs:PutLogEvents
          - logs:DescribeLogGroups
          - ec2:CreateNetworkInterface
          - ec2:DescribeNetworkInterfaces
          - ec2:DeleteNetworkInterface
          - cognito-idp:AdminInitiateAuth
          - ccognito-idp:DescribeUserPool
          - cognito-idp:DescribeUserPoolClient
          - cognito-idp:ListUserPoolClients
          - cognito-idp:ListUserPools
          - 'xray:PutTraceSegments'
          - 'xray:PutTelemetryRecords'
        Resource: '*'
  sendNewCustomerEmail:
    handler: .build/handler.sendNewCustomerEmail
    iamRoleStatements:
      - Effect: 'Allow'
        Action:
          - logs:DescribeLogGroups
          - logs:CreateLogGroup
          - logs:CreateLogStream
          - logs:PutLogEvents
          - ec2:CreateNetworkInterface
          - ec2:DescribeNetworkInterfaces
          - ec2:DeleteNetworkInterface
          - cognito-idp:AdminInitiateAuth
          - ccognito-idp:DescribeUserPool
          - cognito-idp:DescribeUserPoolClient
          - cognito-idp:ListUserPoolClients
          - cognito-idp:ListUserPools
          - 'xray:PutTraceSegments'
          - 'xray:PutTelemetryRecords'
        Resource: '*'
  upsertCognitoUser:
    handler: .build/handler.upsertCognitoUser
    iamRoleStatements:
      - Effect: 'Allow'
        Action:
          - logs:CreateLogGroup
          - logs:CreateLogStream
          - logs:PutLogEvents
          - logs:DescribeLogGroups
          - ec2:CreateNetworkInterface
          - ec2:DescribeNetworkInterfaces
          - ec2:DeleteNetworkInterface
          - cognito-idp:AdminInitiateAuth
          - ccognito-idp:DescribeUserPool
          - cognito-idp:DescribeUserPoolClient
          - cognito-idp:ListUserPoolClients
          - cognito-idp:ListUserPools
          - 'xray:PutTraceSegments'
          - 'xray:PutTelemetryRecords'
        Resource: '*'

stepFunctions:
  stateMachines:
    signupstepfunc:
      definition:
        Comment: 'Sign up step function'
        StartAt: UpsertNewCustomerRecord
        States:
          UpsertNewCustomerRecord:
            Type: Task
            Resource: 'arn'
            Next: SendNewCustomerEmail
          SendNewCustomerEmail:
            Type: Task
            Resource: 'arn'
            Next: UpsertCognitoUser
          UpsertCognitoUser:
            Type: Task
            Resource: 'arn'
            End: true

plugins:
  - serverless-plugin-typescript
  - serverless-offline
  - serverless-iam-roles-per-function
  - serverless-plugin-tracing
  - serverless-step-functions
  - serverless-pseudo-parameters
  - serverless-prune-plugin

【问题讨论】:

  • 您好,您在部署中遇到任何错误吗?

标签: node.js yaml serverless state-machine aws-step-functions


【解决方案1】:

根据提供的 yaml 文件,我认为问题可能是函数定义上的缩进:

functions:
upsertNewCustomerRecord:
    handler: .build/handler.upsertNewCustomerRecord
    iamRoleStatements:

必须替换为:

functions:
  upsertNewCustomerRecord:
    handler: .build/handler.upsertNewCustomerRecord
    iamRoleStatements:

您可以进行此更改并尝试一次吗?

【讨论】:

  • 实际上是在堆栈溢出时将代码粘贴到此处。所有格式都正确完成我实际上最终解决了这个问题。不过谢谢。
【解决方案2】:

不幸的是,我发现我在构建规范文件中使用了一个反斜杠,这就是导致这种情况发生的原因厌倦了这样做,因为在使用无服务器部署时,您的构建不会失败,您必须深入研究每个文件只是为了弄清楚发生了什么。只是要记住的事情。

【讨论】:

    【解决方案3】:

    在我的例子中,我只是忘了把 End: true 放在 step 函数的最后阶段。也许这会有所帮助。

    【讨论】:

    • 请为您的建议提供一个更全面的示例,例如;更详细的代码示例可以更好地让同胞理解。
    猜你喜欢
    • 2020-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    相关资源
    最近更新 更多