Repository: pwrdrvr/microapps-core (language: python)

Issue:
v0.3 - Fix deploying to AWS Accounts IDs with leading zeros
## Motivations
- Failures observed deploying to AWS Accounts IDs that have a leading zero

## To-Do
- Fix `microapps-publish` to handle Account ID as a string
- Fix `deployer-svc` to handle Account ID as a string


Discussion / hints:

Fix patch:
diff --git a/packages/microapps-deployer/src/config/Config.ts b/packages/microapps-deployer/src/config/Config.ts
index 08f984be..cef23e29 100644
--- a/packages/microapps-deployer/src/config/Config.ts
+++ b/packages/microapps-deployer/src/config/Config.ts
@@ -15,7 +15,7 @@ export interface IConfig {
   readonly apigwy: IAPIGateway;
   readonly filestore: IFileStore;
 
-  readonly awsAccountID: number;
+  readonly awsAccountID: string;
   readonly awsRegion: string;
 
   readonly uploadRoleName: string;
@@ -95,10 +95,10 @@ export class Config implements IConfig {
 
   @convict.Property({
     doc: 'AWS Account ID for app Lambda function',
-    default: 0,
+    default: '',
     env: 'AWS_ACCOUNT_ID',
   })
-  public awsAccountID!: number;
+  public awsAccountID!: string;
 
   @convict.Property({
     doc: 'AWS Region for app Lambda function',
diff --git a/packages/microapps-deployer/src/controllers/VersionController.spec.ts b/packages/microapps-deployer/src/controllers/VersionController.spec.ts
index 848bc77c..3d8735aa 100644
--- a/packages/microapps-deployer/src/controllers/VersionController.spec.ts
+++ b/packages/microapps-deployer/src/controllers/VersionController.spec.ts
@@ -5,7 +5,7 @@ import { Config, IConfig } from '../config/Config';
 jest.mock('../config/Config');
 type Writeable<T> = { -readonly [P in keyof T]: T[P] };
 const theConfig: Writeable<IConfig> = {
-  awsAccountID: 123456789,
+  awsAccountID: '00123456789',
   awsRegion: 'mock',
   db: {
     tableName: 'microapps',
diff --git a/packages/microapps-deployer/src/index.ts b/packages/microapps-deployer/src/index.ts
index 6f0a20c1..df1e5cac 100644
--- a/packages/microapps-deployer/src/index.ts
+++ b/packages/microapps-deployer/src/index.ts
@@ -53,12 +53,12 @@ export async function handler(
   }
 
   // Get the current AWS Account ID, once, if not set as env var
-  if (config.awsAccountID === 0 && context?.invokedFunctionArn !== undefined) {
+  if (config.awsAccountID === '' && context?.invokedFunctionArn !== undefined) {
     const parts = context.invokedFunctionArn.split(':');
     const accountIDStr = parts[4];
     if (accountIDStr !== '') {
       // @ts-expect-error we want to overwrite this config value
-      config.awsAccountID = parseInt(accountIDStr, 10);
+      config.awsAccountID = accountIDStr;
     }
   }
 
diff --git a/packages/microapps-edge-to-origin/src/config/config.spec.ts b/packages/microapps-edge-to-origin/src/config/config.spec.ts
index b1696ceb..66b68a69 100644
--- a/packages/microapps-edge-to-origin/src/config/config.spec.ts
+++ b/packages/microapps-edge-to-origin/src/config/config.spec.ts
@@ -10,7 +10,7 @@ type IPartialConfig = Partial<Config>;
 describe('config', () => {
   it('handles funky string enum', () => {
     const rawConfig: IConfig = {
-      awsAccountID: 123,
+      awsAccountID: '123',
       awsRegion: 'us-east-1',
       originRegion: 'us-east-2',
       addXForwardedHostHeader: true,
@@ -23,7 +23,7 @@ describe('config', () => {
     const config = loader.load(rawConfig);
 
     expect(config).toBeDefined();
-    expect(config.awsAccountID).toBe(123);
+    expect(config.awsAccountID).toBe('123');
     expect(config.awsRegion).toBe(process.env.AWS_REGION || 'us-east-1');
     expect(config.originRegion).toBe('us-east-2');
     expect(config.addXForwardedHostHeader).toBe(true);
@@ -37,7 +37,7 @@ describe('config', () => {
     const config = loader.load(rawConfig);
 
     expect(config).toBeDefined();
-    expect(config.awsAccountID).toBe(0);
+    expect(config.awsAccountID).toBe('');
     expect(config.awsRegion).toBe(process.env.AWS_REGION || 'us-east-1');
     expect(config.originRegion).toBe('us-east-2');
     expect(config.addXForwardedHostHeader).toBe(true);
@@ -50,7 +50,7 @@ describe('config', () => {
     const config = loader.load(path.join(__dirname, './config.test.yml'));
 
     expect(config).toBeDefined();
-    expect(config.awsAccountID).toBe(0);
+    expect(config.awsAccountID).toBe('00123456');
     expect(config.awsRegion).toBe(process.env.AWS_REGION || 'us-east-2');
     expect(config.originRegion).toBe('us-east-2');
     expect(config.addXForwardedHostHeader).toBe(true);
diff --git a/packages/microapps-edge-to-origin/src/config/config.ts b/packages/microapps-edge-to-origin/src/config/config.ts
index 2893ea51..f55c95a8 100644
--- a/packages/microapps-edge-to-origin/src/config/config.ts
+++ b/packages/microapps-edge-to-origin/src/config/config.ts
@@ -7,7 +7,7 @@ import { FilesExist } from '../lib/files-exist';
  * Represents a Config
  */
 export interface IConfig {
-  readonly awsAccountID: number;
+  readonly awsAccountID: string;
   readonly awsRegion: string;
 
   /**
@@ -112,10 +112,10 @@ export class Config implements IConfig {
 
   @convict.Property({
     doc: 'AWS Account ID for app Lambda function',
-    default: 0,
+    default: '',
     env: 'AWS_ACCOUNT_ID',
   })
-  public awsAccountID!: number;
+  public awsAccountID!: string;
 
   @convict.Property({
     doc: 'AWS Region for app Lambda function',
diff --git a/packages/microapps-edge-to-origin/src/index.route.prefix.spec.ts b/packages/microapps-edge-to-origin/src/index.route.prefix.spec.ts
index 177a2d8e..b78a91ad 100644
--- a/packages/microapps-edge-to-origin/src/index.route.prefix.spec.ts
+++ b/packages/microapps-edge-to-origin/src/index.route.prefix.spec.ts
@@ -8,7 +8,7 @@ import { Config, IConfig } from './config/config';
 jest.mock('./config/config');
 type Writeable<T> = { -readonly [P in keyof T]: T[P] };
 const theConfig: Writeable<IConfig> = {
-  awsAccountID: 123456,
+  awsAccountID: '00123456',
   awsRegion: 'mock',
   addXForwardedHostHeader: false,
   originRegion: 'us-west-1',
diff --git a/packages/microapps-edge-to-origin/src/index.route.root.spec.ts b/packages/microapps-edge-to-origin/src/index.route.root.spec.ts
index 43cdd8c5..87172a5e 100644
--- a/packages/microapps-edge-to-origin/src/index.route.root.spec.ts
+++ b/packages/microapps-edge-to-origin/src/index.route.root.spec.ts
@@ -8,7 +8,7 @@ import { Config, IConfig } from './config/config';
 jest.mock('./config/config');
 type Writeable<T> = { -readonly [P in keyof T]: T[P] };
 const theConfig: Writeable<IConfig> = {
-  awsAccountID: 123456,
+  awsAccountID: '00123456',
   awsRegion: 'mock',
   addXForwardedHostHeader: false,
   originRegion: 'us-west-1',
diff --git a/packages/microapps-edge-to-origin/src/index.route.spec.ts b/packages/microapps-edge-to-origin/src/index.route.spec.ts
index bd063d7b..8fa319a8 100644
--- a/packages/microapps-edge-to-origin/src/index.route.spec.ts
+++ b/packages/microapps-edge-to-origin/src/index.route.spec.ts
@@ -8,7 +8,7 @@ import { Config, IConfig } from './config/config';
 jest.mock('./config/config');
 type Writeable<T> = { -readonly [P in keyof T]: T[P] };
 const theConfig: Writeable<IConfig> = {
-  awsAccountID: 123456,
+  awsAccountID: '00123456',
   awsRegion: 'mock',
   addXForwardedHostHeader: false,
   originRegion: 'us-west-1',
diff --git a/packages/microapps-edge-to-origin/src/index.spec.ts b/packages/microapps-edge-to-origin/src/index.spec.ts
index cc02f104..61da1572 100644
--- a/packages/microapps-edge-to-origin/src/index.spec.ts
+++ b/packages/microapps-edge-to-origin/src/index.spec.ts
@@ -5,7 +5,7 @@ import { Config, IConfig } from './config/config';
 jest.mock('./config/config');
 type Writeable<T> = { -readonly [P in keyof T]: T[P] };
 const theConfig: Writeable<IConfig> = {
-  awsAccountID: 123456,
+  awsAccountID: '00123456',
   awsRegion: 'mock',
   addXForwardedHostHeader: false,
   originRegion: 'us-west-1',
diff --git a/packages/microapps-publish/microapps.json b/packages/microapps-publish/microapps.json
index 1d0f2326..164b106a 100644
--- a/packages/microapps-publish/microapps.json
+++ b/packages/microapps-publish/microapps.json
@@ -5,7 +5,7 @@
     "defaultFile": "",
     "staticAssetsPath": "./.serverless_nextjs/assets/appname/0.0.0/",
     "lambdaName": "appname",
-    "awsAccountID": 123456789012,
+    "awsAccountID": "00123456789012",
     "awsRegion": "us-east-1",
     "serverlessNextRouterPath": "./node_modules/@pwrdrvr/serverless-nextjs-router/dist/index.js"
   }
diff --git a/packages/microapps-publish/microapps.yaml b/packages/microapps-publish/microapps.yaml
index 246ab691..deaa8573 100644
--- a/packages/microapps-publish/microapps.yaml
+++ b/packages/microapps-publish/microapps.yaml
@@ -4,6 +4,6 @@ app:
   defaultFile: ""
   staticAssetsPath: ./.serverless_nextjs/assets/appname/0.0.0/
   lambdaName: appname
-  awsAccountID: 123456789012
+  awsAccountID: '00123456789012'
   awsRegion: us-east-1
   serverlessNextRouterPath: ./node_modules/@pwrdrvr/serverless-nextjs-router/dist/index.js
diff --git a/packages/microapps-publish/src/commands/delete.ts b/packages/microapps-publish/src/commands/delete.ts
index 93afba19..0faae1b6 100644
--- a/packages/microapps-publish/src/commands/delete.ts
+++ b/packages/microapps-publish/src/commands/delete.ts
@@ -61,13 +61,13 @@ export class DeleteCommand extends Command {
 
     // Get the account ID and region from STS
     // TODO: Move this to the right place
-    if (config.app.awsAccountID === 0 || config.app.awsRegion === '') {
+    if (config.app.awsAccountID === '' || config.app.awsRegion === '') {
       const stsClient = new sts.STSClient({
         maxAttempts: 8,
       });
       const stsResponse = await stsClient.send(new sts.GetCallerIdentityCommand({}));
-      if (config.app.awsAccountID === 0) {
-        config.app.awsAccountID = parseInt(stsResponse.Account, 10);
+      if (config.app.awsAccountID === '') {
+        config.app.awsAccountID = stsResponse.Account;
       }
       if (config.app.awsRegion === '') {
         config.app.awsRegion = stsClient.config.region as string;
diff --git a/packages/microapps-publish/src/commands/nextjs-docker-auto.ts b/packages/microapps-publish/src/commands/nextjs-docker-auto.ts
index 7367f29a..3f12bab3 100755
--- a/packages/microapps-publish/src/commands/nextjs-docker-auto.ts
+++ b/packages/microapps-publish/src/commands/nextjs-docker-auto.ts
@@ -160,13 +160,13 @@ export class DockerAutoCommand extends Command {
 
     // Get the account ID and region from STS
     // TODO: Move this to the right place
-    if (config.app.awsAccountID === 0 || config.app.awsRegion === '') {
+    if (config.app.awsAccountID === '' || config.app.awsRegion === '') {
       const stsClient = new sts.STSClient({
         maxAttempts: 8,
       });
       const stsResponse = await stsClient.send(new sts.GetCallerIdentityCommand({}));
-      if (config.app.awsAccountID === 0) {
-        config.app.awsAccountID = parseInt(stsResponse.Account, 10);
+      if (config.app.awsAccountID === '') {
+        config.app.awsAccountID = stsResponse.Account;
       }
       if (config.app.awsRegion === '') {
         config.app.awsRegion = stsClient.config.region as string;
diff --git a/packages/microapps-publish/src/commands/preflight.ts b/packages/microapps-publish/src/commands/preflight.ts
index 4dfdbb90..167a686c 100644
--- a/packages/microapps-publish/src/commands/preflight.ts
+++ b/packages/microapps-publish/src/commands/preflight.ts
@@ -69,13 +69,13 @@ export class PreflightCommand extends Command {
 
     // Get the account ID and region from STS
     // TODO: Move this to the right place
-    if (config.app.awsAccountID === 0 || config.app.awsRegion === '') {
+    if (config.app.awsAccountID === '' || config.app.awsRegion === '') {
       const stsClient = new sts.STSClient({
         maxAttempts: 8,
       });
       const stsResponse = await stsClient.send(new sts.GetCallerIdentityCommand({}));
-      if (config.app.awsAccountID === 0) {
-        config.app.awsAccountID = parseInt(stsResponse.Account, 10);
+      if (config.app.awsAccountID === '') {
+        config.app.awsAccountID = stsResponse.Account;
       }
       if (config.app.awsRegion === '') {
         config.app.awsRegion = stsClient.config.region as string;
diff --git a/packages/microapps-publish/src/commands/publish-static.ts b/packages/microapps-publish/src/commands/publish-static.ts
index 0e3f0432..ab1ff43e 100644
--- a/packages/microapps-publish/src/commands/publish-static.ts
+++ b/packages/microapps-publish/src/commands/publish-static.ts
@@ -112,13 +112,13 @@ export class PublishCommand extends Command {
 
     // Get the account ID and region from STS
     // TODO: Move this to the right place
-    if (config.app.awsAccountID === 0 || config.app.awsRegion === '') {
+    if (config.app.awsAccountID === '' || config.app.awsRegion === '') {
       const stsClient = new sts.STSClient({
         maxAttempts: 8,
       });
       const stsResponse = await stsClient.send(new sts.GetCallerIdentityCommand({}));
-      if (config.app.awsAccountID === 0) {
-        config.app.awsAccountID = parseInt(stsResponse.Account, 10);
+      if (config.app.awsAccountID === '') {
+        config.app.awsAccountID = stsResponse.Account;
       }
       if (config.app.awsRegion === '') {
         config.app.awsRegion = stsClient.config.region as string;
diff --git a/packages/microapps-publish/src/commands/publish.ts b/packages/microapps-publish/src/commands/publish.ts
index 72810d38..cfa5cadb 100644
--- a/packages/microapps-publish/src/commands/publish.ts
+++ b/packages/microapps-publish/src/commands/publish.ts
@@ -145,13 +145,13 @@ export class PublishCommand extends Command {
 
     // Get the account ID and region from STS
     // TODO: Move this to the right place
-    if (config.app.awsAccountID === 0 || config.app.awsRegion === '') {
+    if (config.app.awsAccountID === '' || config.app.awsRegion === '') {
       const stsClient = new sts.STSClient({
         maxAttempts: 8,
       });
       const stsResponse = await stsClient.send(new sts.GetCallerIdentityCommand({}));
-      if (config.app.awsAccountID === 0) {
-        config.app.awsAccountID = parseInt(stsResponse.Account, 10);
+      if (config.app.awsAccountID === '') {
+        config.app.awsAccountID = stsResponse.Account;
       }
       if (config.app.awsRegion === '') {
         config.app.awsRegion = stsClient.config.region as string;
diff --git a/packages/microapps-publish/src/config/Application.ts b/packages/microapps-publish/src/config/Application.ts
index 7577457e..a1c01adc 100644
--- a/packages/microapps-publish/src/config/Application.ts
+++ b/packages/microapps-publish/src/config/Application.ts
@@ -12,7 +12,7 @@ export interface IApplicationConfig {
   staticAssetsPath: string;
   lambdaName: string;
   lambdaARN: string;
-  awsAccountID: number;
+  awsAccountID: string;
   awsRegion: string;
   serverlessNextRouterPath: string;
   ecrHost: string;
@@ -93,10 +93,10 @@ export class ApplicationConfig implements IApplicationConfig {
 
   @convict.Property({
     doc: 'AWS Account ID to deploy to',
-    default: 0,
+    default: '',
     env: 'AWS_ACCOUNT_ID',
   })
-  public awsAccountID: number;
+  public awsAccountID: string;
 
   @convict.Property({
     doc: 'AWS Region to deploy to',


Test patch:
diff --git a/packages/microapps-edge-to-origin/src/config/config.test.yml b/packages/microapps-edge-to-origin/src/config/config.test.yml
index afdfd68f..15b80f07 100644
--- a/packages/microapps-edge-to-origin/src/config/config.test.yml
+++ b/packages/microapps-edge-to-origin/src/config/config.test.yml
@@ -1,4 +1,5 @@
 awsRegion: us-east-2
 originRegion: us-east-2
 signingMode: sign
-replaceHostHeader: true
\ No newline at end of file
+replaceHostHeader: true
+awsAccountID: '00123456'
\ No newline at end of file