@beesolve/aws-accounts 1.0.2 → 1.0.4

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,6 +1,7 @@
1
1
  import { readFile, writeFile } from "node:fs/promises";
2
2
  import { createInterface } from "node:readline/promises";
3
- import { resolve } from "node:path";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
4
5
  import * as v from "valibot";
5
6
  import {
6
7
  CreateBucketCommand,
@@ -66,7 +67,6 @@ const contextFilePath = "aws.context.json";
66
67
  const configFilePath = "aws.config.ts";
67
68
  const typesFilePath = "aws.config.types.ts";
68
69
  const cachePath = ".remote-state-cache.json";
69
- const lambdaZipPath = "dist-lambda/lambda.zip";
70
70
  const lambdaRoleName = "beesolve-aws-accounts-lambda-role";
71
71
  const lambdaFunctionName = "beesolve-aws-accounts";
72
72
  async function runRemoteBootstrap(input) {
@@ -273,12 +273,14 @@ async function ensureLambdaFunction(props) {
273
273
  if (existingArn === "") {
274
274
  throw new Error("Lambda function exists but ARN is empty.");
275
275
  }
276
+ await waitForLambdaReady(props.lambdaClient, lambdaFunctionName);
276
277
  await props.lambdaClient.send(
277
278
  new UpdateFunctionCodeCommand({
278
279
  FunctionName: lambdaFunctionName,
279
280
  ZipFile: props.lambdaZip
280
281
  })
281
282
  );
283
+ await waitForLambdaReady(props.lambdaClient, lambdaFunctionName);
282
284
  await props.lambdaClient.send(
283
285
  new UpdateFunctionConfigurationCommand({
284
286
  FunctionName: lambdaFunctionName,
@@ -565,6 +567,7 @@ async function runRemoteUpgrade(input) {
565
567
  const deployment = await readDeploymentFromContext();
566
568
  const lambdaZip = await readLambdaZip();
567
569
  input.logger.log(`Updating Lambda function code: ${deployment.lambdaArn}`);
570
+ await waitForLambdaReady(input.lambdaClient, deployment.lambdaArn);
568
571
  const updateResult = await input.lambdaClient.send(
569
572
  new UpdateFunctionCodeCommand({
570
573
  FunctionName: deployment.lambdaArn,
@@ -909,11 +912,35 @@ async function createNewPermissionSet(props) {
909
912
  return permissionSetArn;
910
913
  }
911
914
  async function readLambdaZip() {
915
+ const thisFile = fileURLToPath(import.meta.url);
916
+ const packageDir = dirname(dirname(dirname(thisFile)));
917
+ const zipPath = join(packageDir, "dist-lambda", "lambda.zip");
912
918
  try {
913
- return await readFile(resolve(lambdaZipPath));
919
+ return await readFile(zipPath);
914
920
  } catch {
915
- throw new Error("dist-lambda/lambda.zip not found. Run `npm run build:lambda` first.");
921
+ throw new Error(
922
+ `Lambda zip not found at ${zipPath}. The package may be corrupted \u2014 try reinstalling @beesolve/aws-accounts.`
923
+ );
924
+ }
925
+ }
926
+ async function waitForLambdaReady(lambdaClient, functionName) {
927
+ const maxAttempts = 30;
928
+ for (let i = 0; i < maxAttempts; i++) {
929
+ const response = await lambdaClient.send(
930
+ new GetFunctionCommand({ FunctionName: functionName })
931
+ );
932
+ const lastUpdateStatus = response.Configuration?.LastUpdateStatus;
933
+ if (lastUpdateStatus === "Successful" || lastUpdateStatus === void 0) {
934
+ return;
935
+ }
936
+ if (lastUpdateStatus === "Failed") {
937
+ throw new Error(
938
+ `Lambda function update failed: ${response.Configuration?.LastUpdateStatusReason ?? "unknown reason"}`
939
+ );
940
+ }
941
+ await delay(2e3);
916
942
  }
943
+ throw new Error("Timed out waiting for Lambda function to become ready.");
917
944
  }
918
945
  export {
919
946
  runRemoteApply,
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beesolve/aws-accounts",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "AWS Organizations and IAM Identity Center management CLI",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {