Class: Jets::CLI::Lambda::Function
- Inherits:
-
Object
- Object
- Jets::CLI::Lambda::Function
- Includes:
- AwsServices
- Defined in:
- lib/jets/cli/lambda/function.rb
Instance Attribute Summary collapse
-
#function_name ⇒ Object
(also: #name)
readonly
Returns the value of attribute function_name.
Instance Method Summary collapse
-
#environment_variables ⇒ Object
Environment Variables.
- #environment_variables=(env_vars) ⇒ Object
-
#initialize(function_name) ⇒ Function
constructor
A new instance of Function.
- #provisioned_concurrency(qualifier = "live") ⇒ Object
- #provisioned_concurrency=(concurrency, qualifier = "live") ⇒ Object
-
#provisioned_concurrency_info(qualifier = "live") ⇒ Object
Provisioned Concurrency.
-
#provisioned_concurrency_unset?(qualifier = "live") ⇒ Boolean
Check if provisioned concurrency is unset.
-
#reserved_concurrency ⇒ Object
Reserved Concurrency.
- #reserved_concurrency=(concurrency) ⇒ Object
-
#reserved_concurrency_zero? ⇒ Boolean
Check if reserved concurrency is zero or not set.
Methods included from AwsServices
#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2
Methods included from AwsServices::StackStatus
Methods included from AwsServices::GlobalMemoist
Constructor Details
#initialize(function_name) ⇒ Function
Returns a new instance of Function.
7 8 9 |
# File 'lib/jets/cli/lambda/function.rb', line 7 def initialize(function_name) @function_name = function_name end |
Instance Attribute Details
#function_name ⇒ Object (readonly) Also known as: name
Returns the value of attribute function_name.
4 5 6 |
# File 'lib/jets/cli/lambda/function.rb', line 4 def function_name @function_name end |
Instance Method Details
#environment_variables ⇒ Object
Environment Variables
12 13 14 15 |
# File 'lib/jets/cli/lambda/function.rb', line 12 def environment_variables response = lambda_client.get_function_configuration(function_name: function_name) response.environment.variables.sort.to_h end |
#environment_variables=(env_vars) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jets/cli/lambda/function.rb', line 17 def environment_variables=(env_vars) current_env = environment_variables # Update existing vars and remove vars set to nil updated_env = current_env.merge(env_vars.stringify_keys) { |key, old_val, new_val| new_val.nil? ? nil : new_val } updated_env.compact! # Removes all key-value pairs where value is nil lambda_client.update_function_configuration( function_name: function_name, environment: {variables: updated_env} ) end |
#provisioned_concurrency(qualifier = "live") ⇒ Object
49 50 51 52 |
# File 'lib/jets/cli/lambda/function.rb', line 49 def provisioned_concurrency(qualifier = "live") info = provisioned_concurrency_info(qualifier) (info[:status] == "not set") ? nil : info[:requested] end |
#provisioned_concurrency=(concurrency, qualifier = "live") ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/jets/cli/lambda/function.rb', line 72 def provisioned_concurrency=(concurrency, qualifier = "live") if concurrency.nil? || concurrency == 0 begin lambda_client.delete_provisioned_concurrency_config( function_name: function_name, qualifier: qualifier ) rescue Aws::Lambda::Errors::ResourceNotFoundException end else lambda_client.put_provisioned_concurrency_config( function_name: function_name, qualifier: qualifier, provisioned_concurrent_executions: concurrency ) end end |
#provisioned_concurrency_info(qualifier = "live") ⇒ Object
Provisioned Concurrency
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/jets/cli/lambda/function.rb', line 55 def provisioned_concurrency_info(qualifier = "live") response = lambda_client.get_provisioned_concurrency_config( function_name: function_name, qualifier: qualifier ) { requested: response.requested_provisioned_concurrent_executions, allocated: response.allocated_provisioned_concurrent_executions, status: response.status } rescue Aws::Lambda::Errors::ResourceNotFoundException, Aws::Lambda::Errors::ProvisionedConcurrencyConfigNotFoundException { status: "not set" } end |
#provisioned_concurrency_unset?(qualifier = "live") ⇒ Boolean
Check if provisioned concurrency is unset
96 97 98 99 100 101 102 |
# File 'lib/jets/cli/lambda/function.rb', line 96 def provisioned_concurrency_unset?(qualifier = "live") pc = provisioned_concurrency(qualifier) pc.nil? || (pc[:requested] == 0 && pc[:allocated] == 0) rescue Aws::Lambda::Errors::ResourceNotFoundException, Aws::Lambda::Errors::ProvisionedConcurrencyConfigNotFoundException true # Treat not found as unset end |
#reserved_concurrency ⇒ Object
Reserved Concurrency
31 32 33 34 35 36 |
# File 'lib/jets/cli/lambda/function.rb', line 31 def reserved_concurrency response = lambda_client.get_function_concurrency(function_name: function_name) response.reserved_concurrent_executions rescue Aws::Lambda::Errors::ResourceNotFoundException nil # No reserved concurrency set implies no limit end |
#reserved_concurrency=(concurrency) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jets/cli/lambda/function.rb', line 38 def reserved_concurrency=(concurrency) if concurrency.nil? lambda_client.delete_function_concurrency(function_name: function_name) else lambda_client.put_function_concurrency( function_name: function_name, reserved_concurrent_executions: concurrency ) end end |
#reserved_concurrency_zero? ⇒ Boolean
Check if reserved concurrency is zero or not set
91 92 93 |
# File 'lib/jets/cli/lambda/function.rb', line 91 def reserved_concurrency_zero? reserved_concurrency == 0 end |