Last active
May 16, 2025 15:20
-
-
Save pavi2410/13ad9da14de8eecb67fe33424e2ae14b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { Function, Queue, Role, Table } from "alchemy/aws"; | |
import { R2RestStateStore } from "alchemy/cloudflare"; | |
import { Bundle } from "alchemy/esbuild"; | |
import path from "node:path"; | |
import { fileURLToPath } from "node:url"; | |
import alchemy, { useRef } from "alchemy"; | |
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | |
function App() { | |
const tableRef = useRef(); | |
return ( | |
<alchemy | |
id="aws-app" | |
phase={process.argv[2] === "destroy" ? "destroy" : "up"} | |
stage={process.argv[3]} | |
quiet={process.argv.includes("--quiet")} | |
stateStore={ | |
process.env.ALCHEMY_STATE_STORE === "cloudflare" | |
? (scope) => new R2RestStateStore(scope) | |
: undefined | |
} | |
> | |
<Queue | |
id="alchemy-items-queue" | |
queueName="alchemy-items-queue" | |
visibilityTimeout={30} | |
messageRetentionPeriod={345600} | |
/> | |
<Table | |
id="alchemy-items-table" | |
tableName="alchemy-items" | |
partitionKey={{ name: "id", type: "S" }} | |
ref={tableRef} | |
/> | |
<Function | |
id="api" | |
functionName="alchemy-items-api" | |
handler="index.handler" | |
environment={{ | |
TABLE_NAME: tableRef.current?.tableName, | |
}} | |
url={{ | |
authType: "NONE", | |
cors: { | |
allowOrigins: ["*"], | |
allowMethods: ["GET", "POST", "PUT", "DELETE"], | |
allowHeaders: ["content-type"], | |
}, | |
}} | |
> | |
<Bundle | |
id="api-bundle" | |
entryPoint={path.join(__dirname, "src", "index.ts")} | |
outdir=".out" | |
format="esm" | |
platform="node" | |
target="node20" | |
minify={true} | |
sourcemap={true} | |
external={["@aws-sdk/*"]} | |
/> | |
<Role | |
id="alchemy-api-role" | |
roleName="alchemy-api-lambda-role" | |
assumeRolePolicy={{ | |
Version: "2012-10-17", | |
Statement: [ | |
{ | |
Effect: "Allow", | |
Principal: { Service: "lambda.amazonaws.com" }, | |
Action: "sts:AssumeRole", | |
}, | |
], | |
}} | |
/> | |
</Function> | |
</alchemy> | |
); | |
} | |
await alchemy.finalize(<App />); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment