-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adam McKee
committed
Jan 1, 2025
1 parent
3077d57
commit 2b378e3
Showing
14 changed files
with
2,055 additions
and
63 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[workspace] | ||
members = [ | ||
"poc_config/aws_wasi_host", | ||
"fn_build", | ||
"l3_base", | ||
"l3_cli", | ||
|
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,9 @@ | ||
## validate wit file | ||
|
||
`cat ./aws.wit | wasm-tools component wit` | ||
|
||
## generate js types | ||
|
||
npx @bytecodealliance/jco types ./ -o bindings | ||
|
||
## build component |
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,33 @@ | ||
package l3:configure; | ||
|
||
world configure { | ||
|
||
variant api-instance { | ||
create-new, | ||
use-api-id(string), | ||
} | ||
|
||
record api-gateway-config { | ||
api: api-instance | ||
} | ||
|
||
record load-balancer-config { | ||
} | ||
|
||
variant cloudfront-origin { | ||
api-gateway(api-gateway-config), | ||
application-load-balancer(load-balancer-config), | ||
} | ||
|
||
record cloudfront-config { | ||
origin: cloudfront-origin, | ||
} | ||
|
||
variant http-config { | ||
api-gateway(api-gateway-config), | ||
application-load-balancer(load-balancer-config), | ||
cloudfront-origin(cloudfront-config), | ||
} | ||
|
||
export configure: func() -> http-config; | ||
} |
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,39 @@ | ||
export type ApiInstance = ApiInstanceCreateNew | ApiInstanceUseApiId; | ||
export interface ApiInstanceCreateNew { | ||
tag: 'create-new', | ||
} | ||
export interface ApiInstanceUseApiId { | ||
tag: 'use-api-id', | ||
val: string, | ||
} | ||
export interface ApiGatewayConfig { | ||
api: ApiInstance, | ||
} | ||
export interface LoadBalancerConfig { | ||
} | ||
export type CloudfrontOrigin = CloudfrontOriginApiGateway | CloudfrontOriginApplicationLoadBalancer; | ||
export interface CloudfrontOriginApiGateway { | ||
tag: 'api-gateway', | ||
val: ApiGatewayConfig, | ||
} | ||
export interface CloudfrontOriginApplicationLoadBalancer { | ||
tag: 'application-load-balancer', | ||
val: LoadBalancerConfig, | ||
} | ||
export interface CloudfrontConfig { | ||
origin: CloudfrontOrigin, | ||
} | ||
export type HttpConfig = HttpConfigApiGateway | HttpConfigApplicationLoadBalancer | HttpConfigCloudfrontOrigin; | ||
export interface HttpConfigApiGateway { | ||
tag: 'api-gateway', | ||
val: ApiGatewayConfig, | ||
} | ||
export interface HttpConfigApplicationLoadBalancer { | ||
tag: 'application-load-balancer', | ||
val: LoadBalancerConfig, | ||
} | ||
export interface HttpConfigCloudfrontOrigin { | ||
tag: 'cloudfront-origin', | ||
val: CloudfrontConfig, | ||
} | ||
export function configure(): HttpConfig; |
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,13 @@ | ||
/** | ||
* @return {import('./bindings/..d.ts').HttpConfig} | ||
*/ | ||
export function configure() { | ||
return { | ||
tag: 'api-gateway', | ||
val: { | ||
api: { | ||
tag: 'create-new', | ||
}, | ||
}, | ||
} | ||
} |
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,18 @@ | ||
[package] | ||
name = "aws_wasi" | ||
version = "0.1.0" | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
|
||
[dependencies] | ||
async-std = { version = "1.13.0", features = ["attributes"] } | ||
cap-std = { version = "3.3.0 "} | ||
thiserror = { workspace = true } | ||
wasmtime = { version = "25.0.1", features = ["component-model"]} | ||
wasmtime-wasi = "25.0.1" | ||
wasmtime-wasi-http = "25.0.1" | ||
anyhow = "1.0.92" | ||
|
||
|
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,33 @@ | ||
package l3:configure; | ||
|
||
world configure { | ||
|
||
variant api-instance { | ||
create-new, | ||
use-api-id(string), | ||
} | ||
|
||
record api-gateway-config { | ||
api: api-instance | ||
} | ||
|
||
record load-balancer-config { | ||
} | ||
|
||
variant cloudfront-origin { | ||
api-gateway(api-gateway-config), | ||
application-load-balancer(load-balancer-config), | ||
} | ||
|
||
record cloudfront-config { | ||
origin: cloudfront-origin, | ||
} | ||
|
||
variant http-config { | ||
api-gateway(api-gateway-config), | ||
application-load-balancer(load-balancer-config), | ||
cloudfront-origin(cloudfront-config), | ||
} | ||
|
||
export configure: func() -> http-config; | ||
} |
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,70 @@ | ||
use anyhow::Result; | ||
use wasmtime::{ | ||
component::{Component, Linker}, | ||
Config, Engine, Store, WasmBacktraceDetails, | ||
}; | ||
use wasmtime_wasi::{ResourceTable, WasiCtx, WasiCtxBuilder, WasiView}; | ||
use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView}; | ||
|
||
wasmtime::component::bindgen!({ | ||
world: "configure", | ||
path: "aws.wit", | ||
async: true | ||
}); | ||
|
||
#[async_std::main] | ||
async fn main() -> Result<()> { | ||
let mut builder = WasiCtxBuilder::new(); | ||
builder.inherit_stdio(); | ||
let table = ResourceTable::new(); | ||
let wasi = builder.build(); | ||
|
||
let mut config = Config::new(); | ||
config.cache_config_load_default().unwrap(); | ||
config.wasm_backtrace_details(WasmBacktraceDetails::Enable); | ||
config.wasm_component_model(true); | ||
config.async_support(true); | ||
|
||
let engine = Engine::new(&config)?; | ||
let mut linker = Linker::new(&engine); | ||
|
||
let component = Component::from_file(&engine, "hello.component.wasm").unwrap(); | ||
|
||
struct CommandExtendedCtx { | ||
table: ResourceTable, | ||
wasi: WasiCtx, | ||
http: WasiHttpCtx, | ||
} | ||
impl WasiView for CommandExtendedCtx { | ||
fn table(&mut self) -> &mut ResourceTable { | ||
&mut self.table | ||
} | ||
fn ctx(&mut self) -> &mut WasiCtx { | ||
&mut self.wasi | ||
} | ||
} | ||
impl WasiHttpView for CommandExtendedCtx { | ||
fn table(&mut self) -> &mut ResourceTable { | ||
&mut self.table | ||
} | ||
fn ctx(&mut self) -> &mut WasiHttpCtx { | ||
&mut self.http | ||
} | ||
} | ||
|
||
wasmtime_wasi::add_to_linker_sync(&mut linker)?; | ||
wasmtime_wasi_http::add_only_http_to_linker_sync(&mut linker)?; | ||
let mut store = Store::new( | ||
&engine, | ||
CommandExtendedCtx { | ||
table, | ||
wasi, | ||
http: WasiHttpCtx::new(), | ||
}, | ||
); | ||
|
||
let hello = Configure::instantiate_async(&mut store, &component, &linker).await?; | ||
let res = hello.call_configure(&mut store).await?; | ||
dbg!(res); | ||
Ok(()) | ||
} |
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,4 @@ | ||
{ | ||
"name": "l3-config", | ||
"version": "0.0.1" | ||
} |
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,16 @@ | ||
import {LambdaPlatform} from './LambdaPlatform' | ||
|
||
export class ApiGateway { | ||
readonly tag: string = 'api-gateway' | ||
} | ||
|
||
export class LoadBalancer { | ||
readonly tag: string = 'application-load-balancer' | ||
} | ||
|
||
export type HttpRouting = ApiGateway | LoadBalancer | ||
|
||
export class Platform extends LambdaPlatform<HttpRouting> { | ||
httpRouting(routing: HttpRouting) { | ||
} | ||
} |
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,3 @@ | ||
export abstract class LambdaPlatform<R> { | ||
abstract httpRouting(routing: R) | ||
} |
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,2 @@ | ||
|
||
import {AWS} from './Aws.js' |
Empty file.