@jcoreio/toolchain-aws-lambda 4.3.4 → 4.4.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 +3 -3
- package/scripts/deploy.cjs +55 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcoreio/toolchain-aws-lambda",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "AWS Lambda function build toolchain",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,13 +17,13 @@
|
|
|
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": "^
|
|
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.
|
|
26
|
+
"@jcoreio/toolchain": "4.4.0"
|
|
27
27
|
},
|
|
28
28
|
"toolchainManaged": {
|
|
29
29
|
"devDependencies": {
|
package/scripts/deploy.cjs
CHANGED
|
@@ -114,29 +114,69 @@ module.exports = async function deploy() {
|
|
|
114
114
|
Properties.Handler = packageJson.main.replace(/\.[^.]+$/, '.handler')
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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(
|
|
125
|
-
|
|
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 =
|
|
129
|
-
if (
|
|
130
|
-
if (
|
|
165
|
+
let Bucket = Code.S3Bucket
|
|
166
|
+
if (Code.S3Bucket instanceof Object) {
|
|
167
|
+
if (Code.S3Bucket.Ref) {
|
|
131
168
|
Bucket =
|
|
132
|
-
Parameters[
|
|
133
|
-
(Template.Parameters[
|
|
169
|
+
Parameters[Code.S3Bucket.Ref] ||
|
|
170
|
+
(Template.Parameters[Code.S3Bucket.Ref] || {}).Default
|
|
134
171
|
}
|
|
135
172
|
throw new Error(
|
|
136
|
-
`Lambda
|
|
173
|
+
`Lambda ${
|
|
174
|
+
isServerless ? 'CodeUri.Bucket' : 'Code.S3Bucket'
|
|
175
|
+
} format not supported: ${inspect(Bucket)}`
|
|
137
176
|
)
|
|
138
177
|
}
|
|
139
|
-
|
|
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
|
-
|
|
199
|
+
Code.S3Key = Key
|
|
159
200
|
|
|
160
201
|
if (!Properties.Runtime) {
|
|
161
202
|
Properties.Runtime = `nodejs20.x`
|