@jcoreio/toolchain-aws-lambda 4.3.5 → 4.5.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcoreio/toolchain-aws-lambda",
3
- "version": "4.3.5",
3
+ "version": "4.5.0",
4
4
  "description": "AWS Lambda function build toolchain",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,17 +17,18 @@
17
17
  "@aws-sdk/client-s3": "^3.575.0",
18
18
  "@aws-sdk/client-sts": "^3.575.0",
19
19
  "@jcoreio/cloudformation-tools": "^5.1.1",
20
- "@jcoreio/pack-lambda": "^2.0.0",
20
+ "@jcoreio/pack-lambda": "^3.0.0",
21
21
  "@semantic-release/exec": "^6.0.3",
22
22
  "dedent-js": "^1.0.1",
23
23
  "dotenv": "^16.4.5",
24
24
  "resolve-bin": "^1.0.0",
25
25
  "zod": "^3.21.4",
26
- "@jcoreio/toolchain": "4.3.5"
26
+ "@jcoreio/toolchain": "4.5.0"
27
27
  },
28
28
  "toolchainManaged": {
29
29
  "devDependencies": {
30
- "@types/aws-lambda": "^8.10.137"
30
+ "@types/aws-lambda": "^8.10.137",
31
+ "@jcoreio/cloudformation-template-types": "^1.1.0"
31
32
  }
32
33
  }
33
34
  }
@@ -14,23 +14,27 @@ module.exports = [
14
14
  }
15
15
  `,
16
16
  [`scripts/cloudFormationTemplate.${isTS ? 'ts' : 'js'}`]: dedent`
17
+ import type {
18
+ CloudFormationTemplate,
19
+ CloudFormationTemplateParameterValues,
20
+ } from '@jcoreio/cloudformation-template-types'
21
+
17
22
  // export const StackName = 'StackName'
18
23
 
19
24
  export const Template = {
20
25
  AWSTemplateFormatVersion: '2010-09-09',
21
26
  // Description: 'Template Descrption',
22
- Transform: 'AWS::Serverless-2016-10-31',
23
27
  Parameters: {
24
28
 
25
29
  },
26
30
  Resources: {
27
31
  LambdaFunction: {
28
- Type: 'AWS::Serverless::Function',
32
+ Type: 'AWS::Lambda::Function',
29
33
  Properties: {
30
34
  MemorySize: 128,
31
35
  Timeout: 60,
32
- // CodeUri: {
33
- // Bucket: 'BucketName',
36
+ // Code: {
37
+ // S3Bucket: 'BucketName',
34
38
  // },
35
39
  },
36
40
  },
@@ -38,11 +42,11 @@ module.exports = [
38
42
  Outputs: {
39
43
  LambdaFunction: { Value: { Ref: 'LambdaFunction' } },
40
44
  },
41
- }
45
+ } satisfies CloudFormationTemplate
42
46
 
43
47
  export const Parameters = {
44
48
 
45
- }
49
+ } satisfies CloudFormationTemplateParameterValues<typeof Template>
46
50
 
47
51
  export const Capabilities = ['CAPABILITY_IAM']
48
52
 
@@ -114,29 +114,69 @@ module.exports = async function deploy() {
114
114
  Properties.Handler = packageJson.main.replace(/\.[^.]+$/, '.handler')
115
115
  }
116
116
 
117
- if (!Properties.CodeUri) Properties.CodeUri = {}
118
- const { CodeUri } = Properties
119
-
120
- if (!CodeUri.Bucket) {
117
+ const isServerless = lambdaResource.Type === 'AWS::Serverless::Function'
118
+
119
+ // Adapt between janky difference between AWS::Serverless::Function and AWS::Lambda::Function
120
+ const adapter = isServerless
121
+ ? {
122
+ get Code() {
123
+ const { CodeUri } = lambdaResource
124
+ return CodeUri
125
+ ? {
126
+ get S3Bucket() {
127
+ return CodeUri.Bucket
128
+ },
129
+ set S3Bucket(value) {
130
+ CodeUri.Bucket = value
131
+ },
132
+ get S3Key() {
133
+ return CodeUri.Key
134
+ },
135
+ set S3Key(value) {
136
+ CodeUri.Key = value
137
+ },
138
+ }
139
+ : undefined
140
+ },
141
+ set Code(value) {
142
+ lambdaResource.CodeUri = {
143
+ Bucket: value.S3Bucket,
144
+ Key: value.S3Key,
145
+ }
146
+ },
147
+ }
148
+ : lambdaResource.Properties
149
+
150
+ if (!adapter.Code) adapter.Code = {}
151
+ const { Code } = Properties
152
+
153
+ if (!Code.S3Bucket) {
121
154
  const sts = new STSClient()
122
155
  const { Account } = await sts.send(new GetCallerIdentityCommand({}))
123
156
  // eslint-disable-next-line no-console
124
- console.error(`Defaulting Lambda CodeUri.Bucket to AWS Account: ${Account}`)
125
- CodeUri.Bucket = Account
157
+ console.error(
158
+ `Defaulting Lambda ${
159
+ isServerless ? 'CodeUri.Bucket' : 'Code.S3Bucket'
160
+ } to AWS Account: ${Account}`
161
+ )
162
+ Code.S3Bucket = Account
126
163
  }
127
164
 
128
- let Bucket = CodeUri.Bucket
129
- if (CodeUri.Bucket instanceof Object) {
130
- if (CodeUri.Bucket.Ref) {
165
+ let Bucket = Code.S3Bucket
166
+ if (Code.S3Bucket instanceof Object) {
167
+ if (Code.S3Bucket.Ref) {
131
168
  Bucket =
132
- Parameters[CodeUri.Bucket.Ref] ||
133
- (Template.Parameters[CodeUri.Bucket.Ref] || {}).Default
169
+ Parameters[Code.S3Bucket.Ref] ||
170
+ (Template.Parameters[Code.S3Bucket.Ref] || {}).Default
134
171
  }
135
172
  throw new Error(
136
- `Lambda CodeUri.Bucket format not supported: ${inspect(Bucket)}`
173
+ `Lambda ${
174
+ isServerless ? 'CodeUri.Bucket' : 'Code.S3Bucket'
175
+ } format not supported: ${inspect(Bucket)}`
137
176
  )
138
177
  }
139
- let Key = CodeUri.Key
178
+
179
+ let Key = Code.S3Key
140
180
 
141
181
  const s3 = new S3Client()
142
182
  try {
@@ -154,8 +194,9 @@ module.exports = async function deploy() {
154
194
  packageDir: path.resolve(projectDir, 'dist'),
155
195
  Bucket,
156
196
  Key,
197
+ useHash: true,
157
198
  }))
158
- CodeUri.Key = Key
199
+ Code.S3Key = Key
159
200
 
160
201
  if (!Properties.Runtime) {
161
202
  Properties.Runtime = `nodejs20.x`