fix(aws/custom-resources): propagate provider.architecture to custom resource Lambda#159
Conversation
…resource Lambda The internal custom resource Lambda (used for S3 notifications, Cognito user pools, Event Bridge, and the API Gateway CloudWatch role) was always deployed as x86_64 because `Architectures` was never set on the generated CloudFormation resource, regardless of `provider.architecture` in serverless.yml. Mirror the pattern already used for user-defined functions in lib/plugins/aws/package/compile/functions.js: when `provider.architecture` is configured, set `Properties.Architectures` on the custom resource function. Closes oss-serverless#116
|
Thanks, a genuine question: what difference does it make in the end? It's not like cost optimization is a factor here since these have a very low number of invocations. |
There was a problem hiding this comment.
Pull request overview
Propagates the existing, schema-validated provider.architecture setting to the internally generated AWS custom resource Lambda functions so they can be deployed as arm64 (or explicitly x86_64) instead of always defaulting to x86_64.
Changes:
- Set
Properties.Architectureson the generatedAWS::Lambda::Functionfor custom resources whenprovider.architectureis configured. - Add unit tests to verify
Architectures: ['arm64']is emitted when configured and omitted when not configured.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/plugins/aws/custom-resources/index.js |
Applies provider.architecture to compiled custom resource Lambda function Properties.Architectures. |
test/unit/lib/plugins/aws/custom-resources/index.test.js |
Adds coverage for setting/omitting Architectures based on provider.architecture. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Honestly, I wanted to contribute, and I saw the open Issue so I thought it would be a good place for me to dip my toes in. If you don't think this is worth it, feel free to close it! |
|
Go it! Let's merge, I guess this doesn't hurt and some people may appreciate if they have some policies to always use ARM for example. |
Summary
Fixes #116. The internal custom resource Lambda (used for S3 notifications, Cognito user pools, Event Bridge, and the API Gateway CloudWatch role) was always deployed as
x86_64becauseArchitectureswas never set on the generated CloudFormation resource, regardless ofprovider.architectureinserverless.yml.Changes
lib/plugins/aws/custom-resources/index.js: whenprovider.architectureis configured, setProperties.Architectureson the compiled custom resourceAWS::Lambda::Function. Mirrors the pattern already used for user-defined functions inlib/plugins/aws/package/compile/functions.js.provider.architecturevalue is applied.Tests
Two new cases in
test/unit/lib/plugins/aws/custom-resources/index.test.js:Architecturesis set to['arm64']whenprovider.architectureis'arm64'.Architecturesis omitted whenprovider.architectureis unset (preserves current x86_64 default behavior).All 14 tests in the custom-resources suite pass. Full unit suite (SDK v2 and v3), packaging tests (v2 and v3), isolated tests, prettier, and eslint all pass locally.