AppSyncRdsDataSource
An AppSync datasource backed by RDS.
Example
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
declare const vpc: ec2.Vpc;
const databaseName = 'mydb';
const cluster = new rds.DatabaseCluster(this, 'Cluster', {
engine: rds.DatabaseClusterEngine.auroraPostgres({ version: rds.AuroraPostgresEngineVersion.VER_16_6 }),
writer: rds.ClusterInstance.serverlessV2('writer'),
vpc: vpc,
credentials: { username: 'clusteradmin' },
defaultDatabaseName: databaseName,
enableDataApi: true,
});
const secret = secretsmanager.Secret.fromSecretNameV2(this, 'Secret', 'db-secretName');
const api = new appsync.EventApi(this, 'EventApiRds', {
apiName: 'RdsEventApi',
});
const dataSource = api.addRdsDataSource('rdsds', cluster, secret, databaseName);
import aws_cdk.aws_secretsmanager as secretsmanager
# vpc: ec2.Vpc
database_name = "mydb"
cluster = rds.DatabaseCluster(self, "Cluster",
engine=rds.DatabaseClusterEngine.aurora_postgres(version=rds.AuroraPostgresEngineVersion.VER_16_6),
writer=rds.ClusterInstance.serverless_v2("writer"),
vpc=vpc,
credentials={"username": "clusteradmin"},
default_database_name=database_name,
enable_data_api=True
)
secret = secretsmanager.Secret.from_secret_name_v2(self, "Secret", "db-secretName")
api = appsync.EventApi(self, "EventApiRds",
api_name="RdsEventApi"
)
data_source = api.add_rds_data_source("rdsds", cluster, secret, database_name)
import software.amazon.awscdk.services.secretsmanager.*;
Vpc vpc;
String databaseName = "mydb";
DatabaseCluster cluster = DatabaseCluster.Builder.create(this, "Cluster")
.engine(DatabaseClusterEngine.auroraPostgres(AuroraPostgresClusterEngineProps.builder().version(AuroraPostgresEngineVersion.VER_16_6).build()))
.writer(ClusterInstance.serverlessV2("writer"))
.vpc(vpc)
.credentials(Map.of("username", "clusteradmin"))
.defaultDatabaseName(databaseName)
.enableDataApi(true)
.build();
ISecret secret = Secret.fromSecretNameV2(this, "Secret", "db-secretName");
EventApi api = EventApi.Builder.create(this, "EventApiRds")
.apiName("RdsEventApi")
.build();
AppSyncRdsDataSource dataSource = api.addRdsDataSource("rdsds", cluster, secret, databaseName);
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.SecretsManager;
Vpc vpc;
var databaseName = "mydb";
var cluster = new DatabaseCluster(this, "Cluster", new DatabaseClusterProps {
Engine = DatabaseClusterEngine.AuroraPostgres(new AuroraPostgresClusterEngineProps { Version = AuroraPostgresEngineVersion.VER_16_6 }),
Writer = ClusterInstance.ServerlessV2("writer"),
Vpc = vpc,
Credentials = new Dictionary<string, string> { { "username", "clusteradmin" } },
DefaultDatabaseName = databaseName,
EnableDataApi = true
});
var secret = Secret.FromSecretNameV2(this, "Secret", "db-secretName");
var api = new EventApi(this, "EventApiRds", new EventApiProps {
ApiName = "RdsEventApi"
});
var dataSource = api.AddRdsDataSource("rdsds", cluster, secret, databaseName);
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import secretsmanager "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc
databaseName := "mydb"
cluster := rds.NewDatabaseCluster(this, jsii.String("Cluster"), &DatabaseClusterProps{
Engine: rds.DatabaseClusterEngine_AuroraPostgres(&AuroraPostgresClusterEngineProps{
Version: rds.AuroraPostgresEngineVersion_VER_16_6(),
}),
Writer: rds.ClusterInstance_ServerlessV2(jsii.String("writer")),
Vpc: vpc,
Credentials: map[string]*string{
"username": jsii.String("clusteradmin"),
},
DefaultDatabaseName: databaseName,
EnableDataApi: jsii.Boolean(true),
})
secret := secretsmanager.Secret_FromSecretNameV2(this, jsii.String("Secret"), jsii.String("db-secretName"))
api := appsync.NewEventApi(this, jsii.String("EventApiRds"), &EventApiProps{
ApiName: jsii.String("RdsEventApi"),
})
dataSource := api.AddRdsDataSource(jsii.String("rdsds"), cluster, secret, databaseName)
Initializer
new AppSyncRdsDataSource(scope: Construct, id: string, props: AppSyncRdsDataSourceProps)
AppSyncRdsDataSource(scope: Construct, id: str, props: AppSyncRdsDataSourceProps)
new AppSyncRdsDataSource(Construct scope, String id, AppSyncRdsDataSourceProps props)
new AppSyncRdsDataSource(Construct scope, string id, AppSyncRdsDataSourceProps props)
NewAppSyncRdsDataSource(Scope Construct, Id *string, Props AppSyncRdsDataSourceProps)
Construct Props
databaseNameoptionalstringdatabase_nameoptionalstrdatabaseNameoptionalStringDatabaseNameoptionalstringDatabaseNameoptional*string= None#descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string= None#Default: id of data source
The only allowed pattern is: {[_A-Za-z][_0-9A-Za-z]*}. Any invalid characters will be automatically removed.
secretStoreISecretsecret_storeISecretsecretStoreISecretSecretStoreISecretSecretStoreISecretrequired#serverlessClusterIServerlessClusterserverless_clusterIServerlessClusterserverlessClusterIServerlessClusterServerlessClusterIServerlessClusterServerlessClusterIServerlessClusterrequired#Properties
grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipal#resourceCfnDataSourceresourceCfnDataSourceresourceCfnDataSourceResourceCfnDataSourceResourceCfnDataSource#Methods
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#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#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#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