@awsless/awsless 0.0.146 → 0.0.147

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.
package/dist/bin.js CHANGED
@@ -55,6 +55,9 @@ var flushDebug = () => {
55
55
  return queue.splice(0, queue.length);
56
56
  };
57
57
 
58
+ // src/formation/resource/lambda/function.ts
59
+ import { constantCase as constantCase3 } from "change-case";
60
+
58
61
  // src/formation/asset.ts
59
62
  import { paramCase } from "change-case";
60
63
  var Asset = class {
@@ -65,6 +68,43 @@ var Asset = class {
65
68
  id;
66
69
  };
67
70
 
71
+ // src/formation/property/duration.ts
72
+ var Duration = class _Duration {
73
+ constructor(value) {
74
+ this.value = value;
75
+ }
76
+ static milliseconds(value) {
77
+ return new _Duration(value);
78
+ }
79
+ static seconds(value) {
80
+ return new _Duration(value * 1e3 /* seconds */);
81
+ }
82
+ static minutes(value) {
83
+ return new _Duration(value * 6e4 /* minutes */);
84
+ }
85
+ static hours(value) {
86
+ return new _Duration(value * 36e5 /* hours */);
87
+ }
88
+ static days(value) {
89
+ return new _Duration(value * 864e5 /* days */);
90
+ }
91
+ toMilliseconds() {
92
+ return this.value;
93
+ }
94
+ toSeconds() {
95
+ return Math.floor(this.value / 1e3 /* seconds */);
96
+ }
97
+ toMinutes() {
98
+ return Math.floor(this.value / 6e4 /* minutes */);
99
+ }
100
+ toHours() {
101
+ return Math.floor(this.value / 36e5 /* hours */);
102
+ }
103
+ toDays() {
104
+ return Math.floor(this.value / 864e5 /* days */);
105
+ }
106
+ };
107
+
68
108
  // src/formation/util.ts
69
109
  import { paramCase as paramCase2, pascalCase } from "change-case";
70
110
  var ref = (logicalId) => {
@@ -303,7 +343,7 @@ var Rule = class extends Resource {
303
343
  properties() {
304
344
  return {
305
345
  Name: this.name,
306
- ...this.attr("State", "ENABLED"),
346
+ ...this.attr("State", this.props.enabled ? "ENABLED" : "DISABLED"),
307
347
  ...this.attr("Description", this.props.description),
308
348
  ...this.attr("ScheduleExpression", this.props.schedule),
309
349
  ...this.attr("RoleArn", this.props.roleArn),
@@ -341,11 +381,14 @@ var EventsEventSource = class extends Group {
341
381
  constructor(id, lambda, props) {
342
382
  const rule = new Rule(id, {
343
383
  schedule: props.schedule,
344
- targets: [{
345
- id,
346
- arn: lambda.arn,
347
- input: props.payload
348
- }]
384
+ enabled: props.enabled,
385
+ targets: [
386
+ {
387
+ id,
388
+ arn: lambda.arn,
389
+ input: props.payload
390
+ }
391
+ ]
349
392
  });
350
393
  const permission = new Permission(id, {
351
394
  action: "lambda:InvokeFunction",
@@ -411,11 +454,22 @@ var Function = class extends Resource {
411
454
  if (this.name.length > 64) {
412
455
  throw new TypeError(`Lambda function name length can't be greater then 64. ${this.name}`);
413
456
  }
457
+ if (props.log) {
458
+ if (typeof props.log === "boolean") {
459
+ this.enableLogs(Duration.days(7));
460
+ } else if (props.log instanceof Duration) {
461
+ this.enableLogs(props.log);
462
+ } else {
463
+ this.enableLogs(props.log.retention);
464
+ this.logConfig = props.log;
465
+ }
466
+ }
414
467
  }
415
468
  name;
416
469
  role;
417
470
  policy;
418
471
  environmentVariables;
472
+ logConfig = {};
419
473
  enableLogs(retention) {
420
474
  const logGroup = new LogGroup(this._logicalId, {
421
475
  name: sub("/aws/lambda/${name}", {
@@ -439,6 +493,7 @@ var Function = class extends Resource {
439
493
  warmUp(concurrency) {
440
494
  const source = new EventsEventSource(`${this._logicalId}-warmer`, this, {
441
495
  schedule: "rate(5 minutes)",
496
+ enabled: true,
442
497
  payload: {
443
498
  warmer: true,
444
499
  concurrency
@@ -497,6 +552,13 @@ var Function = class extends Resource {
497
552
  EphemeralStorage: {
498
553
  Size: this.props.ephemeralStorageSize?.toMegaBytes() ?? 512
499
554
  },
555
+ ...this.props.log ? {
556
+ LoggingConfig: {
557
+ LogFormat: this.logConfig.format === "text" ? "Text" : "JSON",
558
+ ApplicationLogLevel: constantCase3(this.logConfig.level ?? "error"),
559
+ SystemLogLevel: constantCase3(this.logConfig.system ?? "warn")
560
+ }
561
+ } : {},
500
562
  ...this.props.vpc ? {
501
563
  VpcConfig: {
502
564
  SecurityGroupIds: this.props.vpc.securityGroupIds,
@@ -749,7 +811,7 @@ var fileExist = async (file) => {
749
811
 
750
812
  // src/util/type-gen.ts
751
813
  import { dirname, join as join2, relative } from "path";
752
- import { camelCase, constantCase as constantCase3 } from "change-case";
814
+ import { camelCase, constantCase as constantCase4 } from "change-case";
753
815
  var generateResourceTypes = async (config2) => {
754
816
  const files = [];
755
817
  await Promise.all(
@@ -860,7 +922,7 @@ var TypeObject = class {
860
922
  return this.add(camelCase(name), type);
861
923
  }
862
924
  addConst(name, type) {
863
- return this.add(constantCase3(name), type);
925
+ return this.add(constantCase4(name), type);
864
926
  }
865
927
  toString() {
866
928
  if (!this.types.size) {
@@ -883,43 +945,6 @@ var TypeObject = class {
883
945
  }
884
946
  };
885
947
 
886
- // src/formation/property/duration.ts
887
- var Duration = class _Duration {
888
- constructor(value) {
889
- this.value = value;
890
- }
891
- static milliseconds(value) {
892
- return new _Duration(value);
893
- }
894
- static seconds(value) {
895
- return new _Duration(value * 1e3 /* seconds */);
896
- }
897
- static minutes(value) {
898
- return new _Duration(value * 6e4 /* minutes */);
899
- }
900
- static hours(value) {
901
- return new _Duration(value * 36e5 /* hours */);
902
- }
903
- static days(value) {
904
- return new _Duration(value * 864e5 /* days */);
905
- }
906
- toMilliseconds() {
907
- return this.value;
908
- }
909
- toSeconds() {
910
- return Math.floor(this.value / 1e3 /* seconds */);
911
- }
912
- toMinutes() {
913
- return Math.floor(this.value / 6e4 /* minutes */);
914
- }
915
- toHours() {
916
- return Math.floor(this.value / 36e5 /* hours */);
917
- }
918
- toDays() {
919
- return Math.floor(this.value / 864e5 /* days */);
920
- }
921
- };
922
-
923
948
  // src/util/byte-size.ts
924
949
  import { filesize } from "filesize";
925
950
  var formatByteSize = (size) => {
@@ -1415,9 +1440,6 @@ var toLambdaFunction = (ctx, id, fileOrProps) => {
1415
1440
  lambda.addPermissions(fileOrProps.permissions);
1416
1441
  }
1417
1442
  lambda.addEnvironment("APP", config2.app.name).addEnvironment("STAGE", config2.app.stage).addEnvironment("STACK", stack.name);
1418
- if (props.log) {
1419
- lambda.enableLogs(props.log instanceof Duration ? props.log : void 0);
1420
- }
1421
1443
  if (props.warm) {
1422
1444
  lambda.warmUp(props.warm);
1423
1445
  }
@@ -1444,7 +1466,7 @@ var toLambdaFunction = (ctx, id, fileOrProps) => {
1444
1466
  };
1445
1467
 
1446
1468
  // src/formation/resource/cognito/user-pool.ts
1447
- import { constantCase as constantCase4 } from "change-case";
1469
+ import { constantCase as constantCase5 } from "change-case";
1448
1470
 
1449
1471
  // src/formation/resource/cognito/user-pool-client.ts
1450
1472
  var UserPoolClient = class extends Resource {
@@ -1683,7 +1705,7 @@ var UserPoolEmail = class _UserPoolEmail {
1683
1705
  }
1684
1706
  toJSON() {
1685
1707
  return {
1686
- ...this.props.type ? { EmailSendingAccount: constantCase4(this.props.type) } : {},
1708
+ ...this.props.type ? { EmailSendingAccount: constantCase5(this.props.type) } : {},
1687
1709
  ...this.props.from ? { From: this.props.from } : {},
1688
1710
  ...this.props.replyTo ? { ReplyToEmailAddress: this.props.replyTo } : {},
1689
1711
  ...this.props.sourceArn ? { SourceArn: this.props.sourceArn } : {}
@@ -1692,7 +1714,7 @@ var UserPoolEmail = class _UserPoolEmail {
1692
1714
  };
1693
1715
 
1694
1716
  // src/plugins/auth/index.ts
1695
- import { constantCase as constantCase5 } from "change-case";
1717
+ import { constantCase as constantCase6 } from "change-case";
1696
1718
 
1697
1719
  // src/formation/resource/cloud-formation/custom-resource.ts
1698
1720
  var CustomResource = class extends Resource {
@@ -1732,7 +1754,7 @@ var authPlugin = definePlugin({
1732
1754
  if (props.access) {
1733
1755
  const userPoolId = bootstrap2.import(`auth-${id}-user-pool-id`);
1734
1756
  const clientId = bootstrap2.import(`auth-${id}-client-id`);
1735
- const name = constantCase5(id);
1757
+ const name = constantCase6(id);
1736
1758
  bind((lambda) => {
1737
1759
  lambda.addEnvironment(`AUTH_${name}_USER_POOL_ID`, userPoolId);
1738
1760
  lambda.addEnvironment(`AUTH_${name}_CLIENT_ID`, clientId);
@@ -2042,7 +2064,7 @@ var Port = class _Port {
2042
2064
  };
2043
2065
 
2044
2066
  // src/plugins/cache/index.ts
2045
- import { constantCase as constantCase6 } from "change-case";
2067
+ import { constantCase as constantCase7 } from "change-case";
2046
2068
  var typeGenCode2 = `
2047
2069
  import { Cluster, CommandOptions } from '@awsless/redis'
2048
2070
 
@@ -2094,8 +2116,8 @@ var cachePlugin = definePlugin({
2094
2116
  }).dependsOn(subnetGroup, securityGroup);
2095
2117
  stack.add(subnetGroup, securityGroup, cluster);
2096
2118
  bind((lambda) => {
2097
- lambda.addEnvironment(`CACHE_${constantCase6(stack.name)}_${constantCase6(id)}_HOST`, cluster.address).addEnvironment(
2098
- `CACHE_${constantCase6(stack.name)}_${constantCase6(id)}_PORT`,
2119
+ lambda.addEnvironment(`CACHE_${constantCase7(stack.name)}_${constantCase7(id)}_HOST`, cluster.address).addEnvironment(
2120
+ `CACHE_${constantCase7(stack.name)}_${constantCase7(id)}_PORT`,
2099
2121
  props.port.toString()
2100
2122
  );
2101
2123
  });
@@ -2247,6 +2269,7 @@ var cronPlugin = definePlugin({
2247
2269
  const lambda = toLambdaFunction(ctx, id, props.consumer);
2248
2270
  const source = new EventsEventSource(id, lambda, {
2249
2271
  schedule: props.schedule,
2272
+ enabled: props.enabled,
2250
2273
  payload: props.payload
2251
2274
  });
2252
2275
  stack.add(lambda, source);
@@ -2376,7 +2399,7 @@ var ConfigurationSet = class extends Resource {
2376
2399
  };
2377
2400
 
2378
2401
  // src/formation/resource/ses/email-identity.ts
2379
- import { constantCase as constantCase7 } from "change-case";
2402
+ import { constantCase as constantCase8 } from "change-case";
2380
2403
  var EmailIdentity = class extends Resource {
2381
2404
  constructor(logicalId, props) {
2382
2405
  super("AWS::SES::EmailIdentity", logicalId);
@@ -2437,7 +2460,7 @@ var EmailIdentity = class extends Resource {
2437
2460
  SigningEnabled: true
2438
2461
  },
2439
2462
  DkimSigningAttributes: {
2440
- NextSigningKeyLength: constantCase7(this.props.dkim)
2463
+ NextSigningKeyLength: constantCase8(this.props.dkim)
2441
2464
  }
2442
2465
  } : {},
2443
2466
  FeedbackAttributes: {
@@ -3268,7 +3291,7 @@ var LoadBalancer = class extends Resource {
3268
3291
  };
3269
3292
 
3270
3293
  // src/formation/resource/elb/listener.ts
3271
- import { constantCase as constantCase8 } from "change-case";
3294
+ import { constantCase as constantCase9 } from "change-case";
3272
3295
  var Listener = class extends Resource {
3273
3296
  constructor(logicalId, props) {
3274
3297
  super("AWS::ElasticLoadBalancingV2::Listener", logicalId);
@@ -3284,7 +3307,7 @@ var Listener = class extends Resource {
3284
3307
  return {
3285
3308
  LoadBalancerArn: this.props.loadBalancerArn,
3286
3309
  Port: this.props.port,
3287
- Protocol: constantCase8(this.props.protocol),
3310
+ Protocol: constantCase9(this.props.protocol),
3288
3311
  Certificates: this.props.certificates.map((arn) => ({
3289
3312
  CertificateArn: arn
3290
3313
  })),
@@ -3637,7 +3660,7 @@ var httpPlugin = definePlugin({
3637
3660
  });
3638
3661
 
3639
3662
  // src/formation/resource/lambda/event-source-mapping.ts
3640
- import { constantCase as constantCase9 } from "change-case";
3663
+ import { constantCase as constantCase10 } from "change-case";
3641
3664
  var EventSourceMapping = class extends Resource {
3642
3665
  constructor(logicalId, props) {
3643
3666
  super("AWS::Lambda::EventSourceMapping", logicalId);
@@ -3659,7 +3682,7 @@ var EventSourceMapping = class extends Resource {
3659
3682
  ...this.attr("ParallelizationFactor", this.props.parallelizationFactor),
3660
3683
  ...this.attr("TumblingWindowInSeconds", this.props.tumblingWindow?.toSeconds()),
3661
3684
  ...this.attr("BisectBatchOnFunctionError", this.props.bisectBatchOnError),
3662
- ...this.attr("StartingPosition", this.props.startingPosition && constantCase9(this.props.startingPosition)),
3685
+ ...this.attr("StartingPosition", this.props.startingPosition && constantCase10(this.props.startingPosition)),
3663
3686
  ...this.attr("StartingPositionTimestamp", this.props.startingPositionTimestamp),
3664
3687
  ...this.props.maxConcurrency ? {
3665
3688
  ScalingConfig: {
@@ -3855,7 +3878,7 @@ var pubsubPlugin = definePlugin({
3855
3878
  });
3856
3879
 
3857
3880
  // src/plugins/queue/index.ts
3858
- import { camelCase as camelCase4, constantCase as constantCase10 } from "change-case";
3881
+ import { camelCase as camelCase4, constantCase as constantCase11 } from "change-case";
3859
3882
  import { relative as relative4 } from "path";
3860
3883
  var typeGenCode3 = `
3861
3884
  import { SendMessageOptions, SendMessageBatchOptions, BatchItem } from '@awsless/sqs'
@@ -3924,7 +3947,7 @@ var queuePlugin = definePlugin({
3924
3947
  stack.add(queue2, lambda, source);
3925
3948
  bind((lambda2) => {
3926
3949
  lambda2.addPermissions(queue2.permissions);
3927
- lambda2.addEnvironment(`QUEUE_${constantCase10(stack.name)}_${constantCase10(id)}_URL`, queue2.url);
3950
+ lambda2.addEnvironment(`QUEUE_${constantCase11(stack.name)}_${constantCase11(id)}_URL`, queue2.url);
3928
3951
  });
3929
3952
  }
3930
3953
  }
@@ -4874,7 +4897,7 @@ var storePlugin = definePlugin({
4874
4897
  });
4875
4898
 
4876
4899
  // src/formation/resource/dynamodb/table.ts
4877
- import { constantCase as constantCase11 } from "change-case";
4900
+ import { constantCase as constantCase12 } from "change-case";
4878
4901
  var Table = class extends Resource {
4879
4902
  constructor(logicalId, props) {
4880
4903
  super("AWS::DynamoDB::Table", logicalId);
@@ -4959,7 +4982,7 @@ var Table = class extends Resource {
4959
4982
  return {
4960
4983
  TableName: this.name,
4961
4984
  BillingMode: "PAY_PER_REQUEST",
4962
- TableClass: constantCase11(this.props.class || "standard"),
4985
+ TableClass: constantCase12(this.props.class || "standard"),
4963
4986
  PointInTimeRecoverySpecification: {
4964
4987
  PointInTimeRecoveryEnabled: this.props.pointInTimeRecovery || false
4965
4988
  },
@@ -4970,7 +4993,7 @@ var Table = class extends Resource {
4970
4993
  AttributeDefinitions: this.attributeDefinitions(),
4971
4994
  ...this.props.stream ? {
4972
4995
  StreamSpecification: {
4973
- StreamViewType: constantCase11(this.props.stream)
4996
+ StreamViewType: constantCase12(this.props.stream)
4974
4997
  }
4975
4998
  } : {},
4976
4999
  ...this.props.timeToLiveAttribute ? {
@@ -4987,7 +5010,7 @@ var Table = class extends Resource {
4987
5010
  ...props.sort ? [{ KeyType: "RANGE", AttributeName: props.sort }] : []
4988
5011
  ],
4989
5012
  Projection: {
4990
- ProjectionType: constantCase11(props.projection || "all")
5013
+ ProjectionType: constantCase12(props.projection || "all")
4991
5014
  }
4992
5015
  }))
4993
5016
  } : {}
@@ -5726,9 +5749,6 @@ var PermissionSchema = z7.object({
5726
5749
  resources: z7.string().array()
5727
5750
  });
5728
5751
  var PermissionsSchema = z7.union([PermissionSchema, PermissionSchema.array()]).describe("Add IAM permissions to your function.");
5729
- var LogSchema = z7.union([z7.boolean(), DurationSchema.refine(durationMin(Duration.days(1)), "Minimum log retention is 1 day")]).describe(
5730
- "Enable logging to a CloudWatch log group. Providing a duration value will set the log retention time."
5731
- );
5732
5752
  var WarmSchema = z7.number().int().min(0).max(10).describe(
5733
5753
  "Specify how many functions you want to warm up each 5 minutes. You can specify a number from 0 to 10."
5734
5754
  );
@@ -5736,6 +5756,25 @@ var VPCSchema = z7.boolean().describe("Put the function inside your global VPC."
5736
5756
  var MinifySchema = z7.boolean().describe("Minify the function code.");
5737
5757
  var HandlerSchema = z7.string().describe("The name of the exported method within your code that Lambda calls to run your function.");
5738
5758
  var FileSchema = LocalFileSchema.describe("The file path of the function code.");
5759
+ var LogRetentionSchema = DurationSchema.refine(durationMin(Duration.days(1)), "Minimum log retention is 1 day");
5760
+ var LogSchema = z7.union([
5761
+ z7.boolean(),
5762
+ LogRetentionSchema,
5763
+ z7.object({
5764
+ retention: LogRetentionSchema.describe("The log retention duration."),
5765
+ format: z7.enum(["text", "json"]).describe(
5766
+ `The format in which Lambda sends your function's application and system logs to CloudWatch. Select between plain text and structured JSON.`
5767
+ ).optional(),
5768
+ system: z7.enum(["debug", "info", "warn"]).describe(
5769
+ "Set this property to filter the system logs for your function that Lambda sends to CloudWatch. Lambda only sends system logs at the selected level of detail and lower, where DEBUG is the highest level and WARN is the lowest."
5770
+ ).optional(),
5771
+ level: z7.enum(["trace", "debug", "info", "warn", "error", "fatal"]).describe(
5772
+ "Set this property to filter the application logs for your function that Lambda sends to CloudWatch. Lambda only sends application logs at the selected level of detail and lower, where TRACE is the highest level and FATAL is the lowest."
5773
+ ).optional()
5774
+ })
5775
+ ]).describe(
5776
+ "Enable logging to a CloudWatch log group. Providing a duration value will set the log retention time."
5777
+ );
5739
5778
  var FunctionSchema = z7.union([
5740
5779
  LocalFileSchema,
5741
5780
  z7.object({
@@ -5762,7 +5801,12 @@ var FunctionDefaultSchema = z7.object({
5762
5801
  minify: MinifySchema.default(true),
5763
5802
  warm: WarmSchema.default(0),
5764
5803
  vpc: VPCSchema.default(false),
5765
- log: LogSchema.default(false),
5804
+ log: LogSchema.default({
5805
+ retention: "7 days",
5806
+ level: "error",
5807
+ system: "warn",
5808
+ format: "json"
5809
+ }),
5766
5810
  timeout: TimeoutSchema.default("10 seconds"),
5767
5811
  runtime: RuntimeSchema.default("nodejs20.x"),
5768
5812
  memorySize: MemorySizeSchema.default("128 MB"),
@@ -6078,6 +6122,7 @@ var ScheduleExpressionSchema = RateExpressionSchema.or(CronExpressionSchema);
6078
6122
  var CronsSchema = z17.record(
6079
6123
  ResourceIdSchema,
6080
6124
  z17.object({
6125
+ enabled: z17.boolean().default(true).describe("If the cron is enabled."),
6081
6126
  consumer: FunctionSchema.describe("The consuming lambda function properties."),
6082
6127
  schedule: ScheduleExpressionSchema.describe(
6083
6128
  'The scheduling expression.\n\nexample: "0 20 * * ? *"\nexample: "5 minutes"'