@aptos-scp/isl-component-resource-definition 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -2,6 +2,66 @@
2
2
 
3
3
  Component is used to automate the initialization of AWS resources, specifically AWS EventBridge, based on user-defined metadata.
4
4
 
5
+ ## Usage
6
+
7
+ The component provides a CLI wrapper for AWS SAM commands with environment variable substitution.
8
+
9
+ ### Basic Usage
10
+
11
+ ```bash
12
+ resource-definition deploy --stack-name %STACK_NAME%
13
+ ```
14
+
15
+ ### Environment Variable Substitution
16
+
17
+ Arguments wrapped with `%` are replaced with their corresponding environment variable values:
18
+
19
+ ```bash
20
+ # If STACK_NAME=my-stack
21
+ resource-definition deploy --stack-name %STACK_NAME%
22
+ # Executes: sam deploy --stack-name my-stack
23
+ ```
24
+
25
+ ### Parameter Overrides
26
+
27
+ The `PARAMETER_OVERRIDE` environment variable supports special handling for nested environment variables:
28
+
29
+ #### Key-Value with Environment Variable Reference
30
+
31
+ ```bash
32
+ # Environment variables:
33
+ # PARAMETER_OVERRIDE="IslSample=$ISL_SAMPLE IslResponseEventbusArn=arn:aws:events:eu-west-1:123456789:event-bus/my-bus"
34
+ # ISL_SAMPLE=sample-value
35
+
36
+ resource-definition deploy --parameter-overrides %PARAMETER_OVERRIDE%
37
+ # Executes: sam deploy --parameter-overrides IslSample=sample-value IslResponseEventbusArn=arn:aws:events:eu-west-1:123456789:event-bus/my-bus
38
+ ```
39
+
40
+ #### Standalone Environment Variable Reference
41
+
42
+ When `PARAMETER_OVERRIDE` contains `$ENV_VAR_NAME` without a key, the environment variable name is converted to PascalCase as the key:
43
+
44
+ ```bash
45
+ # Environment variables:
46
+ # PARAMETER_OVERRIDE="$ISL_RESPONSE_EVENTBUS_ARN"
47
+ # ISL_RESPONSE_EVENTBUS_ARN=arn:aws:events:eu-west-1:123456789:event-bus/my-bus
48
+
49
+ resource-definition deploy --parameter-overrides %PARAMETER_OVERRIDE%
50
+ # Executes: sam deploy --parameter-overrides IslResponseEventbusArn=arn:aws:events:eu-west-1:123456789:event-bus/my-bus
51
+ ```
52
+
53
+ #### Mixed Format
54
+
55
+ ```bash
56
+ # Environment variables:
57
+ # PARAMETER_OVERRIDE="$ISL_SAMPLE CustomKey=$CUSTOM_VALUE StaticKey=static-value"
58
+ # ISL_SAMPLE=sample-value
59
+ # CUSTOM_VALUE=custom-resolved
60
+
61
+ resource-definition deploy --parameter-overrides %PARAMETER_OVERRIDE%
62
+ # Executes: sam deploy --parameter-overrides IslSample=sample-value CustomKey=custom-resolved StaticKey=static-value
63
+ ```
64
+
5
65
  ## Establish environment variables (workstation installation)
6
66
 
7
67
  Copy the .env.example file with default/sample environment variables for development to .env.
@@ -2,4 +2,6 @@ import { IResourceDefinition } from "../interfaces/IResourceDefinition";
2
2
  export declare class SamResourceDefinition implements IResourceDefinition {
3
3
  execute(inputCommand: string, args: string[]): Promise<void>;
4
4
  private evaluateEnvVars;
5
+ private evaluateParameterOverride;
6
+ private snakeCaseToPascalCase;
5
7
  }
@@ -30,11 +30,49 @@ class SamResourceDefinition {
30
30
  return args.map((arg) => {
31
31
  if (arg.startsWith("%") && arg.endsWith("%")) {
32
32
  const envVar = arg.slice(1, -1);
33
- return process.env[envVar] || "";
33
+ const envValue = process.env[envVar] || "";
34
+ if (envVar === "PARAMETER_OVERRIDE") {
35
+ return this.evaluateParameterOverride(envValue);
36
+ }
37
+ return envValue;
34
38
  }
35
39
  return arg;
36
40
  });
37
41
  }
42
+ evaluateParameterOverride(value) {
43
+ return value
44
+ .split(" ")
45
+ .filter((item) => item.trim() !== "")
46
+ .map((pair) => {
47
+ const equalsIndex = pair.indexOf("=");
48
+ // Handle standalone $ENV_VAR without key=value format
49
+ if (equalsIndex === -1 && pair.startsWith("$")) {
50
+ const envVarName = pair.slice(1);
51
+ const pascalCaseKey = this.snakeCaseToPascalCase(envVarName);
52
+ const envValue = process.env[envVarName] || "";
53
+ return `${pascalCaseKey}=${envValue}`;
54
+ }
55
+ if (equalsIndex === -1) {
56
+ return pair;
57
+ }
58
+ const key = pair.slice(0, equalsIndex);
59
+ const pairValue = pair.slice(equalsIndex + 1);
60
+ if (pairValue.startsWith("$")) {
61
+ const nestedEnvVar = pairValue.slice(1);
62
+ const nestedValue = process.env[nestedEnvVar] || "";
63
+ return `${key}=${nestedValue}`;
64
+ }
65
+ return pair;
66
+ })
67
+ .join(" ");
68
+ }
69
+ snakeCaseToPascalCase(snakeCase) {
70
+ return snakeCase
71
+ .toLowerCase()
72
+ .split("_")
73
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
74
+ .join("");
75
+ }
38
76
  }
39
77
  exports.SamResourceDefinition = SamResourceDefinition;
40
78
  //# sourceMappingURL=SamResourceDefinition.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptos-scp/isl-component-resource-definition",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Component is used to create Serverless application",
5
5
  "private": false,
6
6
  "license": "SEE LICENSE IN LICENSE.md",