Class App
A construct which represents an entire CDK app. This construct is normally the root of the construct tree.
public class App : Stage, IConstruct, IConstruct, IDependable
- Inheritance
-
App
- Implements
-
IConstruct
- Inherited Members
Examples
using Path;
using Amazon.CDK.AWS.Lambda;
using Amazon.CDK;
using Amazon.CDK.AWS.APIGateway;
/*
* Stack verification steps:
* * `curl -s -o /dev/null -w "%{http_code}" <url>` should return 401
* * `curl -s -o /dev/null -w "%{http_code}" -H 'Authorization: deny' <url>` should return 403
* * `curl -s -o /dev/null -w "%{http_code}" -H 'Authorization: allow' <url>` should return 200
*/
var app = new App();
var stack = new Stack(app, "TokenAuthorizerInteg");
var authorizerFn = new Function(stack, "MyAuthorizerFunction", new FunctionProps {
Runtime = Runtime.NODEJS_14_X,
Handler = "index.handler",
Code = AssetCode.FromAsset(Join(__dirname, "integ.token-authorizer.handler"))
});
var restapi = new RestApi(stack, "MyRestApi");
var authorizer = new TokenAuthorizer(stack, "MyAuthorizer", new TokenAuthorizerProps {
Handler = authorizerFn
});
restapi.Root.AddMethod("ANY", new MockIntegration(new IntegrationOptions {
IntegrationResponses = new [] { new IntegrationResponse { StatusCode = "200" } },
PassthroughBehavior = PassthroughBehavior.NEVER,
RequestTemplates = new Dictionary<string, string> {
{ "application/json", "{ \"statusCode\": 200 }" }
}
}), new MethodOptions {
MethodResponses = new [] { new MethodResponse { StatusCode = "200" } },
Authorizer = authorizer
});
Remarks
You would normally define an App
instance in your program's entrypoint,
then define constructs where the app is used as the parent scope.
After all the child constructs are defined within the app, you should call
app.synth()
which will emit a "cloud assembly" from this app into the
directory specified by outdir
. Cloud assemblies includes artifacts such as
CloudFormation templates and assets that are needed to deploy this app into
the AWS cloud.
See: https://docs.aws.amazon.com/cdk/latest/guide/apps.html
ExampleMetadata: lit=test/authorizers/integ.token-authorizer.lit.ts infused
Constructors
App(IAppProps?)
Initializes a CDK application.
public App(IAppProps? props = null)
Parameters
props
IAppPropsinitialization properties.
Methods
IsApp(object)
Checks if an object is an instance of the App
class.
public static bool IsApp(object obj)
Parameters
obj
objectThe object to evaluate.
Returns
- bool
true
ifobj
is anApp
.