diff --git a/apps/api/bronya.config.ts b/apps/api/bronya.config.ts index 3cb65887..16228f6d 100644 --- a/apps/api/bronya.config.ts +++ b/apps/api/bronya.config.ts @@ -150,31 +150,27 @@ export const esbuildOptions: BuildOptions = { * Shared construct props. */ export const constructs: ApiConstructProps = { - functionProps: (scope, id) => ({ + functionProps: (scope, id, route) => ({ runtime: Runtime.NODEJS_20_X, - role: new Role( - scope, - `${id}-${Number.parseInt(Math.random().toString().slice(2)).toString(16).padStart(14, "0")}-role`, - { - assumedBy: new ServicePrincipal("lambda.amazonaws.com"), - managedPolicies: [ - ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole"), - ], - inlinePolicies: { - lambdaInvokePolicy: new PolicyDocument({ - statements: [ - new PolicyStatement({ - effect: Effect.ALLOW, - resources: [ - `arn:aws:dynamodb:${process.env["AWS_REGION"]}:${process.env["ACCOUNT_ID"]}:table/${id}-cache`, - ], - actions: ["dynamodb:GetItem", "dynamodb:PutItem"], - }), - ], - }), - }, + role: new Role(scope, `${id}-${route.endpoint}-role`, { + assumedBy: new ServicePrincipal("lambda.amazonaws.com"), + managedPolicies: [ + ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole"), + ], + inlinePolicies: { + lambdaInvokePolicy: new PolicyDocument({ + statements: [ + new PolicyStatement({ + effect: Effect.ALLOW, + resources: [ + `arn:aws:dynamodb:${process.env["AWS_REGION"]}:${process.env["ACCOUNT_ID"]}:table/${id}-cache`, + ], + actions: ["dynamodb:GetItem", "dynamodb:PutItem"], + }), + ], + }), }, - ), + }), }), functionPlugin: ({ functionProps, handler }, scope) => { const warmingTarget = new LambdaFunction(handler, { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5696f045..0b92ee45 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -139,11 +139,11 @@ importers: version: 3.22.4 devDependencies: '@bronya.js/api-construct': - specifier: 0.11.3 - version: 0.11.3 + specifier: 0.11.4 + version: 0.11.4 '@bronya.js/core': - specifier: 0.11.3 - version: 0.11.3 + specifier: 0.11.4 + version: 0.11.4 '@types/aws-lambda': specifier: 8.10.132 version: 8.10.132 @@ -2830,12 +2830,12 @@ packages: to-fast-properties: 2.0.0 dev: false - /@bronya.js/api-construct@0.11.3: - resolution: {integrity: sha512-ro5/IwJQIv36k0uoYYL/pMzvFYJMlnzBOdeDylet+9T7gbXSjZEt+LKA9QjFGoqDvRl3WOQIJLUfJRollOVXng==} + /@bronya.js/api-construct@0.11.4: + resolution: {integrity: sha512-zR5G9wn9IYzy4T68fnh6S6helxjc2eaf6c0emyqY3Z6H4HpSNttK1XBnFRC+yUThYJDpcisvM3LK0ia8z+chuQ==} engines: {node: '>=18', pnpm: ^8.0.0} dependencies: - '@bronya.js/cli': 0.11.3 - '@bronya.js/core': 0.11.3 + '@bronya.js/cli': 0.11.4 + '@bronya.js/core': 0.11.4 acorn: 8.10.0 acorn-typescript: 1.4.5(acorn@8.10.0) aws-cdk-lib: 2.124.0(constructs@10.2.69) @@ -2847,22 +2847,22 @@ packages: defu: 6.1.2 express: 4.18.2 fs-extra: 11.1.1 - jiti: 1.19.1 + jiti: 1.20.0 transitivePeerDependencies: - supports-color dev: true - /@bronya.js/cli@0.11.3: - resolution: {integrity: sha512-1FkvlcXR17rfSGo7cDScrxCeC1S3Ib7GJaGTa874tOtrVHZVM7T0ebyPI1lO715BVEvS+hursJElRU9MZsnQOQ==} + /@bronya.js/cli@0.11.4: + resolution: {integrity: sha512-0aABMJmIhQiIl6gqn2dcXtQCme5RC3BcN1syDxI72H3+RJrKV7Reusw/R8z5ev9lUKc6kPay+OmD7Ck2z0zYCg==} engines: {node: '>=18', pnpm: ^8.0.0} dev: true - /@bronya.js/core@0.11.3: - resolution: {integrity: sha512-D5RU9y6o7KSmUjewjPR9ImR61/FQG4Xw42onn2vwiIJzCyQ7qzo1c7ecnbh7AVdldwa698kySRGne5Um/AemOA==} + /@bronya.js/core@0.11.4: + resolution: {integrity: sha512-DCRxoGsE8a63f5G/bslYi7MK3xPO6j70vXrxUEwRq5k2CtT54KcHejySzkSg3eA7FSes5l4K4LZk8yPHGi9TAQ==} engines: {node: '>=18', pnpm: ^8.0.0} hasBin: true dependencies: - '@bronya.js/cli': 0.11.3 + '@bronya.js/cli': 0.11.4 acorn: 8.10.0 acorn-typescript: 1.4.5(acorn@8.10.0) aws-cdk-lib: 2.124.0(constructs@10.2.69) @@ -2873,7 +2873,7 @@ packages: cors: 2.8.5 defu: 6.1.2 express: 4.18.2 - jiti: 1.19.1 + jiti: 1.20.0 transitivePeerDependencies: - supports-color dev: true @@ -9659,11 +9659,6 @@ packages: supports-color: 8.1.1 dev: false - /jiti@1.19.1: - resolution: {integrity: sha512-oVhqoRDaBXf7sjkll95LHVS6Myyyb1zaunVwk4Z0+WPSW4gjS0pl01zYKHScTuyEhQsFxV5L4DR5r+YqSyqyyg==} - hasBin: true - dev: true - /jiti@1.20.0: resolution: {integrity: sha512-3TV69ZbrvV6U5DfQimop50jE9Dl6J8O1ja1dvBbMba/sZ3YBEQqJ2VZRoQPVnhlzjNtU1vaXRZVrVjU4qtm8yA==} hasBin: true