Class: Kybus::CLI::AWSBotDeployer

Inherits:
BotDeployerBase show all
Defined in:
lib/kybus/cli/bot/deployers/aws_bot_deployer.rb

Instance Method Summary collapse

Methods inherited from BotDeployerBase

#account_id, #function_name

Constructor Details

#initialize(configs) ⇒ AWSBotDeployer

Returns a new instance of AWSBotDeployer.



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kybus/cli/bot/deployers/aws_bot_deployer.rb', line 61

def initialize(configs)
  configs['account_id'] = 
  super
  @role = ::Kybus::AWS::Role.new(configs, function_name, :lambda)
  @dynamo_policy = ::Kybus::AWS::Policy.new(configs, "#{function_name}-dynamo", make_dynamo_policy_document)
  @cloudwatch_policy = ::Kybus::AWS::Policy.new(configs, "#{function_name}-cloudwatch",
                                                make_log_groupo_policy_document)
  @role.add_policy(@dynamo_policy)
  @role.add_policy(@cloudwatch_policy)
  @log_group = ::Kybus::AWS::LogGroup.new(configs, function_name)
  @lambda = ::Kybus::AWS::Lambda.new(configs, function_name)
end

Instance Method Details

#create_or_update!Object



86
87
88
89
90
91
92
# File 'lib/kybus/cli/bot/deployers/aws_bot_deployer.rb', line 86

def create_or_update!
  @log_group.create_or_update!
  @dynamo_policy.create_or_update!
  @cloudwatch_policy.create_or_update!
  @role.create_or_update!
  @lambda.create_or_update!
end

#destroy!Object



74
75
76
77
78
79
80
# File 'lib/kybus/cli/bot/deployers/aws_bot_deployer.rb', line 74

def destroy!
  @lambda.destroy!
  @role.destroy!
  @dynamo_policy.destroy!
  @cloudwatch_policy.destroy!
  @log_group.destroy!
end

#make_dynamo_policy_documentObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kybus/cli/bot/deployers/aws_bot_deployer.rb', line 6

def make_dynamo_policy_document
  {
    Version: '2012-10-17',
    Statement: [
      {
        Effect: 'Allow',
        Action: [
          'dynamodb:BatchGetItem',
          'dynamodb:BatchWriteItem',
          'dynamodb:Describe*',
          'dynamodb:Get*',
          'dynamodb:List*',
          'dynamodb:PutItem',
          'dynamodb:Query',
          'dynamodb:Scan',
          'dynamodb:UpdateItem',
          'dynamodb:DeleteItem'
        ],
        Resource: "arn:aws:dynamodb:#{@region}:#{}:table/#{function_name}*"
      }, {
        Effect: :Allow,
        Action: [
          'dynamodb:Describe*',
          'dynamodb:Get*',
          'dynamodb:List*'
        ],
        Resource: '*'
      }
    ]
  }
end

#make_log_groupo_policy_documentObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/kybus/cli/bot/deployers/aws_bot_deployer.rb', line 38

def make_log_groupo_policy_document
  {
    Version: '2012-10-17',
    Statement: [
      {
        Effect: 'Allow',
        Action: 'logs:CreateLogGroup',
        Resource: "arn:aws:logs:#{@region}:#{}:*"
      },
      {
        Effect: 'Allow',
        Action: [
          'logs:CreateLogStream',
          'logs:PutLogEvents'
        ],
        Resource: [
          "arn:aws:logs:#{@region}:#{}:log-group:/aws/lambda/#{function_name}:*"
        ]
      }
    ]
  }
end

#urlObject



82
83
84
# File 'lib/kybus/cli/bot/deployers/aws_bot_deployer.rb', line 82

def url
  @lambda.url
end