aws.lambda.getInvocation
Invokes an AWS Lambda Function and returns its results. Use this data source to execute Lambda functions during Pulumi operations and use their results in other resources or outputs.
The Lambda function is invoked with RequestResponse invocation type.
Note: The
aws.lambda.Invocationdata source invokes the function during the firstapplyand every subsequentplanwhen the function is known.
Note: If you get a
KMSAccessDeniedException: Lambda was unable to decrypt the environment variables because KMS access was deniederror when invoking a Lambda function 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. (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
Basic Invocation
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as std from "@pulumi/std";
const example = aws.lambda.getInvocation({
functionName: exampleAwsLambdaFunction.functionName,
input: JSON.stringify({
operation: "getStatus",
id: "123456",
}),
});
export const result = example.then(example => std.jsondecode({
input: example.result,
})).then(invoke => invoke.result);
import pulumi
import json
import pulumi_aws as aws
import pulumi_std as std
example = aws.lambda.get_invocation(function_name=example_aws_lambda_function["functionName"],
input=json.dumps({
"operation": "getStatus",
"id": "123456",
}))
pulumi.export("result", std.jsondecode(input=example.result).result)
package main
import (
"encoding/json"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/lambda"
"github.com/pulumi/pulumi-std/sdk/go/std"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
tmpJSON0, err := json.Marshal(map[string]interface{}{
"operation": "getStatus",
"id": "123456",
})
if err != nil {
return err
}
json0 := string(tmpJSON0)
example, err := lambda.LookupInvocation(ctx, &lambda.LookupInvocationArgs{
FunctionName: exampleAwsLambdaFunction.FunctionName,
Input: json0,
}, nil)
if err != nil {
return err
}
ctx.Export("result", pulumi.Any(std.Jsondecode(ctx, &std.JsondecodeArgs{
Input: example.Result,
}, nil).Result))
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;
return await Deployment.RunAsync(() =>
{
var example = Aws.Lambda.GetInvocation.Invoke(new()
{
FunctionName = exampleAwsLambdaFunction.FunctionName,
Input = JsonSerializer.Serialize(new Dictionary<string, object?>
{
["operation"] = "getStatus",
["id"] = "123456",
}),
});
return new Dictionary<string, object?>
{
["result"] = Std.Jsondecode.Invoke(new()
{
Input = example.Apply(getInvocationResult => getInvocationResult.Result),
}).Apply(invoke => invoke.Result),
};
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lambda.LambdaFunctions;
import com.pulumi.aws.lambda.inputs.GetInvocationArgs;
import com.pulumi.std.StdFunctions;
import com.pulumi.std.inputs.JsondecodeArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var example = LambdaFunctions.getInvocation(GetInvocationArgs.builder()
.functionName(exampleAwsLambdaFunction.functionName())
.input(serializeJson(
jsonObject(
jsonProperty("operation", "getStatus"),
jsonProperty("id", "123456")
)))
.build());
ctx.export("result", StdFunctions.jsondecode(JsondecodeArgs.builder()
.input(example.result())
.build()).result());
}
}
variables:
example:
fn::invoke:
function: aws:lambda:getInvocation
arguments:
functionName: ${exampleAwsLambdaFunction.functionName}
input:
fn::toJSON:
operation: getStatus
id: '123456'
outputs:
result:
fn::invoke:
function: std:jsondecode
arguments:
input: ${example.result}
return: result
Dynamic Resource Configuration
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as std from "@pulumi/std";
// Get resource configuration from Lambda
const resourceConfig = aws.lambda.getInvocation({
functionName: "resource-config-generator",
qualifier: "production",
input: JSON.stringify({
environment: environment,
region: current.region,
service: "api",
}),
});
const config = resourceConfig.then(resourceConfig => std.jsondecode({
input: resourceConfig.result,
})).then(invoke => invoke.result);
// Use dynamic configuration
const example = new aws.elasticache.Cluster("example", {
clusterId: config?.cache?.clusterId,
engine: config?.cache?.engine,
nodeType: config?.cache?.nodeType,
numCacheNodes: config?.cache?.nodes,
parameterGroupName: config?.cache?.parameterGroup,
tags: config?.tags,
});
import pulumi
import json
import pulumi_aws as aws
import pulumi_std as std
# Get resource configuration from Lambda
resource_config = aws.lambda.get_invocation(function_name="resource-config-generator",
qualifier="production",
input=json.dumps({
"environment": environment,
"region": current["region"],
"service": "api",
}))
config = std.jsondecode(input=resource_config.result).result
# Use dynamic configuration
example = aws.elasticache.Cluster("example",
cluster_id=config["cache"]["clusterId"],
engine=config["cache"]["engine"],
node_type=config["cache"]["nodeType"],
num_cache_nodes=config["cache"]["nodes"],
parameter_group_name=config["cache"]["parameterGroup"],
tags=config["tags"])
package main
import (
"encoding/json"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/elasticache"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/lambda"
"github.com/pulumi/pulumi-std/sdk/go/std"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
tmpJSON0, err := json.Marshal(map[string]interface{}{
"environment": environment,
"region": current.Region,
"service": "api",
})
if err != nil {
return err
}
json0 := string(tmpJSON0)
// Get resource configuration from Lambda
resourceConfig, err := lambda.LookupInvocation(ctx, &lambda.LookupInvocationArgs{
FunctionName: "resource-config-generator",
Qualifier: pulumi.StringRef("production"),
Input: json0,
}, nil)
if err != nil {
return err
}
config := std.Jsondecode(ctx, &std.JsondecodeArgs{
Input: resourceConfig.Result,
}, nil).Result
// Use dynamic configuration
_, err = elasticache.NewCluster(ctx, "example", &elasticache.ClusterArgs{
ClusterId: pulumi.Any(config.Cache.ClusterId),
Engine: pulumi.Any(config.Cache.Engine),
NodeType: pulumi.Any(config.Cache.NodeType),
NumCacheNodes: pulumi.Any(config.Cache.Nodes),
ParameterGroupName: pulumi.Any(config.Cache.ParameterGroup),
Tags: pulumi.Any(config.Tags),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;
return await Deployment.RunAsync(() =>
{
// Get resource configuration from Lambda
var resourceConfig = Aws.Lambda.GetInvocation.Invoke(new()
{
FunctionName = "resource-config-generator",
Qualifier = "production",
Input = JsonSerializer.Serialize(new Dictionary<string, object?>
{
["environment"] = environment,
["region"] = current.Region,
["service"] = "api",
}),
});
var config = Std.Jsondecode.Invoke(new()
{
Input = resourceConfig.Apply(getInvocationResult => getInvocationResult.Result),
}).Apply(invoke => invoke.Result);
// Use dynamic configuration
var example = new Aws.ElastiCache.Cluster("example", new()
{
ClusterId = config?.Cache?.ClusterId,
Engine = config?.Cache?.Engine,
NodeType = config?.Cache?.NodeType,
NumCacheNodes = config?.Cache?.Nodes,
ParameterGroupName = config?.Cache?.ParameterGroup,
Tags = config?.Tags,
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lambda.LambdaFunctions;
import com.pulumi.aws.lambda.inputs.GetInvocationArgs;
import com.pulumi.std.StdFunctions;
import com.pulumi.std.inputs.JsondecodeArgs;
import com.pulumi.aws.elasticache.Cluster;
import com.pulumi.aws.elasticache.ClusterArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
// Get resource configuration from Lambda
final var resourceConfig = LambdaFunctions.getInvocation(GetInvocationArgs.builder()
.functionName("resource-config-generator")
.qualifier("production")
.input(serializeJson(
jsonObject(
jsonProperty("environment", environment),
jsonProperty("region", current.region()),
jsonProperty("service", "api")
)))
.build());
final var config = StdFunctions.jsondecode(JsondecodeArgs.builder()
.input(resourceConfig.result())
.build()).result();
// Use dynamic configuration
var example = new Cluster("example", ClusterArgs.builder()
.clusterId(config.cache().clusterId())
.engine(config.cache().engine())
.nodeType(config.cache().nodeType())
.numCacheNodes(config.cache().nodes())
.parameterGroupName(config.cache().parameterGroup())
.tags(config.tags())
.build());
}
}
resources:
# Use dynamic configuration
example:
type: aws:elasticache:Cluster
properties:
clusterId: ${config.cache.clusterId}
engine: ${config.cache.engine}
nodeType: ${config.cache.nodeType}
numCacheNodes: ${config.cache.nodes}
parameterGroupName: ${config.cache.parameterGroup}
tags: ${config.tags}
variables:
# Get resource configuration from Lambda
resourceConfig:
fn::invoke:
function: aws:lambda:getInvocation
arguments:
functionName: resource-config-generator
qualifier: production
input:
fn::toJSON:
environment: ${environment}
region: ${current.region}
service: api
config:
fn::invoke:
function: std:jsondecode
arguments:
input: ${resourceConfig.result}
return: result
Using getInvocation
Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.
function getInvocation(args: GetInvocationArgs, opts?: InvokeOptions): Promise<GetInvocationResult>
function getInvocationOutput(args: GetInvocationOutputArgs, opts?: InvokeOptions): Output<GetInvocationResult>def get_invocation(function_name: Optional[str] = None,
input: Optional[str] = None,
qualifier: Optional[str] = None,
region: Optional[str] = None,
opts: Optional[InvokeOptions] = None) -> GetInvocationResult
def get_invocation_output(function_name: Optional[pulumi.Input[str]] = None,
input: Optional[pulumi.Input[str]] = None,
qualifier: Optional[pulumi.Input[str]] = None,
region: Optional[pulumi.Input[str]] = None,
opts: Optional[InvokeOptions] = None) -> Output[GetInvocationResult]func LookupInvocation(ctx *Context, args *LookupInvocationArgs, opts ...InvokeOption) (*LookupInvocationResult, error)
func LookupInvocationOutput(ctx *Context, args *LookupInvocationOutputArgs, opts ...InvokeOption) LookupInvocationResultOutput> Note: This function is named LookupInvocation in the Go SDK.
public static class GetInvocation
{
public static Task<GetInvocationResult> InvokeAsync(GetInvocationArgs args, InvokeOptions? opts = null)
public static Output<GetInvocationResult> Invoke(GetInvocationInvokeArgs args, InvokeOptions? opts = null)
}public static CompletableFuture<GetInvocationResult> getInvocation(GetInvocationArgs args, InvokeOptions options)
public static Output<GetInvocationResult> getInvocation(GetInvocationArgs args, InvokeOptions options)
fn::invoke:
function: aws:lambda/getInvocation:getInvocation
arguments:
# arguments dictionaryThe following arguments are supported:
- Function
Name string - Name of the Lambda function.
- Input string
String in JSON format that is passed as payload to the Lambda function.
The following arguments are optional:
- Qualifier string
- Qualifier (a.k.a version) of the Lambda function. Defaults to
$LATEST. - Region string
- Region where this resource will be managed. Defaults to the Region set in the provider configuration.
- Function
Name string - Name of the Lambda function.
- Input string
String in JSON format that is passed as payload to the Lambda function.
The following arguments are optional:
- Qualifier string
- Qualifier (a.k.a version) of the Lambda function. Defaults to
$LATEST. - Region string
- Region where this resource will be managed. Defaults to the Region set in the provider configuration.
- function
Name String - Name of the Lambda function.
- input String
String in JSON format that is passed as payload to the Lambda function.
The following arguments are optional:
- qualifier String
- Qualifier (a.k.a version) of the Lambda function. Defaults to
$LATEST. - region String
- Region where this resource will be managed. Defaults to the Region set in the provider configuration.
- function
Name string - Name of the Lambda function.
- input string
String in JSON format that is passed as payload to the Lambda function.
The following arguments are optional:
- qualifier string
- Qualifier (a.k.a version) of the Lambda function. Defaults to
$LATEST. - region string
- Region where this resource will be managed. Defaults to the Region set in the provider configuration.
- function_
name str - Name of the Lambda function.
- input str
String in JSON format that is passed as payload to the Lambda function.
The following arguments are optional:
- qualifier str
- Qualifier (a.k.a version) of the Lambda function. Defaults to
$LATEST. - region str
- Region where this resource will be managed. Defaults to the Region set in the provider configuration.
- function
Name String - Name of the Lambda function.
- input String
String in JSON format that is passed as payload to the Lambda function.
The following arguments are optional:
- qualifier String
- Qualifier (a.k.a version) of the Lambda function. Defaults to
$LATEST. - region String
- Region where this resource will be managed. Defaults to the Region set in the provider configuration.
getInvocation Result
The following output properties are available:
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.
