Module: StackBuilder::LambdaPolicy
- Defined in:
- lib/modulator/stack/policies.rb
Class Method Summary collapse
-
.add_lambda_iam_role(function_name: nil) ⇒ Object
add inline iam role to lambda, NOTE: use the same role for all lambdas for now.
- .add_policy(policy, **opts) ⇒ Object
-
.cloudwatch(**opts) ⇒ Object
policy to access cloudwatch.
-
.dynamo_db(**opts) ⇒ Object
policy to access prefixed dynamo tables.
-
.secret_manager(**opts) ⇒ Object
TODO: add access to named secrets.
Class Method Details
.add_lambda_iam_role(function_name: nil) ⇒ Object
add inline iam role to lambda, NOTE: use the same role for all lambdas for now
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/modulator/stack/policies.rb', line 6 def add_lambda_iam_role(function_name: nil) StackBuilder.stack.add('LambdaRole', Humidifier::IAM::Role.new( assume_role_policy_document: { "Version" => "2012-10-17", 'Statement' => [ { "Action" => ["sts:AssumeRole"], "Effect" => "Allow", 'Principal' => { 'Service' => ["lambda.amazonaws.com"] } } ] }, policies: [] ) ) end |
.add_policy(policy, **opts) ⇒ Object
25 26 27 |
# File 'lib/modulator/stack/policies.rb', line 25 def add_policy(policy, **opts) StackBuilder.stack.resources['LambdaRole'].properties['policies'] << send(policy, opts) end |
.cloudwatch(**opts) ⇒ Object
policy to access cloudwatch
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/modulator/stack/policies.rb', line 30 def cloudwatch(**opts) { "policy_document" => { "Version" => "2012-10-17", 'Statement' => [ { "Sid" => "AllowLogCreation", "Action" => [ "logs:CreateLogStream", "logs:PutLogEvents", ], "Effect" => "Allow", "Resource" => Humidifier.fn.sub("arn:aws:logs:${AWS::Region}:${AWS::AccountId}:*") }, { "Sid" => "AllowLogGroupCreation", "Action" => [ "logs:CreateLogGroup", ], "Effect" => "Allow", "Resource" => "*" } ] }, "policy_name" => "cloud-watch-access" } end |
.dynamo_db(**opts) ⇒ Object
policy to access prefixed dynamo tables
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/modulator/stack/policies.rb', line 59 def dynamo_db(**opts) prefixes = opts[:prefixes] || [] prefix_separator = opts[:prefix_separator] || '-' wildcard = '*' if prefixes.any? prefixes.map!{|prefix| prefix == :app_name ? StackBuilder.stack.app_name.dasherize.split('-') : prefix} wildcard = "#{(prefixes << '*').join(prefix_separator)}" end { "policy_document" => { "Version" => "2012-10-17", 'Statement' => [ { "Sid" => "AllowAllActionsOnPrefixedTable", "Effect" => "Allow", "Action" => [ "dynamodb:*" ], "Resource" => Humidifier.fn.sub("arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/#{wildcard}") }, { "Sid" => "AdditionalPrivileges", "Effect" => "Allow", "Action" => [ "dynamodb:ListTables", "dynamodb:DescribeTable" ], "Resource" => "*" } ] }, "policy_name" => "dynamo-db-access" } end |
.secret_manager(**opts) ⇒ Object
TODO: add access to named secrets
95 96 97 |
# File 'lib/modulator/stack/policies.rb', line 95 def secret_manager(**opts) end |