@beesolve/aws-accounts 1.0.3 → 1.0.5

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.
@@ -116,7 +116,11 @@ async function runRemoteBootstrap(input) {
116
116
  resolvedRegion,
117
117
  logger: input.logger
118
118
  });
119
- const context = await readAwsContextFromFile(contextFilePath);
119
+ let context = null;
120
+ try {
121
+ context = await readAwsContextFromFile(contextFilePath);
122
+ } catch {
123
+ }
120
124
  const deployment = {
121
125
  profile: input.profile ?? "",
122
126
  region: resolvedRegion,
@@ -124,8 +128,11 @@ async function runRemoteBootstrap(input) {
124
128
  stateBucketName: bucketName,
125
129
  stateCacheTtlSeconds: 300
126
130
  };
127
- const updatedContext = {
128
- ...context,
131
+ const updatedContext = context != null ? { ...context, deployment } : {
132
+ version: "1",
133
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
134
+ organization: { managementAccountId: accountId, rootId: "pending", graveyardOuId: "pending" },
135
+ identityCenter: { instanceArn: "pending", identityStoreId: "pending" },
129
136
  deployment
130
137
  };
131
138
  const ordered = {
@@ -138,7 +145,7 @@ async function runRemoteBootstrap(input) {
138
145
  await writeFile(contextFilePath, `${JSON.stringify(ordered, null, 2)}
139
146
  `, "utf8");
140
147
  const instanceArn = updatedContext.identityCenter?.instanceArn;
141
- if (instanceArn != null && instanceArn !== "") {
148
+ if (instanceArn != null && instanceArn !== "" && instanceArn !== "pending") {
142
149
  await ensureOrganizationManagementPermissionSet({
143
150
  ssoAdminClient: input.ssoAdminClient,
144
151
  instanceArn,
@@ -273,12 +280,14 @@ async function ensureLambdaFunction(props) {
273
280
  if (existingArn === "") {
274
281
  throw new Error("Lambda function exists but ARN is empty.");
275
282
  }
283
+ await waitForLambdaReady(props.lambdaClient, lambdaFunctionName);
276
284
  await props.lambdaClient.send(
277
285
  new UpdateFunctionCodeCommand({
278
286
  FunctionName: lambdaFunctionName,
279
287
  ZipFile: props.lambdaZip
280
288
  })
281
289
  );
290
+ await waitForLambdaReady(props.lambdaClient, lambdaFunctionName);
282
291
  await props.lambdaClient.send(
283
292
  new UpdateFunctionConfigurationCommand({
284
293
  FunctionName: lambdaFunctionName,
@@ -565,6 +574,7 @@ async function runRemoteUpgrade(input) {
565
574
  const deployment = await readDeploymentFromContext();
566
575
  const lambdaZip = await readLambdaZip();
567
576
  input.logger.log(`Updating Lambda function code: ${deployment.lambdaArn}`);
577
+ await waitForLambdaReady(input.lambdaClient, deployment.lambdaArn);
568
578
  const updateResult = await input.lambdaClient.send(
569
579
  new UpdateFunctionCodeCommand({
570
580
  FunctionName: deployment.lambdaArn,
@@ -920,6 +930,25 @@ async function readLambdaZip() {
920
930
  );
921
931
  }
922
932
  }
933
+ async function waitForLambdaReady(lambdaClient, functionName) {
934
+ const maxAttempts = 30;
935
+ for (let i = 0; i < maxAttempts; i++) {
936
+ const response = await lambdaClient.send(
937
+ new GetFunctionCommand({ FunctionName: functionName })
938
+ );
939
+ const lastUpdateStatus = response.Configuration?.LastUpdateStatus;
940
+ if (lastUpdateStatus === "Successful" || lastUpdateStatus === void 0) {
941
+ return;
942
+ }
943
+ if (lastUpdateStatus === "Failed") {
944
+ throw new Error(
945
+ `Lambda function update failed: ${response.Configuration?.LastUpdateStatusReason ?? "unknown reason"}`
946
+ );
947
+ }
948
+ await delay(2e3);
949
+ }
950
+ throw new Error("Timed out waiting for Lambda function to become ready.");
951
+ }
923
952
  export {
924
953
  runRemoteApply,
925
954
  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.5",
4
4
  "description": "AWS Organizations and IAM Identity Center management CLI",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {