Skip to content

Commit

Permalink
Phase out aws-sam-webpack-plugin
Browse files Browse the repository at this point in the history
Use `sam build` with esbuild instead of webpacker
  • Loading branch information
Fried Hoeben committed Mar 6, 2024
1 parent b278534 commit 3471f68
Show file tree
Hide file tree
Showing 16 changed files with 487 additions and 1,461 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ Next to that it provides helpers that can be used by the actual integrations:
* [js_4me_installation_handler](#js_4me_installation_handler)
* [js_4me_deploy_helper](#js_4me_deploy_helper)

[Webpack](https://webpack.js.org) is used to include only the helpers that are actually used in the lambdas deployed to AWS.
[esbuild](https://esbuild.github.io) is used to include only the helpers that are actually used in the lambdas deployed to AWS.

#### bootstrap.js

Expand Down
9 changes: 9 additions & 0 deletions lansweeper/aws/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ Resources:
DockerTag: nodejs18.x-v1
DockerContext: ./integration-lambda
Dockerfile: Dockerfile
BuildMethod: esbuild
BuildProperties:
Format: cjs
Minify: true
Target: "es2020"
Sourcemap: false
SourcesContent: false
EntryPoints:
- lansweeper/aws/integration-lambda/app.js

Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
Expand Down
45 changes: 0 additions & 45 deletions lansweeper/aws/webpack.config.js

This file was deleted.

10 changes: 9 additions & 1 deletion library/aws/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ Resources:
DockerTag: nodejs18.x-v1
DockerContext: ./secrets-lambda
Dockerfile: Dockerfile

BuildMethod: esbuild
BuildProperties:
Format: cjs
Minify: true
Target: "es2020"
Sourcemap: false
SourcesContent: false
EntryPoints:
- library/aws/secrets-lambda/app.js
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
Expand Down
45 changes: 0 additions & 45 deletions library/aws/webpack.config.js

This file was deleted.

14 changes: 9 additions & 5 deletions library/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ class Bootstrap {
`BootstrapSecretAccountParameter=${account}`,
`BootstrapSecretEnabledReferencesParameter=${enabledOfferings}`,
];
return await this.js4meDeployHelper.deployLambda(clientConfig,
profile,
samPath,
stackName,
parameterOverrides);
const stackOutputs = await this.js4meDeployHelper.deployLambda(clientConfig,
profile,
samPath,
stackName,
parameterOverrides);
if (!stackOutputs) {
this.js4meDeployHelper.deploymentFailed('Unable to build/deploy secrets lambda');
}
return stackOutputs;
}

async getAccessToken(domain, account, clientID, token) {
Expand Down
13 changes: 7 additions & 6 deletions library/helpers/aws_deploy_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ class AwsDeployHelper {
}

async deploy(samPath, stackName, parameterOverrides) {
const buildExitCode = await this.run('node',
const buildExitCode = await this.run('sam',
[
'../../node_modules/webpack-cli/bin/cli.js',
],
{ cwd: samPath });
'build',
'--manifest', './package.json',
'--template', `${samPath}/template.yaml`,
]);
if (buildExitCode !== 0) {
console.error('Unable to build deployment package');
return buildExitCode;
Expand All @@ -37,7 +38,7 @@ class AwsDeployHelper {
'--no-confirm-changeset',
'--parameter-overrides', `${parameterOverrides.join(' ')}`,
],
{ cwd: samPath, shell: true }
{ cwd: './.aws-sam/build', shell: true }
);
if (deployExitCode !== 0) {
console.error('Deploy failed');
Expand Down Expand Up @@ -74,4 +75,4 @@ class AwsDeployHelper {
}
}

module.exports = AwsDeployHelper;
module.exports = AwsDeployHelper;
3 changes: 3 additions & 0 deletions library/helpers/js_4me_deploy_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class Js4meDeployHelper {

async deployIntegrationLambda(clientConfig, profile, samPath, stackName, parameterOverrides) {
const stackOutputs = await this.deployLambda(clientConfig, profile, samPath, stackName, parameterOverrides)
if (!stackOutputs) {
this.deploymentFailed('Unable to build/deploy integration lambda');
}

const lambdaUrl = stackOutputs['IntegrationApi'];
if (!lambdaUrl) {
Expand Down
9 changes: 9 additions & 0 deletions note-dispatcher/aws/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ Resources:
DockerTag: nodejs18.x-v1
DockerContext: ./integration-lambda
Dockerfile: Dockerfile
BuildMethod: esbuild
BuildProperties:
Format: cjs
Minify: true
Target: "es2020"
Sourcemap: false
SourcesContent: false
EntryPoints:
- node-dispatcher/aws/integration-lambda/app.js

Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
Expand Down
45 changes: 0 additions & 45 deletions note-dispatcher/aws/webpack.config.js

This file was deleted.

Loading

0 comments on commit 3471f68

Please sign in to comment.