@adobe/helix-deploy 6.2.25 → 6.2.26
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/deploy/AWSDeployer.js +51 -76
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [6.2.26](https://github.com/adobe/helix-deploy/compare/v6.2.25...v6.2.26) (2022-04-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Reverts
|
|
5
|
+
|
|
6
|
+
* Revert "fix(aws): link integration to v alias of function (#401)" ([ec6d70b](https://github.com/adobe/helix-deploy/commit/ec6d70bf5735ef3991497a1b13b0c63aaa42ce60)), closes [#401](https://github.com/adobe/helix-deploy/issues/401)
|
|
7
|
+
|
|
1
8
|
## [6.2.25](https://github.com/adobe/helix-deploy/compare/v6.2.24...v6.2.25) (2022-04-22)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -228,8 +228,7 @@ export default class AWSDeployer extends BaseDeployer {
|
|
|
228
228
|
if (e.name === 'ResourceNotFoundException') {
|
|
229
229
|
this.log.info(chalk`{green ok}: does not exist yet.`);
|
|
230
230
|
this.log.info(chalk`--: creating new Lambda function {yellow ${functionName}}`);
|
|
231
|
-
|
|
232
|
-
baseARN = res.FunctionArn;
|
|
231
|
+
await this._lambda.send(new CreateFunctionCommand(functionConfig));
|
|
233
232
|
} else {
|
|
234
233
|
this.log.error(chalk`Unable to verify existence of Lambda function {yellow ${functionName}}`);
|
|
235
234
|
throw e;
|
|
@@ -628,23 +627,21 @@ export default class AWSDeployer extends BaseDeployer {
|
|
|
628
627
|
Name: name,
|
|
629
628
|
}));
|
|
630
629
|
this.log.info(chalk`--: updating alias {blue ${name}}...`);
|
|
631
|
-
|
|
630
|
+
await this._lambda.send(new UpdateAliasCommand({
|
|
632
631
|
FunctionName: functionName,
|
|
633
632
|
Name: name,
|
|
634
633
|
FunctionVersion: functionVersion,
|
|
635
634
|
}));
|
|
636
635
|
this.log.info(chalk`{green ok:} updated alias {blue ${name}} to version {yellow ${functionVersion}}.`);
|
|
637
|
-
return res.AliasArn;
|
|
638
636
|
} catch (e) {
|
|
639
637
|
if (e.name === 'ResourceNotFoundException') {
|
|
640
638
|
this.log.info(chalk`--: creating alias {blue ${name}}...`);
|
|
641
|
-
|
|
639
|
+
await this._lambda.send(new CreateAliasCommand({
|
|
642
640
|
FunctionName: functionName,
|
|
643
641
|
Name: name,
|
|
644
642
|
FunctionVersion: functionVersion,
|
|
645
643
|
}));
|
|
646
644
|
this.log.info(chalk`{green ok:} created alias {blue ${name}} for version {yellow ${functionVersion}}.`);
|
|
647
|
-
return res.AliasArn;
|
|
648
645
|
} else {
|
|
649
646
|
this.log.error(`Unable to verify existence of Lambda alias ${name}`);
|
|
650
647
|
throw e;
|
|
@@ -657,7 +654,9 @@ export default class AWSDeployer extends BaseDeployer {
|
|
|
657
654
|
const { ApiId } = await this.initApiId();
|
|
658
655
|
const functionVersion = cfg.version.replace(/\./g, '_');
|
|
659
656
|
|
|
657
|
+
// get function alias
|
|
660
658
|
let res;
|
|
659
|
+
let aliasArn;
|
|
661
660
|
let incrementalVersion;
|
|
662
661
|
try {
|
|
663
662
|
this.log.info(chalk`--: fetching alias ...`);
|
|
@@ -665,95 +664,71 @@ export default class AWSDeployer extends BaseDeployer {
|
|
|
665
664
|
FunctionName: functionName,
|
|
666
665
|
Name: functionVersion,
|
|
667
666
|
}));
|
|
667
|
+
aliasArn = res.AliasArn;
|
|
668
668
|
incrementalVersion = res.FunctionVersion;
|
|
669
|
-
this.log.info(chalk`{green ok}: ${
|
|
669
|
+
this.log.info(chalk`{green ok}: ${aliasArn}`);
|
|
670
670
|
} catch (e) {
|
|
671
671
|
this.log.error(chalk`{red error}: Unable to create link to function ${functionName}`);
|
|
672
672
|
throw e;
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
+
// find integration
|
|
676
|
+
let integration = await this.findIntegration(ApiId, aliasArn);
|
|
677
|
+
let cleanup = false;
|
|
678
|
+
if (integration) {
|
|
679
|
+
this.log.info(`--: using existing integration "${integration.IntegrationId}" for "${aliasArn}"`);
|
|
680
|
+
} else {
|
|
681
|
+
integration = await this._api.send(new CreateIntegrationCommand({
|
|
682
|
+
ApiId,
|
|
683
|
+
IntegrationMethod: 'POST',
|
|
684
|
+
IntegrationType: 'AWS_PROXY',
|
|
685
|
+
IntegrationUri: aliasArn,
|
|
686
|
+
PayloadFormatVersion: '2.0',
|
|
687
|
+
TimeoutInMillis: Math.min(cfg.timeout, 30000),
|
|
688
|
+
}));
|
|
689
|
+
this.log.info(chalk`{green ok:} created new integration "${integration.IntegrationId}" for "${aliasArn}"`);
|
|
690
|
+
cleanup = true;
|
|
691
|
+
}
|
|
692
|
+
const { IntegrationId } = integration;
|
|
693
|
+
|
|
675
694
|
// get all the routes
|
|
676
695
|
this.log.info(chalk`--: fetching routes ...`);
|
|
677
696
|
const routes = await this.fetchRoutes(ApiId);
|
|
697
|
+
const routeParams = {
|
|
698
|
+
ApiId,
|
|
699
|
+
Target: `integrations/${IntegrationId}`,
|
|
700
|
+
AuthorizerId: undefined,
|
|
701
|
+
AuthorizationType: 'NONE',
|
|
702
|
+
};
|
|
703
|
+
if (this._cfg.attachAuthorizer) {
|
|
704
|
+
this.log.info(chalk`--: fetching authorizers...`);
|
|
705
|
+
const authorizers = await this.fetchAuthorizers(ApiId);
|
|
706
|
+
const authorizer = authorizers.find((info) => info.Name === this._cfg.attachAuthorizer);
|
|
707
|
+
if (!authorizer) {
|
|
708
|
+
throw Error(`Specified authorizer ${this._cfg.attachAuthorizer} does not exist in api ${ApiId}.`);
|
|
709
|
+
}
|
|
710
|
+
routeParams.AuthorizerId = authorizer.AuthorizerId;
|
|
711
|
+
routeParams.AuthorizationType = 'CUSTOM';
|
|
712
|
+
this.log.info(chalk`{green ok:} configuring routes with authorizer {blue ${this._cfg.attachAuthorizer}} {yellow ${authorizer.AuthorizerId}}`);
|
|
713
|
+
}
|
|
678
714
|
|
|
679
715
|
// create routes for each symlink
|
|
680
716
|
const sfx = this.getLinkVersions();
|
|
681
717
|
|
|
682
718
|
for (const suffix of sfx) {
|
|
683
|
-
//
|
|
684
|
-
const aliasArn = await this.createOrUpdateAlias(suffix.replace('.', '_'), functionName, incrementalVersion);
|
|
685
|
-
|
|
686
|
-
// find or create integration
|
|
687
|
-
let integration = await this.findIntegration(ApiId, aliasArn);
|
|
688
|
-
if (integration) {
|
|
689
|
-
this.log.info(`--: using existing integration "${integration.IntegrationId}" for "${aliasArn}"`);
|
|
690
|
-
} else {
|
|
691
|
-
integration = await this._api.send(new CreateIntegrationCommand({
|
|
692
|
-
ApiId,
|
|
693
|
-
IntegrationMethod: 'POST',
|
|
694
|
-
IntegrationType: 'AWS_PROXY',
|
|
695
|
-
IntegrationUri: aliasArn,
|
|
696
|
-
PayloadFormatVersion: '2.0',
|
|
697
|
-
TimeoutInMillis: Math.min(cfg.timeout, 30000),
|
|
698
|
-
}));
|
|
699
|
-
this.log.info(chalk`{green ok:} created new integration "${integration.IntegrationId}" for "${aliasArn}"`);
|
|
700
|
-
}
|
|
701
|
-
const { IntegrationId } = integration;
|
|
702
|
-
|
|
703
|
-
const routeParams = {
|
|
704
|
-
ApiId,
|
|
705
|
-
Target: `integrations/${IntegrationId}`,
|
|
706
|
-
AuthorizerId: undefined,
|
|
707
|
-
AuthorizationType: 'NONE',
|
|
708
|
-
};
|
|
709
|
-
if (this._cfg.attachAuthorizer) {
|
|
710
|
-
this.log.info(chalk`--: fetching authorizers...`);
|
|
711
|
-
const authorizers = await this.fetchAuthorizers(ApiId);
|
|
712
|
-
const authorizer = authorizers.find((info) => info.Name === this._cfg.attachAuthorizer);
|
|
713
|
-
if (!authorizer) {
|
|
714
|
-
throw Error(`Specified authorizer ${this._cfg.attachAuthorizer} does not exist in api ${ApiId}.`);
|
|
715
|
-
}
|
|
716
|
-
routeParams.AuthorizerId = authorizer.AuthorizerId;
|
|
717
|
-
routeParams.AuthorizationType = 'CUSTOM';
|
|
718
|
-
this.log.info(chalk`{green ok:} configuring routes with authorizer {blue ${this._cfg.attachAuthorizer}} {yellow ${authorizer.AuthorizerId}}`);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
// create or update routes
|
|
719
|
+
// check if route already exists
|
|
722
720
|
await this.createOrUpdateRoute(routes, routeParams, `ANY /${cfg.packageName}/${cfg.baseName}/${suffix}`);
|
|
723
721
|
await this.createOrUpdateRoute(routes, routeParams, `ANY /${cfg.packageName}/${cfg.baseName}/${suffix}/{path+}`);
|
|
724
722
|
|
|
725
|
-
|
|
723
|
+
// create or update alias
|
|
724
|
+
await this.createOrUpdateAlias(suffix.replace('.', '_'), functionName, incrementalVersion);
|
|
725
|
+
}
|
|
726
726
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
try {
|
|
730
|
-
// eslint-disable-next-line no-await-in-loop
|
|
731
|
-
await this._lambda.send(new AddPermissionCommand({
|
|
732
|
-
FunctionName: aliasArn,
|
|
733
|
-
Action: 'lambda:InvokeFunction',
|
|
734
|
-
SourceArn: sourceArn,
|
|
735
|
-
Principal: 'apigateway.amazonaws.com',
|
|
736
|
-
StatementId: crypto.createHash('md5').update(aliasArn + sourceArn).digest('hex'),
|
|
737
|
-
}));
|
|
738
|
-
this.log.info(chalk`{green ok:} added invoke permissions for ${sourceArn}`);
|
|
739
|
-
} catch (e) {
|
|
740
|
-
// ignore, most likely the permission already exists
|
|
741
|
-
}
|
|
742
|
-
sourceArn = `arn:aws:execute-api:${this._cfg.region}:${this._accountId}:${ApiId}/*/*/${cfg.packageName}/${cfg.baseName}/${suffix}/{path+}`;
|
|
743
|
-
try {
|
|
744
|
-
// eslint-disable-next-line no-await-in-loop
|
|
745
|
-
await this._lambda.send(new AddPermissionCommand({
|
|
746
|
-
FunctionName: aliasArn,
|
|
747
|
-
Action: 'lambda:InvokeFunction',
|
|
748
|
-
SourceArn: sourceArn,
|
|
749
|
-
Principal: 'apigateway.amazonaws.com',
|
|
750
|
-
StatementId: crypto.createHash('md5').update(aliasArn + sourceArn).digest('hex'),
|
|
751
|
-
}));
|
|
752
|
-
this.log.info(chalk`{green ok:} added invoke permissions for ${sourceArn}`);
|
|
753
|
-
} catch (e) {
|
|
754
|
-
// ignore, most likely the permission already exists
|
|
755
|
-
}
|
|
727
|
+
if (cleanup) {
|
|
728
|
+
await this.cleanUpIntegrations(functionName);
|
|
756
729
|
}
|
|
730
|
+
|
|
731
|
+
await this.updateAuthorizers(ApiId, functionName, aliasArn);
|
|
757
732
|
}
|
|
758
733
|
|
|
759
734
|
async updateAuthorizers(ApiId, functionName, aliasArn) {
|