OnDeploy
The cloud.OnDeploy resource runs a block of inflight code each time the application is deployed.
Usage
bring cloud;
let bucket = new cloud.Bucket();
// each time the application is deployed, all objects in the bucket are deleted
let setup = new cloud.OnDeploy(inflight () => {
  for key in bucket.list() {
    bucket.delete(key);
  }
});
To specify that the cloud.OnDeploy resource should be run before or after another resource is created or updated, use the executeBefore or executeAfter properties:
bring cloud;
let counter = new cloud.Counter();
let setup2 = new cloud.OnDeploy(inflight () => {
  counter.inc();
}) as "setup2";
let setup1 = new cloud.OnDeploy(inflight () => {
  counter.set(10);
}, executeBefore: [setup2]) as "setup1";
Target-specific details
Simulator (sim)
The sim implementation of cloud.OnDeploy uses a JavaScript function.
AWS (tf-aws and awscdk)
The AWS implementation of cloud.OnDeploy uses a Amazon Lambda function, which is invoked during the Terraform or CloudFormation deployment.
Azure (tf-azure)
🚧 Not supported yet (tracking issue: #3565)
GCP (tf-gcp)
🚧 Not supported yet (tracking issue: #3564)
API Reference 
OnDeploy 
Run code every time the app is deployed.
Initializers 
bring cloud;
new cloud.OnDeploy(handler: IOnDeployHandler, props?: OnDeployProps);
| Name | Type | Description | 
|---|---|---|
|  |  | No description. | 
|  |  | No description. | 
handlerRequired 
- Type: IOnDeployHandler
propsOptional 
- Type: OnDeployProps
Static Functions 
| Name | Description | 
|---|---|
|  | A hook called by the Wing compiler once for each inflight host that needs to use this type inflight. | 
|  | Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource. | 
onLiftType 
bring cloud;
cloud.OnDeploy.onLiftType(host: IInflightHost, ops: MutArray<str>);
A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.
The list of requested inflight methods
needed by the inflight host are given by ops.
This method is commonly used for adding permissions, environment variables, or other capabilities to the inflight host.
hostRequired 
- Type: IInflightHost
opsRequired 
- Type: MutArray<str>
toInflight 
bring cloud;
cloud.OnDeploy.toInflight(obj: IResource);
Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource.
NOTE: This statement must be executed within an async context.
objRequired 
- Type: IResource
Properties 
| Name | Type | Description | 
|---|---|---|
|  | constructs.Node | The tree node. | 
nodeRequired 
node: Node;
- Type: constructs.Node
The tree node.
Structs 
OnDeployProps 
Options for OnDeploy.
Initializer 
bring cloud;
let OnDeployProps = cloud.OnDeployProps{ ... };
Properties 
| Name | Type | Description | 
|---|---|---|
|  | num | The maximum concurrent invocations that can run at one time. | 
|  | MutMap<str> | Environment variables to pass to the function. | 
|  | num | Specifies the number of days that function logs will be kept. | 
|  | num | The amount of memory to allocate to the function, in MB. | 
|  |  | The maximum amount of time the function can run. | 
|  | MutArray<constructs.Construct> | Execute this trigger only after these resources have been provisioned. | 
|  | MutArray<constructs.Construct> | Adds this trigger as a dependency on other constructs. | 
concurrencyOptional 
concurrency: num;
- Type: num
- Default: platform specific limits (100 on the simulator)
The maximum concurrent invocations that can run at one time.
envOptional 
env: MutMap<str>;
- Type: MutMap<str>
- Default: No environment variables.
Environment variables to pass to the function.
logRetentionDaysOptional 
logRetentionDays: num;
- Type: num
- Default: 30
Specifies the number of days that function logs will be kept.
Setting negative value means logs will not expire.
memoryOptional 
memory: num;
- Type: num
- Default: 1024
The amount of memory to allocate to the function, in MB.
timeoutOptional 
timeout: duration;
- Type: duration
- Default: 1m
The maximum amount of time the function can run.
executeAfterOptional 
executeAfter: MutArray<Construct>;
- Type: MutArray<constructs.Construct>
- Default: no additional dependencies
Execute this trigger only after these resources have been provisioned.
executeBeforeOptional 
executeBefore: MutArray<Construct>;
- Type: MutArray<constructs.Construct>
- Default: no additional dependencies
Adds this trigger as a dependency on other constructs.
Protocols 
IOnDeployHandler 
- 
Extends: IInflight 
- 
Implemented By: IOnDeployHandler 
Inflight client: @winglang/sdk.cloud.IOnDeployHandlerClient
A resource with an inflight "handle" method that can be used by cloud.OnDeploy.
IOnDeployHandlerClient 
- Implemented By: IOnDeployHandlerClient
Inflight client for IOnDeployHandler.
Methods 
| Name | Description | 
|---|---|
|  | Entrypoint function that will be called when the app is deployed. | 
handle 
inflight handle(): void
Entrypoint function that will be called when the app is deployed.