Application
This class represents an AWS CDK application. It allows the user to create a new CDK App instance and a main CDK Stack instance.
#
Constructor#
Parametersconfig
(optional): An object that implements theIApplicationConfig
interface. This object is used to configure the application. If noconfig
object is provided, an empty object is used.
#
Details- The constructor initializes the AWS CDK application by creating a new
App
instance. - It also creates a new CDK Stack instance for the main stack using the provided
config
object. - The constructor hydrates the
config
object with environment variables using theHelper
class. - It sets global variables
mainStack
using theReflect
class.
#
Propertiesapp
: An instance of the CDKApp
class representing the application.mainStack
: An instance of the CDKStack
class representing the main stack of the application.
#
Methodsuse(stack: any): Application
#
This method is used to add a new stack to the application.
#
Parametersstack
: An object representing the stack to be added to the application.
#
Returns- An instance of the
Application
class with the new stack added.
#
Details- The
use
method takes a stack object and calls itsconstruct
method passing in theconfig
object. - This method allows the user to add different stacks to the application and configure them as needed.
#
exampleimport { APIConstruct, Application, DynamoDBConstruct } from "@ten24group/fw24";import { AuthModule } from '@ten24group/fw24-auth-cognito';import { Duration, RemovalPolicy } from 'aws-cdk-lib';import { AttributeType } from 'aws-cdk-lib/aws-dynamodb';
const app = new Application({ functionProps: { bundling: { externalModules: ['@aws-sdk'], }, },});
var api = new APIConstruct({ apiOptions: { description: 'Sample App API Gateway', deployOptions: { stageName: 'v1', }, }, functionProps: { timeout: Duration.seconds(15), },});
const dynamo = new DynamoDBConstruct({ table: { name: 'users_tbl', props: { partitionKey: { name: 'pk', type: AttributeType.STRING, }, sortKey: { name: 'sk', type: AttributeType.STRING, }, }, },});
const authModule = new AuthModule({ userPool: { props: { selfSignUpEnabled: true, removalPolicy: RemovalPolicy.DESTROY, } }, groups: [ { name: 'admin', routes: ['auth/addUserToGroup', 'auth/removeUserFromGroup'], }, { name: 'user', autoUserSignup: true, }, ], useAsDefaultAuthorizer: false});
app.use(api).use(dynamo).useModule(authModule).run();
This sample app creates an API gateway, adds a dynamoDB table and add supports for Authentication for 2 user groups admin
and user
using the AuthModule
.
#
Backend DIR structureFW24 prefers conventions over configurations and follows a very intuitive directory structure.
โโโ README.mdโโโ cdk.jsonโโโ docs -- CLI generated API docsโ โโโ apiโ โโโ postman-xxx.jsonโ โโโ swagger-xxx.jsonโโโ gen -- auto-generated configs used by the framework internallyโ โโโ configโ โโโ auth.jsonโ โโโ entities.jsonโ โโโ menu.jsonโ โโโ dashboard.jsonโโโ package-lock.jsonโโโ package.jsonโโโ srcโ โโโ controllersโ โ โโโ book.tsโ โ โโโ helloworld.tsโ โ โโโ test.tsโ โโโ dbโ โ โโโ myproject2.dynamo.client.tsโ โโโ entitiesโ โ โโโ book.tsโ โโโ functionsโ โ โโโ bucket1handler.tsโ โโโ modules -- this is where your application specific modules liveโ โโโ policiesโ โ โโโ mypolicy.tsโ โโโ queuesโ โ โโโ myqueue.tsโ โโโ servicesโ โ โโโ book.tsโ โโโ tasksโ โ โโโ mytask.tsโ โโโ templates -- this's where your email templates liveโ โโโ index.ts // this is where the application code livesโโโ tsconfig.json