aws-cloudformation / aws-cloudformation/cloudformation-coverage-roadmap
Add support for ECMAScript modules in inline ZipFile code
- Dominant language
- No language data
- Stars
- 1.1k
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
### Name of the resource
AWS::Lambda::Function
### Resource name
_No response_
### Description
The Node.js Lambda runtime, like Node.js itself, supports either CommonJS or ECMAScript module source code. The two are differentiated mainly by how packages are imported. The former uses the `require` function, where the latter uses the `import` statement. The latter is seen in some circles as more modern. Which module format is used is indicated by the file extension: `index.js` or `index.cjs` for CommonJS, or `index.mjs` for ECAMScript module.
The `AWS::Lambda::Function` CloudFormation resource supports embedded, inline source code via the `Properties: Code: ZipFile`. However, there is currently no way to tell CloudFormation that the embedded source code is an ECMAScript module because the file extension is always `.js`, not `.mjs`.
Add a property to control the file extension of the `index` file in the embedded source.
### Other Details
Example using ECMAScript module syntax:
```yaml
PostConfirmSignupFunction:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: |
import {
AdminAddUserToGroupCommand,
CognitoIdentityProviderClient,
} from '@aws-sdk/client-cognito-identity-provider'
const client = new CognitoIdentityProviderClient({})
const GroupName = 'defaultGroup'
export async function handler(event) {
const UserPoolId = event.userPoolId
const Username = event.userName
const command = new AdminAddUserToGroupCommand({
UserPoolId, Username, GroupName
})
await client.send(command)
return event
}
Handler: index.handler
PackageType: Zip
Role: !GetAtt PostConfirmSignupRole.Arn
Runtime: nodejs18.x
```
Contributor guide
Research direction
Start by examining the AWS::Lambda::Function handling for Properties.Code.ZipFile and how inline source is packaged as index.js. Trace the Node.js Lambda example in the issue and identify the existing tests for inline ZipFile code. Done means a configurable index extension supports .mjs while preserving CommonJS behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript
- Domain
- backend, cloud
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100