You can create an AWS CDK project entirely on the command. In this lesson, you will learn how to install the AWS CLI to view all of you existing S3 bucks and to initialize a CDK app with TypeScript.
You can find the CLI documentation here at Configuring the AWS CLI
This course is written using version 1 of the cdk, while at the time of writting this comment, we are on version 2. If you get stuck, you can refer to this modified code: import * as cdk from 'aws-cdk-lib'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import { Construct } from 'constructs'; import * as appsync from '@aws-cdk/aws-appsync-alpha';
export class BookStoreGraphqlApiStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props);
// The code that defines your stack goes here
// Create the AppSync GraphQL API
const api = new appsync.GraphqlApi(this, "MyApi", {
name: "my-book-api",
schema: appsync.SchemaFile.fromAsset("graphql/schema.graphql"),
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.API_KEY,
apiKeyConfig: {
name: "MyApiKey",
expires: cdk.Expiration.after(cdk.Duration.days(365)),
},
},
},
});
const listBooksLamdba = new lambda.Function(this, "ListBooksHandler", {
code: lambda.Code.fromAsset("functions"),
runtime: lambda.Runtime.NODEJS_14_X,
handler: "listBooks.handler",
});
const listBooksDataSource = api.addLambdaDataSource(
"listBooksDataSource",
listBooksLamdba,
);
listBooksDataSource.createResolver("ListBooksResolver", {
typeName: "Query",
fieldName: "listBooks",
});
} }