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
new DataSource(name: string, args: DataSourceArgs, opts?: CustomResourceOptions);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:
- Api
Id 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.
- Dynamodb
Config DataSource Dynamodb Config Args DynamoDB settings. See below
- Elasticsearch
Config DataSource Elasticsearch Config Args Amazon Elasticsearch settings. See below
- Http
Config DataSource Http Config Args HTTP settings. See below
- Lambda
Config DataSource Lambda Config Args AWS Lambda settings. See below
- Name string
A user-supplied name for the DataSource.
- Service
Role stringArn The IAM service role ARN for the data source.
- Api
Id 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.
- Dynamodb
Config DataSource Dynamodb Config DynamoDB settings. See below
- Elasticsearch
Config DataSource Elasticsearch Config Amazon Elasticsearch settings. See below
- Http
Config DataSource Http Config HTTP settings. See below
- Lambda
Config DataSource Lambda Config AWS Lambda settings. See below
- Name string
A user-supplied name for the DataSource.
- Service
Role stringArn The IAM service role ARN for the data source.
- api
Id 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.
- dynamodb
Config DataSource Dynamodb Config DynamoDB settings. See below
- elasticsearch
Config DataSource Elasticsearch Config Amazon Elasticsearch settings. See below
- http
Config DataSource Http Config HTTP settings. See below
- lambda
Config DataSource Lambda Config AWS Lambda settings. See below
- name string
A user-supplied name for the DataSource.
- service
Role stringArn 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[DataSource Dynamodb Config] DynamoDB settings. See below
- elasticsearch_
config Dict[DataSource Elasticsearch Config] Amazon Elasticsearch settings. See below
- http_
config Dict[DataSource Http Config] HTTP settings. See below
- lambda_
config Dict[DataSource Lambda Config] AWS Lambda settings. See below
- name str
A user-supplied name for the DataSource.
- service_
role_ strarn 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:
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): DataSourcestatic 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:
- Api
Id string The API ID for the GraphQL API for the DataSource.
- Arn string
The ARN
- Description string
A description of the DataSource.
- Dynamodb
Config DataSource Dynamodb Config Args DynamoDB settings. See below
- Elasticsearch
Config DataSource Elasticsearch Config Args Amazon Elasticsearch settings. See below
- Http
Config DataSource Http Config Args HTTP settings. See below
- Lambda
Config DataSource Lambda Config Args AWS Lambda settings. See below
- Name string
A user-supplied name for the DataSource.
- Service
Role stringArn 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 string The API ID for the GraphQL API for the DataSource.
- Arn string
The ARN
- Description string
A description of the DataSource.
- Dynamodb
Config DataSource Dynamodb Config DynamoDB settings. See below
- Elasticsearch
Config DataSource Elasticsearch Config Amazon Elasticsearch settings. See below
- Http
Config DataSource Http Config HTTP settings. See below
- Lambda
Config DataSource Lambda Config AWS Lambda settings. See below
- Name string
A user-supplied name for the DataSource.
- Service
Role stringArn 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 string The API ID for the GraphQL API for the DataSource.
- arn string
The ARN
- description string
A description of the DataSource.
- dynamodb
Config DataSource Dynamodb Config DynamoDB settings. See below
- elasticsearch
Config DataSource Elasticsearch Config Amazon Elasticsearch settings. See below
- http
Config DataSource Http Config HTTP settings. See below
- lambda
Config DataSource Lambda Config AWS Lambda settings. See below
- name string
A user-supplied name for the DataSource.
- service
Role stringArn 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[DataSource Dynamodb Config] DynamoDB settings. See below
- elasticsearch_
config Dict[DataSource Elasticsearch Config] Amazon Elasticsearch settings. See below
- http_
config Dict[DataSource Http Config] HTTP settings. See below
- lambda_
config Dict[DataSource Lambda Config] AWS Lambda settings. See below
- name str
A user-supplied name for the DataSource.
- service_
role_ strarn 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
- table_
name str Name of the DynamoDB table.
- region str
AWS region of Elasticsearch domain. Defaults to current region.
- use
Caller boolCredentials Set to
trueto use Amazon Cognito credentials with this data source.
DataSourceElasticsearchConfig
DataSourceHttpConfig
DataSourceLambdaConfig
- Function
Arn string The ARN for the Lambda function.
- Function
Arn string The ARN for the Lambda function.
- function
Arn 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
awsTerraform Provider.