effortless-aws 0.14.2 → 0.14.3

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/dist/cli/index.js CHANGED
@@ -72271,46 +72271,68 @@ var ensureDistribution = (input) => Effect_exports.gen(function* () {
72271
72271
  };
72272
72272
  }
72273
72273
  yield* Effect_exports.logDebug("Creating CloudFront distribution (first deploy may take 5-15 minutes)...");
72274
+ const distConfig = {
72275
+ CallerReference: `${project2}-${stage}-${handlerName}-${Date.now()}`,
72276
+ Comment: comment,
72277
+ Origins: {
72278
+ Quantity: 1,
72279
+ Items: [
72280
+ {
72281
+ Id: originId,
72282
+ DomainName: originDomain,
72283
+ OriginAccessControlId: oacId,
72284
+ S3OriginConfig: { OriginAccessIdentity: "" }
72285
+ }
72286
+ ]
72287
+ },
72288
+ DefaultCacheBehavior: {
72289
+ TargetOriginId: originId,
72290
+ ViewerProtocolPolicy: "redirect-to-https",
72291
+ AllowedMethods: {
72292
+ Quantity: 2,
72293
+ Items: ["GET", "HEAD"],
72294
+ CachedMethods: { Quantity: 2, Items: ["GET", "HEAD"] }
72295
+ },
72296
+ Compress: true,
72297
+ CachePolicyId: CACHING_OPTIMIZED_POLICY_ID,
72298
+ FunctionAssociations: functionAssociations,
72299
+ LambdaFunctionAssociations: lambdaFunctionAssociations
72300
+ },
72301
+ Aliases: aliasesConfig,
72302
+ ...viewerCertificate ? { ViewerCertificate: viewerCertificate } : {},
72303
+ DefaultRootObject: index,
72304
+ Enabled: true,
72305
+ CustomErrorResponses: customErrorResponses,
72306
+ PriceClass: "PriceClass_All",
72307
+ HttpVersion: "http2and3"
72308
+ };
72274
72309
  const createResult = yield* cloudfront_exports.make("create_distribution_with_tags", {
72275
72310
  DistributionConfigWithTags: {
72276
- DistributionConfig: {
72277
- CallerReference: `${project2}-${stage}-${handlerName}-${Date.now()}`,
72278
- Comment: comment,
72279
- Origins: {
72280
- Quantity: 1,
72281
- Items: [
72282
- {
72283
- Id: originId,
72284
- DomainName: originDomain,
72285
- OriginAccessControlId: oacId,
72286
- S3OriginConfig: { OriginAccessIdentity: "" }
72287
- }
72288
- ]
72289
- },
72290
- DefaultCacheBehavior: {
72291
- TargetOriginId: originId,
72292
- ViewerProtocolPolicy: "redirect-to-https",
72293
- AllowedMethods: {
72294
- Quantity: 2,
72295
- Items: ["GET", "HEAD"],
72296
- CachedMethods: { Quantity: 2, Items: ["GET", "HEAD"] }
72297
- },
72298
- Compress: true,
72299
- CachePolicyId: CACHING_OPTIMIZED_POLICY_ID,
72300
- FunctionAssociations: functionAssociations,
72301
- LambdaFunctionAssociations: lambdaFunctionAssociations
72302
- },
72303
- Aliases: aliasesConfig,
72304
- ...viewerCertificate ? { ViewerCertificate: viewerCertificate } : {},
72305
- DefaultRootObject: index,
72306
- Enabled: true,
72307
- CustomErrorResponses: customErrorResponses,
72308
- PriceClass: "PriceClass_All",
72309
- HttpVersion: "http2and3"
72310
- },
72311
+ DistributionConfig: distConfig,
72311
72312
  Tags: { Items: toAwsTagList(tags2) }
72312
72313
  }
72313
- });
72314
+ }).pipe(
72315
+ // If CNAME is claimed by another distribution (e.g. DNS still points elsewhere),
72316
+ // retry without aliases so the deploy doesn't fail
72317
+ Effect_exports.catchIf(
72318
+ (e) => e._tag === "CloudFrontError" && e.is("CNAMEAlreadyExists"),
72319
+ () => Effect_exports.gen(function* () {
72320
+ const cnameList = aliases?.join(", ") ?? "";
72321
+ yield* Effect_exports.logWarning(
72322
+ `Domain ${cnameList} is still associated with another CloudFront distribution (DNS points elsewhere). Creating distribution without custom domain. Update your DNS records and redeploy to attach the domain.`
72323
+ );
72324
+ return yield* cloudfront_exports.make("create_distribution_with_tags", {
72325
+ DistributionConfigWithTags: {
72326
+ DistributionConfig: {
72327
+ ...distConfig,
72328
+ Aliases: { Quantity: 0, Items: [] }
72329
+ },
72330
+ Tags: { Items: toAwsTagList(tags2) }
72331
+ }
72332
+ });
72333
+ })
72334
+ )
72335
+ );
72314
72336
  const dist = createResult.Distribution;
72315
72337
  return {
72316
72338
  distributionId: dist.Id,
@@ -72320,24 +72342,30 @@ var ensureDistribution = (input) => Effect_exports.gen(function* () {
72320
72342
  });
72321
72343
  var findDistributionByTags = (project2, stage, handlerName) => Effect_exports.gen(function* () {
72322
72344
  const resources = yield* getResourcesByTags(project2, stage);
72323
- const dist = resources.find((r) => {
72345
+ const candidates = resources.filter((r) => {
72324
72346
  const isDistribution = r.ResourceARN?.includes(":distribution/");
72325
72347
  const handlerTag = r.Tags?.find((t) => t.Key === "effortless:handler");
72326
72348
  return isDistribution && handlerTag?.Value === handlerName;
72327
72349
  });
72328
- if (!dist?.ResourceARN) return void 0;
72329
- const distributionId = dist.ResourceARN.split("/").pop();
72330
- const result = yield* cloudfront_exports.make("get_distribution", { Id: distributionId }).pipe(
72331
- Effect_exports.catchIf(
72332
- (e) => e._tag === "CloudFrontError" && e.is("NoSuchDistribution"),
72333
- () => Effect_exports.succeed(void 0)
72334
- )
72335
- );
72336
- if (!result) return void 0;
72337
- return {
72338
- Id: distributionId,
72339
- DomainName: result.Distribution.DomainName
72340
- };
72350
+ for (const dist of candidates) {
72351
+ const distributionId = dist.ResourceARN.split("/").pop();
72352
+ const result = yield* cloudfront_exports.make("get_distribution", { Id: distributionId }).pipe(
72353
+ Effect_exports.catchIf(
72354
+ (e) => e._tag === "CloudFrontError" && e.is("NoSuchDistribution"),
72355
+ () => {
72356
+ Effect_exports.logDebug(`Distribution ${distributionId} no longer exists (stale tag), skipping`);
72357
+ return Effect_exports.succeed(void 0);
72358
+ }
72359
+ )
72360
+ );
72361
+ if (result) {
72362
+ return {
72363
+ Id: distributionId,
72364
+ DomainName: result.Distribution.DomainName
72365
+ };
72366
+ }
72367
+ }
72368
+ return void 0;
72341
72369
  });
72342
72370
  var invalidateDistribution = (distributionId) => Effect_exports.gen(function* () {
72343
72371
  yield* Effect_exports.logDebug(`Invalidating CloudFront distribution: ${distributionId}`);