Skip to content
v2.276.0

LambdaDataSource ​

An AppSync datasource backed by a Lambda function.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_appsync as appsync } from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';
import { aws_lambda as lambda } from 'aws-cdk-lib';
import { aws_appsync as interfaces_appsync } from 'aws-cdk-lib/interfaces';

declare const function_: lambda.Function;
declare const graphQLApiRef: interfaces_appsync.IGraphQLApiRef;
declare const role: iam.Role;
const lambdaDataSource = new appsync.LambdaDataSource(this, 'MyLambdaDataSource', {
  api: graphQLApiRef,
  lambdaFunction: function_,

  // the properties below are optional
  description: 'description',
  metricsConfig: appsync.DataSourceMetricsConfig.ENABLED,
  name: 'name',
  serviceRole: role,
});
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_appsync as appsync
from aws_cdk import aws_iam as iam
from aws_cdk import aws_lambda as lambda_
from aws_cdk.interfaces import aws_appsync as interfaces_appsync

# function_: lambda.Function
# graph_ql_api_ref: interfaces_appsync.IGraphQLApiRef
# role: iam.Role

lambda_data_source = appsync.LambdaDataSource(self, "MyLambdaDataSource",
    api=graph_ql_api_ref,
    lambda_function=function_,

    # the properties below are optional
    description="description",
    metrics_config=appsync.DataSourceMetricsConfig.ENABLED,
    name="name",
    service_role=role
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.appsync.*;
import software.amazon.awscdk.services.iam.*;
import software.amazon.awscdk.services.lambda.*;
import software.amazon.awscdk.interfaces.appsync.*;

Function function_;
IGraphQLApiRef graphQLApiRef;
Role role;

LambdaDataSource lambdaDataSource = LambdaDataSource.Builder.create(this, "MyLambdaDataSource")
        .api(graphQLApiRef)
        .lambdaFunction(function_)

        // the properties below are optional
        .description("description")
        .metricsConfig(DataSourceMetricsConfig.ENABLED)
        .name("name")
        .serviceRole(role)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.AppSync;
using Amazon.CDK.AWS.IAM;
using Amazon.CDK.AWS.Lambda;
using Amazon.CDK.Interfaces.AppSync;

Function function_;
IGraphQLApiRef graphQLApiRef;
Role role;

var lambdaDataSource = new LambdaDataSource(this, "MyLambdaDataSource", new LambdaDataSourceProps {
    Api = graphQLApiRef,
    LambdaFunction = function_,

    // the properties below are optional
    Description = "description",
    MetricsConfig = DataSourceMetricsConfig.ENABLED,
    Name = "name",
    ServiceRole = role
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var function_ Function
var graphQLApiRef IGraphQLApiRef
var role Role

lambdaDataSource := awscdk.Aws_appsync.NewLambdaDataSource(this, jsii.String("MyLambdaDataSource"), &LambdaDataSourceProps{
	Api: graphQLApiRef,
	LambdaFunction: function_,

	// the properties below are optional
	Description: jsii.String("description"),
	MetricsConfig: awscdk.*Aws_appsync.DataSourceMetricsConfig_ENABLED,
	Name: jsii.String("name"),
	ServiceRole: role,
})

Initializer ​

ts
new LambdaDataSource(scope: Construct, id: string, props: LambdaDataSourceProps)
python
LambdaDataSource(scope: Construct, id: str, props: LambdaDataSourceProps)
java
new LambdaDataSource(Construct scope, String id, LambdaDataSourceProps props)
csharp
new LambdaDataSource(Construct scope, string id, LambdaDataSourceProps props)
go
NewLambdaDataSource(Scope Construct, Id *string, Props LambdaDataSourceProps)

Construct Props ​

The API to attach this data source to.
descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string= None#
the description of the data source.
lambdaFunctionIFunctionlambda_functionIFunctionlambdaFunctionIFunctionLambdaFunctionIFunctionLambdaFunctionIFunctionrequired#
The Lambda function to call to interact with this data source.
metricsConfigoptionalDataSourceMetricsConfigmetrics_configoptionalDataSourceMetricsConfigmetricsConfigoptionalDataSourceMetricsConfigMetricsConfigoptionalDataSourceMetricsConfigMetricsConfigoptionalDataSourceMetricsConfig#
Whether to enable enhanced metrics of the data source Value will be ignored, if `enhancedMetricsConfig.dataSourceLevelMetricsBehavior` on AppSync GraphqlApi construct is set to `FULL_REQUEST_DATA_SOURCE_METRICS`.

Default: no metrics configuration

nameoptionalstringnameoptionalstrnameoptionalStringNameoptionalstringNameoptional*string#
The name of the data source.

Default: id of data source

serviceRoleoptionalIRoleservice_roleoptionalIRoleserviceRoleoptionalIRoleServiceRoleoptionalIRoleServiceRoleoptionalIRole#
The IAM service role to be assumed by AppSync to interact with the data source.

Default: Create a new role

Properties ​

the underlying CFN data source resource.
grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipal#
the principal of the data source to be IGrantable.
namestringnamestrnameStringNamestringName*string#
the name of the data source.
nodeNodenodeNodenodeNodeNodeNodeNodeNode#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#
Uniquely identifies this class.

Methods ​

createFunction(id: string, props: BaseAppsyncFunctionProps): AppsyncFunctiondef create_function(self, id: str, props: BaseAppsyncFunctionProps) -> AppsyncFunctionpublic AppsyncFunction createFunction(String id, BaseAppsyncFunctionProps props)public AppsyncFunction CreateFunction(string id, BaseAppsyncFunctionProps props)func CreateFunction(Id *string, Props BaseAppsyncFunctionProps) AppsyncFunction#
creates a new appsync function for this datasource and API using the given properties.
createResolver(id: string, props: BaseResolverProps): Resolverdef create_resolver(self, id: str, props: BaseResolverProps) -> Resolverpublic Resolver createResolver(String id, BaseResolverProps props)public Resolver CreateResolver(string id, BaseResolverProps props)func CreateResolver(Id *string, Props BaseResolverProps) Resolver#
creates a new resolver for this datasource and API using the given properties.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) 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.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining