@beesolve/aws-accounts 1.0.3 → 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.
@@ -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,
@@ -920,6 +923,25 @@ async function readLambdaZip() {
920
923
  );
921
924
  }
922
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);
942
+ }
943
+ throw new Error("Timed out waiting for Lambda function to become ready.");
944
+ }
923
945
  export {
924
946
  runRemoteApply,
925
947
  runRemoteBootstrap,
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beesolve/aws-accounts",
3
- "version": "1.0.3",
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": {