elijahchancey/pretty_cloudformation

embedded python code should be passed to yapf

Opened this issue · 1 comments

these options should be used:
--style='{based_on_style: pep8, indent_width: 4, column_limit:175}'

Example template:

AWSTemplateFormatVersion: '2010-09-09'
Description: Send a Slack notification if Expensive Instances are running.
Resources:
  InvokeLambdaPermission:
    Properties:
      Action: lambda:InvokeFunction
      FunctionName:
        Fn::GetAtt:
        - ec2ExpensiveInstancesAlarm
        - Arn
      Principal: events.amazonaws.com
      SourceArn:
        Fn::GetAtt:
        - ec2ExpensiveInstancesAlarmRule
        - Arn
    Type: AWS::Lambda::Permission
  LambdaExecutionRole:
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Action:
          - sts:AssumeRole
          Effect: Allow
          Principal:
            Service:
            - lambda.amazonaws.com
        Version: '2012-10-17'
      ManagedPolicyArns:
      - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
      Path: /
      Policies:
      - PolicyDocument:
          Statement:
          - Action:
            - ec2:DescribeInstances
            Effect: Allow
            Resource: '*'
          Version: '2012-10-17'
        PolicyName: root
    Type: AWS::IAM::Role
  ec2ExpensiveInstancesAlarm:
    Properties:
      Code:
        ZipFile: !Sub |
          def lambda_handler(event, context):
            print ('test'  )
            return "test"
      Handler: index.lambda_handler
      MemorySize: 128
      Role: !GetAtt 'LambdaExecutionRole.Arn'
      Runtime: python3.6
    Type: AWS::Lambda::Function
  ec2ExpensiveInstancesAlarmRule:
    Properties:
      ScheduleExpression: cron(0 * * * ? *)
      Targets:
      - Arn:
          Fn::GetAtt:
          - ec2ExpensiveInstancesAlarm
          - Arn
        Id: ec2ExpensiveInstancesAlarmScheduler
    Type: AWS::Events::Rule