wirejs-deploy-amplify-basic 0.1.152-llm → 0.1.153-llm

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,11 @@
1
+ import path from 'path';
1
2
  import { randomUUID } from 'crypto';
2
3
  import {
3
4
  defineBackend,
4
5
  } from '@aws-amplify/backend';
5
- import { RemovalPolicy, NestedStack } from "aws-cdk-lib";
6
- import { FunctionUrlAuthType } from 'aws-cdk-lib/aws-lambda';
6
+ import { Duration, RemovalPolicy, NestedStack } from "aws-cdk-lib";
7
+ import { FunctionUrlAuthType, IFunction, Runtime } from 'aws-cdk-lib/aws-lambda';
8
+ import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
7
9
  import { Bucket, BlockPublicAccess } from 'aws-cdk-lib/aws-s3';
8
10
  import { Table, AttributeType, BillingMode } from 'aws-cdk-lib/aws-dynamodb';
9
11
  import { AnyPrincipal, PolicyStatement } from 'aws-cdk-lib/aws-iam';
@@ -11,12 +13,14 @@ import { AnyPrincipal, PolicyStatement } from 'aws-cdk-lib/aws-iam';
11
13
  import { TableDefinition, indexName } from 'wirejs-resources';
12
14
  import { TableIndexes } from './constructs/table-indexes';
13
15
  import { RealtimeService } from './constructs/realtime-service';
14
- import { api } from './functions/api/resource';
15
16
  import { auth } from './auth/resource';
16
17
 
17
18
  // @ts-ignore
18
19
  import generatedResources from './generated-resources';
19
20
 
21
+ const __filename = import.meta.url.replace(/^file:/, '');
22
+ const __dirname = path.dirname(__filename);
23
+
20
24
  const generated: any[] = generatedResources;
21
25
 
22
26
  const APP_ID = process.env.AWS_APP_ID ?? process.env.PWD?.replace(/[^a-zA-Z0-9-_]/g, '_');
@@ -32,9 +36,20 @@ const SELF_INVOCATION_ID = randomUUID();
32
36
  /**
33
37
  * Amplify resources
34
38
  */
35
- const backend = defineBackend({
36
- auth,
37
- api,
39
+ const backend = defineBackend({ auth });
40
+
41
+ const api = new NodejsFunction(backend.stack, 'ApiHandler', {
42
+ runtime: Runtime.NODEJS_22_X,
43
+ memorySize: 2 * 1024,
44
+ handler: 'handler',
45
+ entry: path.join(__dirname, 'functions', 'api', 'handler.ts'),
46
+ bundling: {
47
+ minify: true,
48
+ nodeModules: [
49
+ 'jsdom'
50
+ ]
51
+ },
52
+ timeout: Duration.minutes(15),
38
53
  });
39
54
 
40
55
  /**
@@ -56,21 +71,14 @@ userPoolClient.explicitAuthFlows.push(
56
71
  'ALLOW_ADMIN_USER_PASSWORD_AUTH'
57
72
  );
58
73
 
59
- // new CfnPermission(backend.stack, 'SelfInvokePermission', {
60
- // action: 'lambda:InvokeFunction',
61
- // functionName: backend.api.resources.lambda.functionName,
62
- // principal: 'lambda.amazonaws.com',
63
- // sourceArn: backend.api.resources.lambda.functionArn
64
- // });
65
-
66
- backend.api.resources.lambda.role?.addToPrincipalPolicy(new PolicyStatement({
74
+ api.role?.addToPrincipalPolicy(new PolicyStatement({
67
75
  actions: ['lambda:InvokeFunction'],
68
76
  resources: [
69
77
  `arn:${backend.stack.partition}:lambda:${backend.stack.region}:${backend.stack.account}:function:*`,
70
78
  ],
71
79
  }));
72
80
 
73
- const allLambdas = [ backend.api.resources.lambda ];
81
+ const allLambdas: IFunction[] = [ api ];
74
82
 
75
83
  /**
76
84
  * CDK resources
@@ -80,7 +88,7 @@ const bucket = new Bucket(backend.stack, 'data', {
80
88
  versioned: true,
81
89
  removalPolicy: RemovalPolicy.RETAIN,
82
90
  });
83
- bucket.grantReadWrite(backend.api.resources.lambda);
91
+ bucket.grantReadWrite(api);
84
92
 
85
93
  function isRealtimeService(resource: any): resource is {
86
94
  type: 'RealtimeService';
@@ -96,7 +104,7 @@ if (generated.some(isRealtimeService)) {
96
104
  const realtime = new RealtimeService(realtimeStack, 'realtime', {
97
105
  appId: APP_ID!,
98
106
  branchId: BRANCH_ID,
99
- publisher: backend.api,
107
+ publisher: api,
100
108
  bucket: bucket.bucketName,
101
109
  namespaces: generated
102
110
  .filter(isRealtimeService)
@@ -188,19 +196,20 @@ for (const resource of generated) {
188
196
  }
189
197
  }
190
198
 
199
+
191
200
  /**
192
201
  * Lambda environment vars
193
202
  */
194
- backend.api.addEnvironment(
203
+ api.addEnvironment(
195
204
  'BUCKET', bucket.bucketName,
196
205
  );
197
- backend.api.addEnvironment(
206
+ api.addEnvironment(
198
207
  'COGNITO_CLIENT_ID', backend.auth.resources.userPoolClient.userPoolClientId
199
208
  );
200
- backend.api.addEnvironment(
209
+ api.addEnvironment(
201
210
  'TABLE_NAME_PREFIX', TABLE_NAME_PREFIX
202
211
  );
203
- backend.api.addEnvironment(
212
+ api.addEnvironment(
204
213
  'SELF_INVOCATION_ID', SELF_INVOCATION_ID
205
214
  );
206
215
 
@@ -208,12 +217,12 @@ backend.api.addEnvironment(
208
217
  /**
209
218
  * Client configuration
210
219
  */
211
- const apiUrl = backend.api.resources.lambda.addFunctionUrl({
220
+ const apiUrl = api.addFunctionUrl({
212
221
  authType: FunctionUrlAuthType.NONE,
213
222
  });
214
223
  apiUrl.grantInvokeUrl(new AnyPrincipal());
215
224
 
216
- backend.api.resources.lambda.addToRolePolicy(new PolicyStatement({
225
+ api.addToRolePolicy(new PolicyStatement({
217
226
  actions: [
218
227
  'bedrock:InvokeModel',
219
228
  'bedrock:InvokeModelWithResponseStream',
@@ -222,8 +231,4 @@ backend.api.resources.lambda.addToRolePolicy(new PolicyStatement({
222
231
  }));
223
232
 
224
233
 
225
- backend.addOutput({
226
- custom: {
227
- api: apiUrl.url
228
- }
229
- });
234
+ backend.addOutput({ custom: { api: apiUrl.url } });
@@ -18,12 +18,7 @@ export class RealtimeService extends Construct {
18
18
  constructor(scope: Construct, id: string, props: {
19
19
  appId: string;
20
20
  branchId: string;
21
- publisher: {
22
- addEnvironment: (key: string, value: string) => void;
23
- resources: {
24
- lambda: IFunction;
25
- }
26
- };
21
+ publisher: NodejsFunction;
27
22
  bucket: string; // needed for `Secret`, which currently uses the common S3 bucket
28
23
  namespaces: string[];
29
24
  }) {
@@ -79,7 +74,7 @@ export class RealtimeService extends Construct {
79
74
 
80
75
  for (const namespace of props.namespaces) {
81
76
  const ns = realtimeService.addChannelNamespace(namespace);
82
- ns.grantPublish(props.publisher.resources.lambda);
77
+ ns.grantPublish(props.publisher);
83
78
  }
84
79
  }
85
80
  }
@@ -3,6 +3,6 @@
3
3
  "dependencies": {
4
4
  "jsdom": "^25.0.1",
5
5
  "wirejs-dom": "^1.0.44",
6
- "wirejs-resources": "^0.1.152-llm"
6
+ "wirejs-resources": "^0.1.153-llm"
7
7
  }
8
8
  }
package/build.js CHANGED
@@ -78,7 +78,7 @@ async function installDeps() {
78
78
  // install all
79
79
  execSync('npm i');
80
80
 
81
- console.log("done installing deps")
81
+ console.log("done installing deps");
82
82
  }
83
83
 
84
84
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.1.152-llm",
3
+ "version": "0.1.153-llm",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -44,7 +44,7 @@
44
44
  "recursive-copy": "^2.0.14",
45
45
  "rimraf": "^6.0.1",
46
46
  "wirejs-dom": "^1.0.44",
47
- "wirejs-resources": "^0.1.152-llm"
47
+ "wirejs-resources": "^0.1.153-llm"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@aws-amplify/backend": "^1.14.0",
@@ -1,12 +0,0 @@
1
- import {
2
- defineFunction
3
- } from '@aws-amplify/backend';
4
-
5
- const api = defineFunction({
6
- entry: './handler.ts',
7
- runtime: 22,
8
- memoryMB: 1024,
9
- timeoutSeconds: 60 * 15,
10
- });
11
-
12
- export { api };