小编Nim*_*ale的帖子

我应该总是使用pillar.get而不是支柱['foo']吗?

我在支柱文档中看到有两种方法可以在SLS中引用支柱数据.

{{ pillar['foo'] }}
Run Code Online (Sandbox Code Playgroud)

{{ salt['pillar.get']('foo') }}
Run Code Online (Sandbox Code Playgroud)

pillar.get方法更好地处理嵌套的柱状数据,并允许在柱子中找不到数据时指定默认值.但它有点打字,我发现第一种方法更容易阅读.

因此,最好的做法是始终使用pillar.get方法或使用柱['foo']可接受,特别是在处理非嵌套柱数据时.

我怀疑总是使用pillar.get方法是最好的,因为在处理嵌套的柱状数据时使用它或者你想设置默认值是有意义的.并且最好只为您提供一种方法.但我想得到其他人的想法.

Thansk,乔

salt-stack

12
推荐指数
2
解决办法
7587
查看次数

Python格式最佳实践

我刚刚开始使用Python,并且对于在字符串上使用.format时遇到了关于最佳实践(或至少是常见实践)的问题.

我的问题主要是你何时使用空白大括号而不是索引号与名称.

例如,如果您想要包含在字符串中的单个变量,那么您会做什么?

print "I {} Stack Overflow".format(var)
print "I {0} Stack Overflow".format(var)
print "I {verb} Stack Overflow".format(verb = var)
Run Code Online (Sandbox Code Playgroud)

如果您想要包含多个变量,这会改变吗?也许可以将{}包含在单个var中,但从不包含多个vars?

任何想法或见解将非常感激.

谢谢!

python format

6
推荐指数
1
解决办法
3846
查看次数

DependOn 和 Cloudformation 自定义资源

根据我的理解,如果更新了指定了 DependsOn 的资源,则应该更新它所依赖的资源。我在某些资源中看到了这一点,但它似乎不适用于自定义资源。

我正在使用 APIGateway 并尝试在与阶段相关的资源更新时使用自定义资源来部署阶段。这是因为当需要部署更新时,包含的AWS::ApiGateway::Stage&AWS::ApiGateway::Deployment似乎不能很好地工作。

我有以下模板(为了便于参考而进行了剪裁):

<snip>
pipelineMgrStateMachine:
  Type: AWS::StepFunctions::StateMachine
  Properties:
    <snip>

webhookEndPointMethod:
  Type: AWS::ApiGateway::Method
  DependsOn: pipelineMgrStateMachine
  Properties:
    RestApiId: !Ref pipelineMgrGW
    ResourceId: !Ref webhookEndPointResource
    HttpMethod: POST
    AuthorizationType: NONE
    Integration:
      Type: AWS
      IntegrationHttpMethod: POST
      Uri: !Sub arn:aws:apigateway:${AWS::Region}:states:action/StartExecution
      Credentials: !GetAtt pipelineMgrGWRole.Arn
      PassthroughBehavior: WHEN_NO_TEMPLATES
      RequestTemplates:
        application/json: !Sub |
          {
            "input": "$util.escapeJavaScript($input.json('$'))",
            "name": "$context.requestId",
            "stateMachineArn": "${pipelineMgrStateMachine}"
          }
      IntegrationResponses:
        - StatusCode: 200
    MethodResponses:
      - StatusCode: 200

pipelineMgrStageDeployer:
  Type: Custom::pipelineMgrStageDeployer
  DependsOn: webhookEndPointMethod
  Properties:
    ServiceToken: !GetAtt apiGwStageDeployer.Arn
    StageName: pipelinemgr
    RestApiId: !Ref pipelineMgrGW …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-cloudformation

1
推荐指数
1
解决办法
3032
查看次数