AWS::AppSync::DataSource - AWS CloudFormation

AWS::AppSync::DataSource

The AWS::AppSync::DataSource resource creates data sources for resolvers in AWS AppSync to connect to, such as Amazon DynamoDB, AWS Lambda, and Amazon OpenSearch Service. Resolvers use these data sources to fetch data when clients make GraphQL calls.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

{ "Type" : "AWS::AppSync::DataSource", "Properties" : { "ApiId" : String, "Description" : String, "DynamoDBConfig" : DynamoDBConfig, "EventBridgeConfig" : EventBridgeConfig, "HttpConfig" : HttpConfig, "LambdaConfig" : LambdaConfig, "MetricsConfig" : String, "Name" : String, "OpenSearchServiceConfig" : OpenSearchServiceConfig, "RelationalDatabaseConfig" : RelationalDatabaseConfig, "ServiceRoleArn" : String, "Type" : String } }

Properties

ApiId

Unique AWS AppSync GraphQL API identifier where this data source will be created.

Required: Yes

Type: String

Update requires: Replacement

Description

The description of the data source.

Required: No

Type: String

Update requires: No interruption

DynamoDBConfig

AWS Region and TableName for an Amazon DynamoDB table in your account.

Required: No

Type: DynamoDBConfig

Update requires: No interruption

EventBridgeConfig

An EventBridge configuration that contains a valid ARN of an event bus.

Required: No

Type: EventBridgeConfig

Update requires: No interruption

HttpConfig

Endpoints for an HTTP data source.

Required: No

Type: HttpConfig

Update requires: No interruption

LambdaConfig

An ARN of a Lambda function in valid ARN format. This can be the ARN of a Lambda function that exists in the current account or in another account.

Required: No

Type: LambdaConfig

Update requires: No interruption

MetricsConfig

Enables or disables enhanced data source metrics for specified data sources. Note that MetricsConfig won't be used unless the dataSourceLevelMetricsBehavior value is set to PER_DATA_SOURCE_METRICS. If the dataSourceLevelMetricsBehavior is set to FULL_REQUEST_DATA_SOURCE_METRICS instead, MetricsConfig will be ignored. However, you can still set its value.

MetricsConfig can be ENABLED or DISABLED.

Required: No

Type: String

Allowed values: DISABLED | ENABLED

Update requires: No interruption

Name

Friendly name for you to identify your AppSync data source after creation.

Required: Yes

Type: String

Update requires: Replacement

OpenSearchServiceConfig

AWS Region and Endpoints for an Amazon OpenSearch Service domain in your account.

Required: No

Type: OpenSearchServiceConfig

Update requires: No interruption

RelationalDatabaseConfig

Relational Database configuration of the relational database data source.

Required: No

Type: RelationalDatabaseConfig

Update requires: No interruption

ServiceRoleArn

The AWS Identity and Access Management service role ARN for the data source. The system assumes this role when accessing the data source.

Required if Type is specified as AWS_LAMBDA, AMAZON_DYNAMODB, AMAZON_ELASTICSEARCH, AMAZON_EVENTBRIDGE, or AMAZON_OPENSEARCH_SERVICE.

Required: Conditional

Type: String

Update requires: No interruption

Type

The type of the data source.

  • AWS_LAMBDA: The data source is an AWS Lambda function.

  • AMAZON_DYNAMODB: The data source is an Amazon DynamoDB table.

  • AMAZON_ELASTICSEARCH: The data source is an Amazon OpenSearch Service domain.

  • AMAZON_EVENTBRIDGE: The data source is an Amazon EventBridge event bus.

  • AMAZON_OPENSEARCH_SERVICE: The data source is an Amazon OpenSearch Service domain.

  • AMAZON_BEDROCK_RUNTIME: The data source is the Amazon Bedrock runtime.

  • NONE: There is no data source. This type is used when you wish to invoke a GraphQL operation without connecting to a data source, such as performing data transformation with resolvers or triggering a subscription to be invoked from a mutation.

  • HTTP: The data source is an HTTP endpoint.

  • RELATIONAL_DATABASE: The data source is a relational database.

Required: Yes

Type: String

Update requires: No interruption

Return values

Ref

When you pass the logical ID of an AWS::AppSync::DataSource resource to the intrinsic Ref function, the function returns the ARN of the Data Source, such as arn:aws:appsync:us-east-1:123456789012:apis/graphqlapiid/datasources/datasourcename.

For more information about using the Ref function, see Ref.

Fn::GetAtt

Fn::GetAtt returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

For more information about using Fn::GetAtt, see Fn::GetAtt.

DataSourceArn

The Amazon Resource Name (ARN) of the API key, such as arn:aws:appsync:us-east-1:123456789012:apis/graphqlapiid/datasources/datasourcename.

Name

Friendly name for you to identify your AWS AppSync data source after creation.

Examples

Data Source Creation Example

The following example creates a data source and associates it with an existing GraphQL API by passing the GraphQL API ID as a parameter.

YAML

Parameters: graphQlApiId: Type: String dataSourceName: Type: String dataSourceDescription: Type: String serviceRoleArn: Type: String lambdaFunctionArn: Type: String Resources: DataSource: Type: AWS::AppSync::DataSource Properties: ApiId: Ref: graphQlApiId Name: Ref: dataSourceName Description: Ref: dataSourceDescription Type: "AWS_LAMBDA" ServiceRoleArn: Ref: serviceRoleArn LambdaConfig: LambdaFunctionArn: Ref: lambdaFunctionArn

JSON

{ "Parameters": { "graphQlApiId": { "Type": "String" }, "dataSourceName": { "Type": "String" }, "dataSourceDescription": { "Type": "String" }, "serviceRoleArn": { "Type": "String" }, "lambdaFunctionArn": { "Type": "String" } }, "Resources": { "DataSource": { "Type": "AWS::AppSync::DataSource", "Properties": { "ApiId": { "Ref": "graphQlApiId" }, "Name": { "Ref": "dataSourceName" }, "Description": { "Ref": "dataSourceDescription" }, "Type": "AWS_LAMBDA", "ServiceRoleArn": { "Ref": "serviceRoleArn" }, "LambdaConfig": { "LambdaFunctionArn": { "Ref": "lambdaFunctionArn" } } } } } }

See also