DataSource

Provides an AppSync DataSource.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var exampleTable = new Aws.DynamoDB.Table("exampleTable", new Aws.DynamoDB.TableArgs
        {
            Attributes = 
            {
                new Aws.DynamoDB.Inputs.TableAttributeArgs
                {
                    Name = "UserId",
                    Type = "S",
                },
            },
            HashKey = "UserId",
            ReadCapacity = 1,
            WriteCapacity = 1,
        });
        var exampleRole = new Aws.Iam.Role("exampleRole", new Aws.Iam.RoleArgs
        {
            AssumeRolePolicy = @"{
  ""Version"": ""2012-10-17"",
  ""Statement"": [
    {
      ""Action"": ""sts:AssumeRole"",
      ""Principal"": {
        ""Service"": ""appsync.amazonaws.com""
      },
      ""Effect"": ""Allow""
    }
  ]
}

",
        });
        var exampleRolePolicy = new Aws.Iam.RolePolicy("exampleRolePolicy", new Aws.Iam.RolePolicyArgs
        {
            Policy = exampleTable.Arn.Apply(arn => @$"{{
  ""Version"": ""2012-10-17"",
  ""Statement"": [
    {{
      ""Action"": [
        ""dynamodb:*""
      ],
      ""Effect"": ""Allow"",
      ""Resource"": [
        ""{arn}""
      ]
    }}
  ]
}}

"),
            Role = exampleRole.Id,
        });
        var exampleGraphQLApi = new Aws.AppSync.GraphQLApi("exampleGraphQLApi", new Aws.AppSync.GraphQLApiArgs
        {
            AuthenticationType = "API_KEY",
        });
        var exampleDataSource = new Aws.AppSync.DataSource("exampleDataSource", new Aws.AppSync.DataSourceArgs
        {
            ApiId = exampleGraphQLApi.Id,
            DynamodbConfig = new Aws.AppSync.Inputs.DataSourceDynamodbConfigArgs
            {
                TableName = exampleTable.Name,
            },
            ServiceRoleArn = exampleRole.Arn,
            Type = "AMAZON_DYNAMODB",
        });
    }

}
package main

import (
    "fmt"

    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/appsync"
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/dynamodb"
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/iam"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        exampleTable, err := dynamodb.NewTable(ctx, "exampleTable", &dynamodb.TableArgs{
            Attributes: dynamodb.TableAttributeArray{
                &dynamodb.TableAttributeArgs{
                    Name: pulumi.String("UserId"),
                    Type: pulumi.String("S"),
                },
            },
            HashKey:       pulumi.String("UserId"),
            ReadCapacity:  pulumi.Int(1),
            WriteCapacity: pulumi.Int(1),
        })
        if err != nil {
            return err
        }
        exampleRole, err := iam.NewRole(ctx, "exampleRole", &iam.RoleArgs{
            AssumeRolePolicy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", "  \"Version\": \"2012-10-17\",\n", "  \"Statement\": [\n", "    {\n", "      \"Action\": \"sts:AssumeRole\",\n", "      \"Principal\": {\n", "        \"Service\": \"appsync.amazonaws.com\"\n", "      },\n", "      \"Effect\": \"Allow\"\n", "    }\n", "  ]\n", "}\n", "\n")),
        })
        if err != nil {
            return err
        }
        _, err = iam.NewRolePolicy(ctx, "exampleRolePolicy", &iam.RolePolicyArgs{
            Policy: exampleTable.Arn.ApplyT(func(arn string) (string, error) {
                return fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", "  \"Version\": \"2012-10-17\",\n", "  \"Statement\": [\n", "    {\n", "      \"Action\": [\n", "        \"dynamodb:*\"\n", "      ],\n", "      \"Effect\": \"Allow\",\n", "      \"Resource\": [\n", "        \"", arn, "\"\n", "      ]\n", "    }\n", "  ]\n", "}\n", "\n"), nil
            }).(pulumi.StringOutput),
            Role: exampleRole.ID(),
        })
        if err != nil {
            return err
        }
        exampleGraphQLApi, err := appsync.NewGraphQLApi(ctx, "exampleGraphQLApi", &appsync.GraphQLApiArgs{
            AuthenticationType: pulumi.String("API_KEY"),
        })
        if err != nil {
            return err
        }
        _, err = appsync.NewDataSource(ctx, "exampleDataSource", &appsync.DataSourceArgs{
            ApiId: exampleGraphQLApi.ID(),
            DynamodbConfig: &appsync.DataSourceDynamodbConfigArgs{
                TableName: exampleTable.Name,
            },
            ServiceRoleArn: exampleRole.Arn,
            Type:           pulumi.String("AMAZON_DYNAMODB"),
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws

example_table = aws.dynamodb.Table("exampleTable",
    attributes=[{
        "name": "UserId",
        "type": "S",
    }],
    hash_key="UserId",
    read_capacity=1,
    write_capacity=1)
example_role = aws.iam.Role("exampleRole", assume_role_policy="""{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "appsync.amazonaws.com"
      },
      "Effect": "Allow"
    }
  ]
}

""")
example_role_policy = aws.iam.RolePolicy("exampleRolePolicy",
    policy=example_table.arn.apply(lambda arn: f"""{{
  "Version": "2012-10-17",
  "Statement": [
    {{
      "Action": [
        "dynamodb:*"
      ],
      "Effect": "Allow",
      "Resource": [
        "{arn}"
      ]
    }}
  ]
}}

"""),
    role=example_role.id)
example_graph_ql_api = aws.appsync.GraphQLApi("exampleGraphQLApi", authentication_type="API_KEY")
example_data_source = aws.appsync.DataSource("exampleDataSource",
    api_id=example_graph_ql_api.id,
    dynamodb_config={
        "table_name": example_table.name,
    },
    service_role_arn=example_role.arn,
    type="AMAZON_DYNAMODB")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const exampleTable = new aws.dynamodb.Table("example", {
    attributes: [{
        name: "UserId",
        type: "S",
    }],
    hashKey: "UserId",
    readCapacity: 1,
    writeCapacity: 1,
});
const exampleRole = new aws.iam.Role("example", {
    assumeRolePolicy: `{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "appsync.amazonaws.com"
      },
      "Effect": "Allow"
    }
  ]
}
`,
});
const exampleRolePolicy = new aws.iam.RolePolicy("example", {
    policy: pulumi.interpolate`{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "dynamodb:*"
      ],
      "Effect": "Allow",
      "Resource": [
        "${exampleTable.arn}"
      ]
    }
  ]
}
`,
    role: exampleRole.id,
});
const exampleGraphQLApi = new aws.appsync.GraphQLApi("example", {
    authenticationType: "API_KEY",
});
const exampleDataSource = new aws.appsync.DataSource("example", {
    apiId: exampleGraphQLApi.id,
    dynamodbConfig: {
        tableName: exampleTable.name,
    },
    serviceRoleArn: exampleRole.arn,
    type: "AMAZON_DYNAMODB",
});

Create a DataSource Resource

def DataSource(resource_name, opts=None, api_id=None, description=None, dynamodb_config=None, elasticsearch_config=None, http_config=None, lambda_config=None, name=None, service_role_arn=None, type=None, __props__=None);
func NewDataSource(ctx *Context, name string, args DataSourceArgs, opts ...ResourceOption) (*DataSource, error)
public DataSource(string name, DataSourceArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args DataSourceArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
opts ResourceOptions
A bag of options that control this resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args DataSourceArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args DataSourceArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

DataSource Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.

Inputs

The DataSource resource accepts the following input properties:

ApiId string

The API ID for the GraphQL API for the DataSource.

Type string

The type of the DataSource. Valid values: AWS_LAMBDA, AMAZON_DYNAMODB, AMAZON_ELASTICSEARCH, HTTP, NONE.

Description string

A description of the DataSource.

DynamodbConfig DataSourceDynamodbConfigArgs

DynamoDB settings. See below

ElasticsearchConfig DataSourceElasticsearchConfigArgs

Amazon Elasticsearch settings. See below

HttpConfig DataSourceHttpConfigArgs

HTTP settings. See below

LambdaConfig DataSourceLambdaConfigArgs

AWS Lambda settings. See below

Name string

A user-supplied name for the DataSource.

ServiceRoleArn string

The IAM service role ARN for the data source.

ApiId string

The API ID for the GraphQL API for the DataSource.

Type string

The type of the DataSource. Valid values: AWS_LAMBDA, AMAZON_DYNAMODB, AMAZON_ELASTICSEARCH, HTTP, NONE.

Description string

A description of the DataSource.

DynamodbConfig DataSourceDynamodbConfig

DynamoDB settings. See below

ElasticsearchConfig DataSourceElasticsearchConfig

Amazon Elasticsearch settings. See below

HttpConfig DataSourceHttpConfig

HTTP settings. See below

LambdaConfig DataSourceLambdaConfig

AWS Lambda settings. See below

Name string

A user-supplied name for the DataSource.

ServiceRoleArn string

The IAM service role ARN for the data source.

apiId string

The API ID for the GraphQL API for the DataSource.

type string

The type of the DataSource. Valid values: AWS_LAMBDA, AMAZON_DYNAMODB, AMAZON_ELASTICSEARCH, HTTP, NONE.

description string

A description of the DataSource.

dynamodbConfig DataSourceDynamodbConfig

DynamoDB settings. See below

elasticsearchConfig DataSourceElasticsearchConfig

Amazon Elasticsearch settings. See below

httpConfig DataSourceHttpConfig

HTTP settings. See below

lambdaConfig DataSourceLambdaConfig

AWS Lambda settings. See below

name string

A user-supplied name for the DataSource.

serviceRoleArn string

The IAM service role ARN for the data source.

api_id str

The API ID for the GraphQL API for the DataSource.

type str

The type of the DataSource. Valid values: AWS_LAMBDA, AMAZON_DYNAMODB, AMAZON_ELASTICSEARCH, HTTP, NONE.

description str

A description of the DataSource.

dynamodb_config Dict[DataSourceDynamodbConfig]

DynamoDB settings. See below

elasticsearch_config Dict[DataSourceElasticsearchConfig]

Amazon Elasticsearch settings. See below

http_config Dict[DataSourceHttpConfig]

HTTP settings. See below

lambda_config Dict[DataSourceLambdaConfig]

AWS Lambda settings. See below

name str

A user-supplied name for the DataSource.

service_role_arn str

The IAM service role ARN for the data source.

Outputs

All input properties are implicitly available as output properties. Additionally, the DataSource resource produces the following output properties:

Arn string

The ARN

Id string
The provider-assigned unique ID for this managed resource.
Arn string

The ARN

Id string
The provider-assigned unique ID for this managed resource.
arn string

The ARN

id string
The provider-assigned unique ID for this managed resource.
arn str

The ARN

id str
The provider-assigned unique ID for this managed resource.

Look up an Existing DataSource Resource

Get an existing DataSource resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: DataSourceState, opts?: CustomResourceOptions): DataSource
static get(resource_name, id, opts=None, api_id=None, arn=None, description=None, dynamodb_config=None, elasticsearch_config=None, http_config=None, lambda_config=None, name=None, service_role_arn=None, type=None, __props__=None);
func GetDataSource(ctx *Context, name string, id IDInput, state *DataSourceState, opts ...ResourceOption) (*DataSource, error)
public static DataSource Get(string name, Input<string> id, DataSourceState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

ApiId string

The API ID for the GraphQL API for the DataSource.

Arn string

The ARN

Description string

A description of the DataSource.

DynamodbConfig DataSourceDynamodbConfigArgs

DynamoDB settings. See below

ElasticsearchConfig DataSourceElasticsearchConfigArgs

Amazon Elasticsearch settings. See below

HttpConfig DataSourceHttpConfigArgs

HTTP settings. See below

LambdaConfig DataSourceLambdaConfigArgs

AWS Lambda settings. See below

Name string

A user-supplied name for the DataSource.

ServiceRoleArn string

The IAM service role ARN for the data source.

Type string

The type of the DataSource. Valid values: AWS_LAMBDA, AMAZON_DYNAMODB, AMAZON_ELASTICSEARCH, HTTP, NONE.

ApiId string

The API ID for the GraphQL API for the DataSource.

Arn string

The ARN

Description string

A description of the DataSource.

DynamodbConfig DataSourceDynamodbConfig

DynamoDB settings. See below

ElasticsearchConfig DataSourceElasticsearchConfig

Amazon Elasticsearch settings. See below

HttpConfig DataSourceHttpConfig

HTTP settings. See below

LambdaConfig DataSourceLambdaConfig

AWS Lambda settings. See below

Name string

A user-supplied name for the DataSource.

ServiceRoleArn string

The IAM service role ARN for the data source.

Type string

The type of the DataSource. Valid values: AWS_LAMBDA, AMAZON_DYNAMODB, AMAZON_ELASTICSEARCH, HTTP, NONE.

apiId string

The API ID for the GraphQL API for the DataSource.

arn string

The ARN

description string

A description of the DataSource.

dynamodbConfig DataSourceDynamodbConfig

DynamoDB settings. See below

elasticsearchConfig DataSourceElasticsearchConfig

Amazon Elasticsearch settings. See below

httpConfig DataSourceHttpConfig

HTTP settings. See below

lambdaConfig DataSourceLambdaConfig

AWS Lambda settings. See below

name string

A user-supplied name for the DataSource.

serviceRoleArn string

The IAM service role ARN for the data source.

type string

The type of the DataSource. Valid values: AWS_LAMBDA, AMAZON_DYNAMODB, AMAZON_ELASTICSEARCH, HTTP, NONE.

api_id str

The API ID for the GraphQL API for the DataSource.

arn str

The ARN

description str

A description of the DataSource.

dynamodb_config Dict[DataSourceDynamodbConfig]

DynamoDB settings. See below

elasticsearch_config Dict[DataSourceElasticsearchConfig]

Amazon Elasticsearch settings. See below

http_config Dict[DataSourceHttpConfig]

HTTP settings. See below

lambda_config Dict[DataSourceLambdaConfig]

AWS Lambda settings. See below

name str

A user-supplied name for the DataSource.

service_role_arn str

The IAM service role ARN for the data source.

type str

The type of the DataSource. Valid values: AWS_LAMBDA, AMAZON_DYNAMODB, AMAZON_ELASTICSEARCH, HTTP, NONE.

Supporting Types

DataSourceDynamodbConfig

See the input and output API doc for this type.

See the input and output API doc for this type.

See the input and output API doc for this type.

TableName string

Name of the DynamoDB table.

Region string

AWS region of Elasticsearch domain. Defaults to current region.

UseCallerCredentials bool

Set to true to use Amazon Cognito credentials with this data source.

TableName string

Name of the DynamoDB table.

Region string

AWS region of Elasticsearch domain. Defaults to current region.

UseCallerCredentials bool

Set to true to use Amazon Cognito credentials with this data source.

tableName string

Name of the DynamoDB table.

region string

AWS region of Elasticsearch domain. Defaults to current region.

useCallerCredentials boolean

Set to true to use Amazon Cognito credentials with this data source.

table_name str

Name of the DynamoDB table.

region str

AWS region of Elasticsearch domain. Defaults to current region.

useCallerCredentials bool

Set to true to use Amazon Cognito credentials with this data source.

DataSourceElasticsearchConfig

See the input and output API doc for this type.

See the input and output API doc for this type.

See the input and output API doc for this type.

Endpoint string

HTTP URL.

Region string

AWS region of Elasticsearch domain. Defaults to current region.

Endpoint string

HTTP URL.

Region string

AWS region of Elasticsearch domain. Defaults to current region.

endpoint string

HTTP URL.

region string

AWS region of Elasticsearch domain. Defaults to current region.

endpoint str

HTTP URL.

region str

AWS region of Elasticsearch domain. Defaults to current region.

DataSourceHttpConfig

See the input and output API doc for this type.

See the input and output API doc for this type.

See the input and output API doc for this type.

Endpoint string

HTTP URL.

Endpoint string

HTTP URL.

endpoint string

HTTP URL.

endpoint str

HTTP URL.

DataSourceLambdaConfig

See the input and output API doc for this type.

See the input and output API doc for this type.

See the input and output API doc for this type.

FunctionArn string

The ARN for the Lambda function.

FunctionArn string

The ARN for the Lambda function.

functionArn string

The ARN for the Lambda function.

function_arn str

The ARN for the Lambda function.

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.