Skip to content

Data Source: awsLambdaInvocation

Use this data source to invoke custom lambda functions as data source. The lambda function is invoked with RequestResponse invocation type.

\~> NOTE: If you get a kmsAccessDeniedException:LambdaWasUnableToDecryptTheEnvironmentVariablesBecauseKmsAccessWasDenied error when invoking an awsLambdaFunction with environment variables, the IAM role associated with the function may have been deleted and recreated after the function was created. You can fix the problem two ways: 1) updating the function's role to another role and then updating it back again to the recreated role, or 2) by using Terraform to taint the function and apply your configuration again to recreate the function. (When you create a function, Lambda grants permissions on the KMS key to the function's IAM role. If the IAM role is recreated, the grant is no longer valid. Changing the function's role or recreating the function causes Lambda to update the grant.)

Example Usage

import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const dataAwsLambdaInvocationExample =
  new aws.dataAwsLambdaInvocation.DataAwsLambdaInvocation(this, "example", {
    functionName: "${aws_lambda_function.lambda_function_test.function_name}",
    input: '{\n  "key1": "value1",\n  "key2": "value2"\n}\n',
  });
new cdktf.TerraformOutput(this, "result_entry", {
  value: `\${jsondecode(${dataAwsLambdaInvocationExample.result})["key1"]}`,
});

Argument Reference

  • functionName - (Required) Name of the lambda function.
  • input - (Required) String in JSON format that is passed as payload to the lambda function.
  • qualifier - (Optional) Qualifier (a.k.a version) of the lambda function. Defaults to $latest.

Attributes Reference

  • result - String result of the lambda function invocation.