-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reference an existing lambda function with `aws.FunctionRef` ## 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
Showing
6 changed files
with
629 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
bring cloud; | ||
bring aws; | ||
bring util; | ||
|
||
// a really cool way to test a "ref" resource: basically, we define a cloud.Function | ||
// and then we define a `FunctionRef` that references it's ARN. nice, ha? | ||
|
||
let c = new cloud.Counter(); | ||
let f = new cloud.Function(inflight () => { | ||
c.inc(); | ||
}); | ||
|
||
// this will only work if we are testing on tf-aws | ||
if let arn = aws.Function.from(f)?.functionArn { | ||
let fref = new aws.FunctionRef(arn); | ||
|
||
test "can invoke a function (FunctionRef)" { | ||
fref.invoke(""); | ||
util.waitUntil(() => { | ||
return c.peek() == 1; | ||
}); | ||
} | ||
} | ||
|
||
if util.env("WING_TARGET") == "sim" { | ||
bring expect; | ||
|
||
let dummyArn = "arn:aws:lambda:us-east-1:111111111111:function:Function-11111111"; | ||
let fr = new aws.FunctionRef(dummyArn); | ||
|
||
test "functionArn returns the arn" { | ||
expect.equal(dummyArn, fr.functionArn); | ||
} | ||
|
||
test "invoke() sends a request to aws, fails because we are using a dummy function" { | ||
let var err = false; | ||
try { | ||
fr.invoke(""); | ||
} catch e { | ||
err = true; | ||
} | ||
|
||
assert(err); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.