AWS无服务器多个Yaml Java

问题描述

我有一个AWS示例无服务器应用程序,其中有单个yaml文件以及多个处理程序。

问题在于template.yaml不断增长,如何为每个处理程序或一组处理程序分隔yaml,以便于管理。

解决方法

对于我们的项目,我们开始以另一种方式将主要的YAML分为多个:

  • 所有lambda仍在serverless.yml文件中描述

  • 在serverless.yml中

    resources:
     - ${file(./sls-config/cognito-user-pools-authorizer.yml)}
     - ${file(./sls-config/aurora.yml)}
     - ${file(./sls-config/bucket.yml)}
     - ${file(./sls-config/queues.yml)}
     - ${file(./sls-config/alarms.yml)}
     - ${file(./sls-config/roles.yml)}
     - ${file(./sls-config/outputs.yml)}
    

是的,将资源分配给您。

  • alarm.yml

    Resources:
       SQSAlarmTopic:
           Type: AWS::SNS::Topic
           Properties:
                 DisplayName: ${self:provider.prefix}-sqs-alarm-topic
                 TopicName: ${self:provider.prefix}-sqs-alarm-topic
                 Subscription:
                   - Endpoint: example-email@mail.com
                     Protocol: email
                 Tags: ${self:custom.sqsTags}
    

    以此类推。

  • outputs.yml

    Outputs:
        CognitoUserPoolId:
            Value: ${self:custom.userPool}
        CognitoUserPoolClientId:
            Value: ${self:custom.userPoolClientId}
        DSClusterID:
            Description: "RDS Cluster "
            Value: { Ref: RDSCluster }
        DBAddress:
            Value: !GetAtt RDSCluster.Endpoint.Address
    

custom和provide中的变量可以通过sub_configs.yml轻松使用。

请注意yaml文件中的间距/填充:)