Class: AWSCDK::Lambda::Function

Inherits:
FunctionBase
  • Object
show all
Defined in:
lambda/function.rb

Overview

This construct does not yet reproduce all features from the underlying resource library.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, id, props) ⇒ Function

Returns a new instance of Function.

Parameters:



11
12
13
14
15
16
17
# File 'lambda/function.rb', line 11

def initialize(scope, id, props)
  props = props.is_a?(Hash) ? ::AWSCDK::Lambda::FunctionProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  Jsii::Type.check_type(id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "id")
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkZ1bmN0aW9uUHJvcHMifQ==")), "props")
  Jsii::Object.instance_method(:initialize).bind(self).call(scope, id, props)
end

Class Method Details

.classify_version_property(property_name, locked) ⇒ void

This method returns an undefined value.

Record whether specific properties in the AWS::Lambda::Function resource should also be associated to the Version resource.

See 'currentVersion' section in the module README for more details.

Parameters:

  • property_name (String)

    The property to classify.

  • locked (Boolean)

    whether the property should be associated to the version or not.



83
84
85
86
87
# File 'lambda/function.rb', line 83

def self.classify_version_property(property_name, locked)
  Jsii::Type.check_type(property_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "propertyName")
  Jsii::Type.check_type(locked, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJib29sZWFuIn0=")), "locked")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "classifyVersionProperty", [property_name, locked])
end

.from_function_arn(scope, id, function_arn) ⇒ AWSCDK::Lambda::IFunction

Import a lambda function into the CDK using its ARN.

For Function.addPermissions() to work on this imported lambda, make sure that is in the same account and region as the stack you are importing it into.

Parameters:

  • scope (Constructs::Construct)
  • id (String)
  • function_arn (String)

Returns:



98
99
100
101
102
103
# File 'lambda/function.rb', line 98

def self.from_function_arn(scope, id, function_arn)
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  Jsii::Type.check_type(id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "id")
  Jsii::Type.check_type(function_arn, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "functionArn")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "fromFunctionArn", [scope, id, function_arn])
end

.from_function_attributes(scope, id, attrs) ⇒ AWSCDK::Lambda::IFunction

Creates a Lambda function object which represents a function not defined within this stack.

For Function.addPermissions() to work on this imported lambda, set the sameEnvironment property to true if this imported lambda is in the same account and region as the stack you are importing it into.

Parameters:

  • scope (Constructs::Construct)

    The parent construct.

  • id (String)

    The name of the lambda construct.

  • attrs (AWSCDK::Lambda::FunctionAttributes)

    the attributes of the function to import.

Returns:



114
115
116
117
118
119
120
# File 'lambda/function.rb', line 114

def self.from_function_attributes(scope, id, attrs)
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  Jsii::Type.check_type(id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "id")
  attrs = attrs.is_a?(Hash) ? ::AWSCDK::Lambda::FunctionAttributes.new(**attrs.transform_keys(&:to_sym)) : attrs
  Jsii::Type.check_type(attrs, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkZ1bmN0aW9uQXR0cmlidXRlcyJ9")), "attrs")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "fromFunctionAttributes", [scope, id, attrs])
end

.from_function_name(scope, id, function_name) ⇒ AWSCDK::Lambda::IFunction

Import a lambda function into the CDK using its name.

Parameters:

  • scope (Constructs::Construct)
  • id (String)
  • function_name (String)

Returns:



128
129
130
131
132
133
# File 'lambda/function.rb', line 128

def self.from_function_name(scope, id, function_name)
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  Jsii::Type.check_type(id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "id")
  Jsii::Type.check_type(function_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "functionName")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "fromFunctionName", [scope, id, function_name])
end

.jsii_overridable_methodsObject



19
20
21
22
23
24
25
26
27
28
29
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lambda/function.rb', line 19

def self.jsii_overridable_methods
  {
    :node => { kind: :property, name: "node", is_optional: false },
    :env => { kind: :property, name: "env", is_optional: false },
    :physical_name => { kind: :property, name: "physicalName", is_optional: false },
    :stack => { kind: :property, name: "stack", is_optional: false },
    :architecture => { kind: :property, name: "architecture", is_optional: false },
    :can_create_permissions => { kind: :property, name: "canCreatePermissions", is_optional: false },
    :connections => { kind: :property, name: "connections", is_optional: false },
    :function_arn => { kind: :property, name: "functionArn", is_optional: false },
    :function_name => { kind: :property, name: "functionName", is_optional: false },
    :function_ref => { kind: :property, name: "functionRef", is_optional: false },
    :grant_principal => { kind: :property, name: "grantPrincipal", is_optional: false },
    :is_bound_to_vpc => { kind: :property, name: "isBoundToVpc", is_optional: false },
    :latest_version => { kind: :property, name: "latestVersion", is_optional: false },
    :permissions_node => { kind: :property, name: "permissionsNode", is_optional: false },
    :resource_arns_for_grant_invoke => { kind: :property, name: "resourceArnsForGrantInvoke", is_optional: false },
    :role => { kind: :property, name: "role", is_optional: true },
    :tenancy_config => { kind: :property, name: "tenancyConfig", is_optional: true },
    :current_version => { kind: :property, name: "currentVersion", is_optional: false },
    :log_group => { kind: :property, name: "logGroup", is_optional: false },
    :runtime => { kind: :property, name: "runtime", is_optional: false },
    :dead_letter_queue => { kind: :property, name: "deadLetterQueue", is_optional: true },
    :dead_letter_topic => { kind: :property, name: "deadLetterTopic", is_optional: true },
    :timeout => { kind: :property, name: "timeout", is_optional: true },
    :to_string => { kind: :method, name: "toString", is_optional: false },
    :with => { kind: :method, name: "with", is_optional: false },
    :apply_cross_stack_reference_strength => { kind: :method, name: "applyCrossStackReferenceStrength", is_optional: false },
    :apply_removal_policy => { kind: :method, name: "applyRemovalPolicy", is_optional: false },
    :generate_physical_name => { kind: :method, name: "generatePhysicalName", is_optional: false },
    :get_resource_arn_attribute => { kind: :method, name: "getResourceArnAttribute", is_optional: false },
    :get_resource_name_attribute => { kind: :method, name: "getResourceNameAttribute", is_optional: false },
    :add_event_source => { kind: :method, name: "addEventSource", is_optional: false },
    :add_event_source_mapping => { kind: :method, name: "addEventSourceMapping", is_optional: false },
    :add_function_url => { kind: :method, name: "addFunctionUrl", is_optional: false },
    :add_permission => { kind: :method, name: "addPermission", is_optional: false },
    :add_to_role_policy => { kind: :method, name: "addToRolePolicy", is_optional: false },
    :configure_async_invoke => { kind: :method, name: "configureAsyncInvoke", is_optional: false },
    :consider_warning_on_invoke_function_permissions => { kind: :method, name: "considerWarningOnInvokeFunctionPermissions", is_optional: false },
    :grant_invoke => { kind: :method, name: "grantInvoke", is_optional: false },
    :grant_invoke_composite_principal => { kind: :method, name: "grantInvokeCompositePrincipal", is_optional: false },
    :grant_invoke_latest_version => { kind: :method, name: "grantInvokeLatestVersion", is_optional: false },
    :grant_invoke_url => { kind: :method, name: "grantInvokeUrl", is_optional: false },
    :grant_invoke_version => { kind: :method, name: "grantInvokeVersion", is_optional: false },
    :metric => { kind: :method, name: "metric", is_optional: false },
    :metric_duration => { kind: :method, name: "metricDuration", is_optional: false },
    :metric_errors => { kind: :method, name: "metricErrors", is_optional: false },
    :metric_invocations => { kind: :method, name: "metricInvocations", is_optional: false },
    :metric_throttles => { kind: :method, name: "metricThrottles", is_optional: false },
    :warn_invoke_function_permissions => { kind: :method, name: "warnInvokeFunctionPermissions", is_optional: false },
    :add_alias => { kind: :method, name: "addAlias", is_optional: false },
    :add_environment => { kind: :method, name: "addEnvironment", is_optional: false },
    :add_layers => { kind: :method, name: "addLayers", is_optional: false },
    :invalidate_version_based_on => { kind: :method, name: "invalidateVersionBasedOn", is_optional: false },
  }
end

.metric_all(metric_name, props = nil) ⇒ AWSCDK::CloudWatch::Metric

Return the given named metric for this Lambda.

Parameters:

Returns:



140
141
142
143
144
145
# File 'lambda/function.rb', line 140

def self.metric_all(metric_name, props = nil)
  Jsii::Type.check_type(metric_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "metricName")
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "metricAll", [metric_name, props])
end

.metric_all_concurrent_executions(props = nil) ⇒ AWSCDK::CloudWatch::Metric

Note:

Default: max over 5 minutes

Metric for the number of concurrent executions across all Lambdas.

Parameters:

Returns:



152
153
154
155
156
# File 'lambda/function.rb', line 152

def self.metric_all_concurrent_executions(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "metricAllConcurrentExecutions", [props])
end

.metric_all_duration(props = nil) ⇒ AWSCDK::CloudWatch::Metric

Note:

Default: average over 5 minutes

Metric for the Duration executing all Lambdas.

Parameters:

Returns:



163
164
165
166
167
# File 'lambda/function.rb', line 163

def self.metric_all_duration(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "metricAllDuration", [props])
end

.metric_all_errors(props = nil) ⇒ AWSCDK::CloudWatch::Metric

Note:

Default: sum over 5 minutes

Metric for the number of Errors executing all Lambdas.

Parameters:

Returns:



174
175
176
177
178
# File 'lambda/function.rb', line 174

def self.metric_all_errors(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "metricAllErrors", [props])
end

.metric_all_invocations(props = nil) ⇒ AWSCDK::CloudWatch::Metric

Note:

Default: sum over 5 minutes

Metric for the number of invocations of all Lambdas.

Parameters:

Returns:



185
186
187
188
189
# File 'lambda/function.rb', line 185

def self.metric_all_invocations(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "metricAllInvocations", [props])
end

.metric_all_throttles(props = nil) ⇒ AWSCDK::CloudWatch::Metric

Note:

Default: sum over 5 minutes

Metric for the number of throttled invocations of all Lambdas.

Parameters:

Returns:



196
197
198
199
200
# File 'lambda/function.rb', line 196

def self.metric_all_throttles(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "metricAllThrottles", [props])
end

.metric_all_unreserved_concurrent_executions(props = nil) ⇒ AWSCDK::CloudWatch::Metric

Note:

Default: max over 5 minutes

Metric for the number of unreserved concurrent executions across all Lambdas.

Parameters:

Returns:



207
208
209
210
211
# File 'lambda/function.rb', line 207

def self.metric_all_unreserved_concurrent_executions(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Function", "metricAllUnreservedConcurrentExecutions", [props])
end

.PROPERTY_INJECTION_IDString

Uniquely identifies this class.

Returns:

  • (String)


364
365
366
# File 'lambda/function.rb', line 364

def self.PROPERTY_INJECTION_ID()
  Jsii::Kernel.instance.get_static("aws-cdk-lib.aws_lambda.Function", "PROPERTY_INJECTION_ID")
end

Instance Method Details

#add_alias(alias_name, options = nil) ⇒ AWSCDK::Lambda::Alias

Defines an alias for this function.

The alias will automatically be updated to point to the latest version of the function as it is being updated during a deployment.

fn = nil # AWSCDK::Lambda::Function


fn.add_alias("Live")

# Is equivalent to

AWSCDK::Lambda::Alias.new(self, "AliasLive", {
    alias_name: "Live",
    version: fn.current_version,
})

Parameters:

Returns:



744
745
746
747
748
749
# File 'lambda/function.rb', line 744

def add_alias(alias_name, options = nil)
  Jsii::Type.check_type(alias_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "aliasName")
  options = options.is_a?(Hash) ? ::AWSCDK::Lambda::AliasOptions.new(**options.transform_keys(&:to_sym)) : options
  Jsii::Type.check_type(options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkFsaWFzT3B0aW9ucyJ9")), "options") unless options.nil?
  jsii_call_method("addAlias", [alias_name, options])
end

#add_environment(key, value, options = nil) ⇒ AWSCDK::Lambda::Function

Adds an environment variable to this Lambda function.

If this is a ref to a Lambda function, this operation results in a no-op.

Parameters:

  • key (String)

    The environment variable key.

  • value (String)

    The environment variable's value.

  • options (AWSCDK::Lambda::EnvironmentOptions, nil) (defaults to: nil)

    Environment variable options.

Returns:

  • (AWSCDK::Lambda::Function)


759
760
761
762
763
764
765
# File 'lambda/function.rb', line 759

def add_environment(key, value, options = nil)
  Jsii::Type.check_type(key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "key")
  Jsii::Type.check_type(value, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "value")
  options = options.is_a?(Hash) ? ::AWSCDK::Lambda::EnvironmentOptions.new(**options.transform_keys(&:to_sym)) : options
  Jsii::Type.check_type(options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkVudmlyb25tZW50T3B0aW9ucyJ9")), "options") unless options.nil?
  jsii_call_method("addEnvironment", [key, value, options])
end

#add_event_source(source) ⇒ void

This method returns an undefined value.

Adds an event source to this function.

Event sources are implemented in the aws-cdk-lib/aws-lambda-event-sources module.

The following example adds an SQS Queue as an event source:

import { SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';
myFunction.addEventSource(new SqsEventSource(myQueue));

Parameters:



523
524
525
526
# File 'lambda/function.rb', line 523

def add_event_source(source)
  Jsii::Type.check_type(source, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLklFdmVudFNvdXJjZSJ9")), "source")
  jsii_call_method("addEventSource", [source])
end

#add_event_source_mapping(id, options) ⇒ AWSCDK::Lambda::EventSourceMapping

Adds an event source that maps to this AWS Lambda function.



533
534
535
536
537
538
# File 'lambda/function.rb', line 533

def add_event_source_mapping(id, options)
  Jsii::Type.check_type(id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "id")
  options = options.is_a?(Hash) ? ::AWSCDK::Lambda::EventSourceMappingOptions.new(**options.transform_keys(&:to_sym)) : options
  Jsii::Type.check_type(options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkV2ZW50U291cmNlTWFwcGluZ09wdGlvbnMifQ==")), "options")
  jsii_call_method("addEventSourceMapping", [id, options])
end

#add_function_url(options = nil) ⇒ AWSCDK::Lambda::FunctionURL

Adds a url to this lambda function.

Parameters:

Returns:



544
545
546
547
548
# File 'lambda/function.rb', line 544

def add_function_url(options = nil)
  options = options.is_a?(Hash) ? ::AWSCDK::Lambda::FunctionURLOptions.new(**options.transform_keys(&:to_sym)) : options
  Jsii::Type.check_type(options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkZ1bmN0aW9uVXJsT3B0aW9ucyJ9")), "options") unless options.nil?
  jsii_call_method("addFunctionUrl", [options])
end

#add_layers(*layers) ⇒ void

This method returns an undefined value.

Adds one or more Lambda Layers to this Lambda function.

Parameters:



771
772
773
774
775
776
# File 'lambda/function.rb', line 771

def add_layers(*layers)
  layers.each_with_index do |item, index|
    Jsii::Type.check_type(item, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLklMYXllclZlcnNpb24ifQ==")), "layers[#{index}]")
  end
  jsii_call_method("addLayers", [*layers])
end

#add_permission(id, permission) ⇒ void

This method returns an undefined value.

Adds a permission to the Lambda resource policy.

Parameters:

  • id (String)

    The id for the permission construct.

  • permission (AWSCDK::Lambda::Permission)

    The permission to grant to this Lambda function.

See Also:



556
557
558
559
560
561
# File 'lambda/function.rb', line 556

def add_permission(id, permission)
  Jsii::Type.check_type(id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "id")
  permission = permission.is_a?(Hash) ? ::AWSCDK::Lambda::Permission.new(**permission.transform_keys(&:to_sym)) : permission
  Jsii::Type.check_type(permission, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLlBlcm1pc3Npb24ifQ==")), "permission")
  jsii_call_method("addPermission", [id, permission])
end

#add_to_role_policy(statement) ⇒ void

This method returns an undefined value.

Adds a statement to the IAM role assumed by the instance.

Parameters:



567
568
569
570
# File 'lambda/function.rb', line 567

def add_to_role_policy(statement)
  Jsii::Type.check_type(statement, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLlBvbGljeVN0YXRlbWVudCJ9")), "statement")
  jsii_call_method("addToRolePolicy", [statement])
end

#apply_cross_stack_reference_strength(strength) ⇒ void

This method returns an undefined value.

Override the cross-stack reference strength for this resource.

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters:



453
454
455
456
# File 'lambda/function.rb', line 453

def apply_cross_stack_reference_strength(strength)
  Jsii::Type.check_type(strength, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5SZWZlcmVuY2VTdHJlbmd0aCJ9")), "strength")
  jsii_call_method("applyCrossStackReferenceStrength", [strength])
end

#apply_removal_policy(policy) ⇒ void

This method returns an undefined value.

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

Parameters:



470
471
472
473
# File 'lambda/function.rb', line 470

def apply_removal_policy(policy)
  Jsii::Type.check_type(policy, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5SZW1vdmFsUG9saWN5In0=")), "policy")
  jsii_call_method("applyRemovalPolicy", [policy])
end

#architectureAWSCDK::Lambda::Architecture

The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64).



259
260
261
# File 'lambda/function.rb', line 259

def architecture()
  jsii_get_property("architecture")
end

#can_create_permissionsBoolean

Whether the addPermission() call adds any permissions.

True for new Lambdas, false for version $LATEST and imported Lambdas from different accounts.

Returns:

  • (Boolean)


269
270
271
# File 'lambda/function.rb', line 269

def can_create_permissions()
  jsii_get_property("canCreatePermissions")
end

#configure_async_invoke(options) ⇒ void

This method returns an undefined value.

Configures options for asynchronous invocation.



576
577
578
579
580
# File 'lambda/function.rb', line 576

def configure_async_invoke(options)
  options = options.is_a?(Hash) ? ::AWSCDK::Lambda::EventInvokeConfigOptions.new(**options.transform_keys(&:to_sym)) : options
  Jsii::Type.check_type(options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkV2ZW50SW52b2tlQ29uZmlnT3B0aW9ucyJ9")), "options")
  jsii_call_method("configureAsyncInvoke", [options])
end

#connectionsAWSCDK::EC2::Connections

Access the Connections object.

Will fail if not a VPC-enabled Lambda Function



278
279
280
# File 'lambda/function.rb', line 278

def connections()
  jsii_get_property("connections")
end

#consider_warning_on_invoke_function_permissions(scope, action) ⇒ void

This method returns an undefined value.

A warning will be added to functions under the following conditions: - permissions that include lambda:InvokeFunction are added to the unqualified function.

  • function.currentVersion is invoked before or after the permission is created.

This applies only to permissions on Lambda functions, not versions or aliases. This function is overridden as a noOp for QualifiedFunctionBase.

Parameters:

  • scope (Constructs::Construct)
  • action (String)


592
593
594
595
596
# File 'lambda/function.rb', line 592

def consider_warning_on_invoke_function_permissions(scope, action)
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  Jsii::Type.check_type(action, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "action")
  jsii_call_method("considerWarningOnInvokeFunctionPermissions", [scope, action])
end

#current_versionAWSCDK::Lambda::Version

Returns a lambda.Version which represents the current version of this Lambda function. A new version will be created every time the function's configuration changes.

You can specify options for this version using the current_version_options prop when initializing the lambda.Function.



374
375
376
# File 'lambda/function.rb', line 374

def current_version()
  jsii_get_property("currentVersion")
end

#dead_letter_queueAWSCDK::SQS::IQueue?

The DLQ (as queue) associated with this Lambda Function (this is an optional attribute).

Returns:



402
403
404
# File 'lambda/function.rb', line 402

def dead_letter_queue()
  jsii_get_property("deadLetterQueue")
end

#dead_letter_topicAWSCDK::SNS::ITopic?

The DLQ (as topic) associated with this Lambda Function (this is an optional attribute).

Returns:



409
410
411
# File 'lambda/function.rb', line 409

def dead_letter_topic()
  jsii_get_property("deadLetterTopic")
end

#envAWSCDK::Interfaces::ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.



231
232
233
# File 'lambda/function.rb', line 231

def env()
  jsii_get_property("env")
end

#function_arnString

ARN of this function.

Returns:

  • (String)


285
286
287
# File 'lambda/function.rb', line 285

def function_arn()
  jsii_get_property("functionArn")
end

#function_nameString

Name of this function.

Returns:

  • (String)


292
293
294
# File 'lambda/function.rb', line 292

def function_name()
  jsii_get_property("functionName")
end

#function_refAWSCDK::Interfaces::AWSLambda::FunctionReference

A reference to a Function resource.



299
300
301
# File 'lambda/function.rb', line 299

def function_ref()
  jsii_get_property("functionRef")
end

#generate_physical_nameString

Returns:

  • (String)


476
477
478
# File 'lambda/function.rb', line 476

def generate_physical_name()
  jsii_call_method("generatePhysicalName", [])
end

#get_resource_arn_attribute(arn_attr, arn_components) ⇒ String

Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. bucket.bucketArn).

Normally, this token will resolve to arn_attr, but if the resource is referenced across environments, arn_components will be used to synthesize a concrete ARN with the resource's physical name. Make sure to reference this.physicalName in arn_components.

Parameters:

  • arn_attr (String)

    The CFN attribute which resolves to the ARN of the resource.

  • arn_components (AWSCDK::ARNComponents)

    The format of the ARN of this resource.

Returns:

  • (String)


490
491
492
493
494
495
# File 'lambda/function.rb', line 490

def get_resource_arn_attribute(arn_attr, arn_components)
  Jsii::Type.check_type(arn_attr, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "arnAttr")
  arn_components = arn_components.is_a?(Hash) ? ::AWSCDK::ARNComponents.new(**arn_components.transform_keys(&:to_sym)) : arn_components
  Jsii::Type.check_type(arn_components, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5Bcm5Db21wb25lbnRzIn0=")), "arnComponents")
  jsii_call_method("getResourceArnAttribute", [arn_attr, arn_components])
end

#get_resource_name_attribute(name_attr) ⇒ String

Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. bucket.bucketName).

Normally, this token will resolve to name_attr, but if the resource is referenced across environments, it will be resolved to this.physicalName, which will be a concrete name.

Parameters:

  • name_attr (String)

    The CFN attribute which resolves to the resource's name.

Returns:

  • (String)


505
506
507
508
# File 'lambda/function.rb', line 505

def get_resource_name_attribute(name_attr)
  Jsii::Type.check_type(name_attr, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "nameAttr")
  jsii_call_method("getResourceNameAttribute", [name_attr])
end

#grant_invoke(grantee) ⇒ AWSCDK::IAM::Grant

Grant the given identity permissions to invoke this Lambda.

[disable-awslint:no-grants]

Parameters:

Returns:



604
605
606
607
# File 'lambda/function.rb', line 604

def grant_invoke(grantee)
  Jsii::Type.check_type(grantee, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLklHcmFudGFibGUifQ==")), "grantee")
  jsii_call_method("grantInvoke", [grantee])
end

#grant_invoke_composite_principal(composite_principal) ⇒ Array<AWSCDK::IAM::Grant>

Grant multiple principals the ability to invoke this Lambda via CompositePrincipal.

[disable-awslint:no-grants]

Parameters:

Returns:



615
616
617
618
# File 'lambda/function.rb', line 615

def grant_invoke_composite_principal(composite_principal)
  Jsii::Type.check_type(composite_principal, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLkNvbXBvc2l0ZVByaW5jaXBhbCJ9")), "compositePrincipal")
  jsii_call_method("grantInvokeCompositePrincipal", [composite_principal])
end

#grant_invoke_latest_version(grantee) ⇒ AWSCDK::IAM::Grant

Grant the given identity permissions to invoke the $LATEST version or unqualified version of this Lambda.

[disable-awslint:no-grants]

Parameters:

Returns:



626
627
628
629
# File 'lambda/function.rb', line 626

def grant_invoke_latest_version(grantee)
  Jsii::Type.check_type(grantee, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLklHcmFudGFibGUifQ==")), "grantee")
  jsii_call_method("grantInvokeLatestVersion", [grantee])
end

#grant_invoke_url(grantee) ⇒ AWSCDK::IAM::Grant

Grant the given identity permissions to invoke this Lambda Function URL.

[disable-awslint:no-grants]

Parameters:

Returns:



637
638
639
640
# File 'lambda/function.rb', line 637

def grant_invoke_url(grantee)
  Jsii::Type.check_type(grantee, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLklHcmFudGFibGUifQ==")), "grantee")
  jsii_call_method("grantInvokeUrl", [grantee])
end

#grant_invoke_version(grantee, version) ⇒ AWSCDK::IAM::Grant

Grant the given identity permissions to invoke the given version of this Lambda.

[disable-awslint:no-grants]

Parameters:

Returns:



649
650
651
652
653
# File 'lambda/function.rb', line 649

def grant_invoke_version(grantee, version)
  Jsii::Type.check_type(grantee, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLklHcmFudGFibGUifQ==")), "grantee")
  Jsii::Type.check_type(version, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLklWZXJzaW9uIn0=")), "version")
  jsii_call_method("grantInvokeVersion", [grantee, version])
end

#grant_principalAWSCDK::IAM::IPrincipal

The principal this Lambda Function is running as.



306
307
308
# File 'lambda/function.rb', line 306

def grant_principal()
  jsii_get_property("grantPrincipal")
end

#invalidate_version_based_on(x) ⇒ void

This method returns an undefined value.

Mix additional information into the hash of the Version object.

The Lambda Function construct does its best to automatically create a new Version when anything about the Function changes (its code, its layers, any of the other properties).

However, you can sometimes source information from places that the CDK cannot look into, like the deploy-time values of SSM parameters. In those cases, the CDK would not force the creation of a new Version object when it actually should.

This method can be used to invalidate the current Version object. Pass in any string into this method, and make sure the string changes when you know a new Version needs to be created.

This method may be called more than once.

Parameters:

  • x (String)


797
798
799
800
# File 'lambda/function.rb', line 797

def invalidate_version_based_on(x)
  Jsii::Type.check_type(x, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "x")
  jsii_call_method("invalidateVersionBasedOn", [x])
end

#is_bound_to_vpcBoolean

Whether or not this Lambda function was bound to a VPC.

If this is false, trying to access the connections object will fail.

Returns:

  • (Boolean)


315
316
317
# File 'lambda/function.rb', line 315

def is_bound_to_vpc()
  jsii_get_property("isBoundToVpc")
end

#latest_versionAWSCDK::Lambda::IVersion

The $LATEST version of this function.

Note that this is reference to a non-specific AWS Lambda version, which means the function this version refers to can return different results in different invocations.

To obtain a reference to an explicit version which references the current function configuration, use lambdaFunction.currentVersion instead.



329
330
331
# File 'lambda/function.rb', line 329

def latest_version()
  jsii_get_property("latestVersion")
end

#log_groupAWSCDK::Logs::ILogGroup

The LogGroup where the Lambda function's logs are made available.

If either log_retention is set or this property is called, a CloudFormation custom resource is added to the stack that pre-creates the log group as part of the stack deployment, if it already doesn't exist, and sets the correct log retention period (never expire, by default).

Further, if the log group already exists and the log_retention is not set, the custom resource will reset the log retention to never expire even if it was configured with a different value.



388
389
390
# File 'lambda/function.rb', line 388

def log_group()
  jsii_get_property("logGroup")
end

#metric(metric_name, props = nil) ⇒ AWSCDK::CloudWatch::Metric

Return the given named metric for this Function.

Parameters:

Returns:



660
661
662
663
664
665
# File 'lambda/function.rb', line 660

def metric(metric_name, props = nil)
  Jsii::Type.check_type(metric_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "metricName")
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  jsii_call_method("metric", [metric_name, props])
end

#metric_duration(props = nil) ⇒ AWSCDK::CloudWatch::Metric

How long execution of this Lambda takes.

Average over 5 minutes

Parameters:

Returns:



673
674
675
676
677
# File 'lambda/function.rb', line 673

def metric_duration(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  jsii_call_method("metricDuration", [props])
end

#metric_errors(props = nil) ⇒ AWSCDK::CloudWatch::Metric

How many invocations of this Lambda fail.

Sum over 5 minutes

Parameters:

Returns:



685
686
687
688
689
# File 'lambda/function.rb', line 685

def metric_errors(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  jsii_call_method("metricErrors", [props])
end

#metric_invocations(props = nil) ⇒ AWSCDK::CloudWatch::Metric

How often this Lambda is invoked.

Sum over 5 minutes

Parameters:

Returns:



697
698
699
700
701
# File 'lambda/function.rb', line 697

def metric_invocations(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  jsii_call_method("metricInvocations", [props])
end

#metric_throttles(props = nil) ⇒ AWSCDK::CloudWatch::Metric

How often this Lambda is throttled.

Sum over 5 minutes

Parameters:

Returns:



709
710
711
712
713
# File 'lambda/function.rb', line 709

def metric_throttles(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NZXRyaWNPcHRpb25zIn0=")), "props") unless props.nil?
  jsii_call_method("metricThrottles", [props])
end

#nodeConstructs::Node

The tree node.

Returns:

  • (Constructs::Node)


216
217
218
# File 'lambda/function.rb', line 216

def node()
  jsii_get_property("node")
end

#permissions_nodeConstructs::Node

The construct node where permissions are attached.

Returns:

  • (Constructs::Node)


336
337
338
# File 'lambda/function.rb', line 336

def permissions_node()
  jsii_get_property("permissionsNode")
end

#physical_nameString

Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource.

This value will resolve to one of the following:

  • a concrete value (e.g. "my-awesome-bucket")
  • undefined, when a name should be generated by CloudFormation
  • a concrete name generated automatically during synthesis, in cross-environment scenarios.

Returns:

  • (String)


245
246
247
# File 'lambda/function.rb', line 245

def physical_name()
  jsii_get_property("physicalName")
end

#resource_arns_for_grant_invokeArray<String>

The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().

Returns:

  • (Array<String>)


343
344
345
# File 'lambda/function.rb', line 343

def resource_arns_for_grant_invoke()
  jsii_get_property("resourceArnsForGrantInvoke")
end

#roleAWSCDK::IAM::IRole?

Execution role associated with this function.

Returns:



350
351
352
# File 'lambda/function.rb', line 350

def role()
  jsii_get_property("role")
end

#runtimeAWSCDK::Lambda::Runtime

The runtime configured for this lambda.



395
396
397
# File 'lambda/function.rb', line 395

def runtime()
  jsii_get_property("runtime")
end

#stackAWSCDK::Stack

The stack in which this resource is defined.

Returns:



252
253
254
# File 'lambda/function.rb', line 252

def stack()
  jsii_get_property("stack")
end

#tenancy_configAWSCDK::Lambda::TenancyConfig?

The tenancy configuration for this function.



357
358
359
# File 'lambda/function.rb', line 357

def tenancy_config()
  jsii_get_property("tenancyConfig")
end

#timeoutAWSCDK::Duration?

The timeout configured for this lambda.

Returns:



416
417
418
# File 'lambda/function.rb', line 416

def timeout()
  jsii_get_property("timeout")
end

#to_stringString

Returns a string representation of this construct.

Returns:

  • (String)


423
424
425
# File 'lambda/function.rb', line 423

def to_string()
  jsii_call_method("toString", [])
end

#warn_invoke_function_permissions(scope) ⇒ void

This method returns an undefined value.

Parameters:

  • scope (Constructs::Construct)


717
718
719
720
# File 'lambda/function.rb', line 717

def warn_invoke_function_permissions(scope)
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  jsii_call_method("warnInvokeFunctionPermissions", [scope])
end

#with(*mixins) ⇒ Constructs::IConstruct

Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

Parameters:

  • mixins (Array<Constructs::IMixin>)

Returns:

  • (Constructs::IConstruct)


436
437
438
439
440
441
# File 'lambda/function.rb', line 436

def with(*mixins)
  mixins.each_with_index do |item, index|
    Jsii::Type.check_type(item, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLklNaXhpbiJ9")), "mixins[#{index}]")
  end
  jsii_call_method("with", [*mixins])
end