Deep Dive 2 Kihara, Takuya 木原 卓也 / @tacck / Sapporo, Japan CO-OP Sapporo 生活協同組合コープさっぽろ Software Engineer / Flutter, TypeScript, Vue.js, React Amplify Japan User Group Co-organizer Yuru-Web@Sapporo Organizer (Sapporo local community) AWS Community Builder Since Q2 2021 / Category: Front-end Web and Mobile Community
Amplify ? – Developer Experience – What is Sandbox ? – Relation from Backend to Frontend, CDK ▪ Deep Dive in Codes – Backend Resource about Data – Convey backend types to Frontend – Deploy Resources by CDK 30 days of AWS Amplify / #30DaysOfAmplify / Amplify Gen2 Deep Dive 4
using TypeScript – Resource definition using TypeScript files – Lambda functions can be written in TypeScript – etc... ▪ Sandbox (Development environment on AWS) – Run CDK with hotswapping 30 days of AWS Amplify / #30DaysOfAmplify / Amplify Gen2 Deep Dive 7
#30DaysOfAmplify / Amplify Gen2 Deep Dive 8 ▪ For development environment on your local machine – Providing an environment on AWS for each team member – Quick resource deployment by hotswaping
Deep Dive 17 resource.ts string() is defined ModelField.ts string(). And return _field(). node_modules/@aws-amplify/data-schema/src/ModelField.ts Fields
Deep Dive 18 Filed methods like require() is defined this method. And return type is “ModelField”. node_modules/@aws-amplify/data-schema/src/ModelField.ts Fields
Deep Dive 19 Filed methods type is defined here. If you use require() in resource, “UsedMethod” has “required” and omit from type-hinting. node_modules/@aws-amplify/data-schema/src/ModelField.ts Fields
Deep Dive 23 Model methods type is defined here. If you use authorization() in resource, “UsedMethod” has “authorization” and omit from type-hinting. node_modules/@aws-amplify/data-schema/src/ModelType.ts Models
Deep Dive 25 resource.ts schema() is defined ModelSchema.ts schema. The actual method is bindConfigToSchema(). node_modules/@aws-amplify/data-schema/src/ModelSchema.ts
Deep Dive 26 bindConfigToSchema() return type is “SchemaReturnType”. And, SchemaReturnType’s actual type is ModelSchema. node_modules/@aws-amplify/data-schema/src/ModelSchema.ts Schema
Deep Dive 27 Schema methods type is defined here. If you use authorization() in resource, “UsedMethod” has “authorization” and omit from type-hinting. node_modules/@aws-amplify/data-schema/src/ModelSchema.ts Schema
Deep Dive 29 This method defines a Schema object. For example, the “models” field includes “Todo”. node_modules/@aws-amplify/data-schema/src/ModelSchema.ts Schema
Deep Dive 32 Type argument “Schema” is ModelSchema, which was seen previously. ModelSchema has the same object as GenericModelSchema. So, this type is InternalClientSchema. node_modules/@aws-amplify/data-schema/src/ClientSchema/index.ts
Deep Dive 33 Type argument “CustomerSchema” is extended by ModelSchemaContents. So, the property type is ClientSchemaProperty. node_modules/@aws-amplify/data-schema/src/ClientSchema/index.ts
Deep Dive 35 Here is the type check sequence. For the specific type, see “ClientModel”. node_modules/@aws-amplify/data-schema/src/ClientSchema/index.ts
Deep Dive 36 The first "type" we saw was here. And the value type is “ClientFields”. For the specific type, see “ResolveFields”. node_modules/@aws-amplify/data-schema/src/ClientSchema/Core/ClientModel.ts
Deep Dive 43 There are two main points. One is "defining command handler", and another is "defining calling CDK". packages/cli/src/commands/sandbox/sandbox_command_factory.ts
Deep Dive 46 "SandboxCommand" is used "yargs". When we need to run the sandbox command, we run "npx ampx sandbox" on the terminal. The argument "sandbox" hits "this.command = 'sandbox'" in this code. packages/cli/src/commands/sandbox/sandbox_command.ts
Deep Dive 47 "yargs" calls the handler in this code. In the handler, call "sandbox.start". “sandbox” is from the first argument. packages/cli/src/commands/sandbox/sandbox_command.ts
Deep Dive 48 Go back to "createSandboxCommand". The first argument, "sandboxFacory", is "SandboxSingletonFactory". It is "defining calling CDK". packages/cli/src/commands/sandbox/sandbox_command_factory.ts
Deep Dive 49 The substance of the processing is in “getInstance”. And it calls “FileWatchingSandbox”. packages/sandbox/src/sandbox_singleton_factory.ts
Deep Dive 55 Go back to “SandboxSingletonFactory”. The second argument, “executor”, is “AmplifySandboxExecutor”. packages/sandbox/src/sandbox_singleton_factory.ts
Deep Dive 56 packages/sandbox/src/sandbox_executor.ts “this.executor.deploy” in “FileWatchingSandbox” is defined in this code. And it calls “this.backendDeployer.deploy”.
Deep Dive 58 Go back to “SandboxSingletonFactory”. The first argument, “backendDeployer”, is “BackendDeployerFactory”. packages/sandbox/src/sandbox_singleton_factory.ts
Deep Dive 59 packages/backend-deployer/src/cdk_deployer_singleton_factory.ts The substance of the processing is in “getInstance”. And it calls “CDKDeployer”.
Deep Dive 64 packages/backend-deployer/src/cdk_deployer.ts The “this.executeCommand” method calls the “this.packageManagerController.runWithPacka geManager” method.
Deep Dive 66 packages/backend-deployer/src/cdk_deployer_singleton_factory.ts Go back to “BackendDeployerFactory”. The third argument, “packageManagerController”, is the first argument of the base class.
Deep Dive 67 Go back to “SandboxSingletonFactory” again. The first argument, “packageManagerController”, is “BackendDeployerFactory”. packages/sandbox/src/sandbox_singleton_factory.ts
Deep Dive 68 packages/cli-core/src/package-manager-controller/package_manager_controller_factory.ts “getPackageManagerController” is a method that returns a class based on the package manager. Here, check “NpmPackageManagerController”.
Deep Dive 70 packages/cli-core/src/package-manager-controller/package_manager_controller_base.ts We search “runWithPackageManager” in “CDKDeployer” and find here. And it calls “this. executeWithDebugLogger”.
Deep Dive 71 packages/cli-core/src/package-manager-controller/execute_with_debugger_logger.ts Finally, we find the CDK execution place. execa is the package that runs the system command.
to the frontend. – It is worked with type definitions of TypeScript. ▪ Sandbox is watching files changed and running the CDK command in the ampx command. 30 days of AWS Amplify / #30DaysOfAmplify / Amplify Gen2 Deep Dive 73