Skip to content

Commit

Permalink
feat(sdk): adding OnDeploy to awscdk target (#3817)
Browse files Browse the repository at this point in the history
Closes #3782 

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
marciocadev authored Aug 15, 2023
1 parent 71b9b5d commit cff291a
Show file tree
Hide file tree
Showing 4 changed files with 766 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libs/wingsdk/src/target-awscdk/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import stringify from "safe-stable-stringify";
import { Bucket } from "./bucket";
import { Counter } from "./counter";
import { Function } from "./function";
import { OnDeploy } from "./on-deploy";
import { Queue } from "./queue";
import { Schedule } from "./schedule";
import { Secret } from "./secret";
Expand All @@ -18,6 +19,7 @@ import {
BUCKET_FQN,
COUNTER_FQN,
FUNCTION_FQN,
ON_DEPLOY_FQN,
QUEUE_FQN,
SECRET_FQN,
TOPIC_FQN,
Expand Down Expand Up @@ -161,6 +163,9 @@ export class App extends CoreApp {

case SECRET_FQN:
return new Secret(scope, id, args[0]);

case ON_DEPLOY_FQN:
return new OnDeploy(scope, id, args[0], args[1]);
}
return undefined;
}
Expand Down
41 changes: 41 additions & 0 deletions libs/wingsdk/src/target-awscdk/on-deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Trigger } from "aws-cdk-lib/triggers";
import { Construct } from "constructs";
import { Function as AwsFunction } from "./function";
import * as cloud from "../cloud";
import * as core from "../core";

/**
* AWS implementation of `cloud.OnDeploy`.
*
* @inflight `@winglang/sdk.cloud.IOnDeployClient`
*/
export class OnDeploy extends cloud.OnDeploy {
constructor(
scope: Construct,
id: string,
handler: cloud.IOnDeployHandler,
props: cloud.OnDeployProps = {}
) {
super(scope, id, handler, props);

let fn = cloud.Function._newFunction(this, "Function", handler, props);
const awsFn = fn as AwsFunction;

let trigger = new Trigger(this, "Trigger", {
handler: awsFn._function,
});

trigger.executeAfter(...(props.executeAfter ?? []));
trigger.executeBefore(...(props.executeBefore ?? []));
}

/** @internal */
public _toInflight(): core.Code {
return core.InflightClient.for(
__dirname.replace("target-awscdk", "shared-aws"),
__filename,
"OnDeployClient",
[]
);
}
}
Loading

0 comments on commit cff291a

Please sign in to comment.