@ez4/aws-function 0.36.0 → 0.37.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/dist/function/client.d.ts +3 -3
- package/dist/function/helpers/variables.d.ts +3 -3
- package/dist/function/types.d.ts +6 -1
- package/dist/main.cjs +115 -114
- package/dist/main.mjs +120 -119
- package/dist/types/variables.d.ts +1 -1
- package/package.json +7 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Arn, ResourceTags } from '@ez4/aws-common';
|
|
2
|
-
import type {
|
|
2
|
+
import type { FunctionVariables } from '../types/variables';
|
|
3
3
|
export type CreateRequest = {
|
|
4
4
|
roleArn: Arn;
|
|
5
5
|
sourceFile: string;
|
|
@@ -7,7 +7,7 @@ export type CreateRequest = {
|
|
|
7
7
|
handlerName: string;
|
|
8
8
|
description?: string;
|
|
9
9
|
logGroup?: string;
|
|
10
|
-
variables?:
|
|
10
|
+
variables?: FunctionVariables;
|
|
11
11
|
timeout?: number;
|
|
12
12
|
memory?: number;
|
|
13
13
|
publish?: boolean;
|
|
@@ -23,7 +23,7 @@ export type UpdateConfigurationRequest = {
|
|
|
23
23
|
handlerName?: string;
|
|
24
24
|
description?: string;
|
|
25
25
|
logGroup?: string;
|
|
26
|
-
variables?:
|
|
26
|
+
variables?: FunctionVariables;
|
|
27
27
|
timeout?: number;
|
|
28
28
|
memory?: number;
|
|
29
29
|
debug?: boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const assertVariables: (variables:
|
|
3
|
-
export declare const protectVariables: (variables:
|
|
1
|
+
import type { FunctionVariables } from '../../types/variables';
|
|
2
|
+
export declare const assertVariables: (variables: FunctionVariables) => void;
|
|
3
|
+
export declare const protectVariables: (variables: FunctionVariables) => FunctionVariables;
|
package/dist/function/types.d.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import type { EntryState, StepContext } from '@ez4/stateful';
|
|
2
|
+
import type { LinkedVariables } from '@ez4/project/library';
|
|
2
3
|
import type { Arn } from '@ez4/aws-common';
|
|
4
|
+
import type { FunctionVariables } from '../types/variables';
|
|
3
5
|
import type { CreateRequest, ImportOrCreateResponse } from './client';
|
|
4
6
|
export declare const FunctionServiceName = "AWS:Lambda/Function";
|
|
5
7
|
export declare const FunctionServiceType = "aws:lambda.function";
|
|
6
8
|
export type GetFunctionFiles = () => [string, string[]];
|
|
9
|
+
export type GetFunctionVariables = () => Promise<LinkedVariables> | LinkedVariables;
|
|
7
10
|
export type GetFunctionBundle = (context: StepContext) => Promise<string> | string;
|
|
8
11
|
export type GetFunctionHash = () => Promise<string | undefined> | string | undefined;
|
|
9
|
-
export type FunctionParameters = Omit<CreateRequest, 'roleArn' | 'publish'> & {
|
|
12
|
+
export type FunctionParameters = Omit<CreateRequest, 'roleArn' | 'publish' | 'variables'> & {
|
|
10
13
|
getFunctionFiles: GetFunctionFiles;
|
|
14
|
+
getFunctionVariables: GetFunctionVariables;
|
|
11
15
|
getFunctionBundle: GetFunctionBundle;
|
|
12
16
|
getFunctionHash: GetFunctionHash;
|
|
13
17
|
};
|
|
14
18
|
export type FunctionResult = ImportOrCreateResponse & {
|
|
19
|
+
variables: FunctionVariables;
|
|
15
20
|
valuesHash?: string;
|
|
16
21
|
sourceHash: string;
|
|
17
22
|
bundleHash: string;
|
package/dist/main.cjs
CHANGED
|
@@ -1,154 +1,155 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof t=="object"||typeof t=="function")for(let i of
|
|
3
|
-
I(e,i,{get:()=>t[i],enumerable:!(o=
|
|
4
|
-
enumerable:!0}):n,e)),
|
|
5
|
-
MappingServiceName:()=>
|
|
6
|
-
buildFunctionArn:()=>
|
|
7
|
-
getFunctionArn:()=>
|
|
8
|
-
isFunctionState:()=>k,isMappingState:()=>
|
|
9
|
-
tryGetFunctionState:()=>
|
|
10
|
-
Be=require("@ez4/project/library");var ue=require("@ez4/aws-common");var
|
|
11
|
-
$=require("@ez4/aws-identity");var s=require("@aws-sdk/client-lambda"),c=require("@ez4/aws-common");var _=require("@ez4/aws-common"),X=require("@ez4/utils");var p="AWS:Lambda/Function",
|
|
1
|
+
"use strict";var Qe=Object.create;var I=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty;var r=(e,t)=>I(e,"name",{value:t,configurable:!0});var Ye=(e,t)=>{for(var n in t)I(e,n,{get:t[n],enumerable:!0})},K=(e,t,n,o)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let i of Ke(t))!Xe.call(e,i)&&i!==n&&
|
|
3
|
+
I(e,i,{get:()=>t[i],enumerable:!(o=Je(t,i))||o.enumerable});return e};var et=(e,t,n)=>(n=e!=null?Qe(_e(e)):{},K(t||!e||!e.__esModule?I(n,"default",{value:e,
|
|
4
|
+
enumerable:!0}):n,e)),tt=e=>K(I({},"__esModule",{value:!0}),e);var Lt={};Ye(Lt,{FunctionServiceName:()=>p,FunctionServiceType:()=>f,MappingService:()=>j,
|
|
5
|
+
MappingServiceName:()=>S,MappingServiceType:()=>v,PermissionServiceName:()=>C,PermissionServiceType:()=>x,
|
|
6
|
+
buildFunctionArn:()=>Vt,createFunction:()=>Et,createMapping:()=>Nt,createPermission:()=>It,
|
|
7
|
+
getFunctionArn:()=>dt,getFunctionName:()=>A,getFunctionState:()=>gt,getPermission:()=>Mt,
|
|
8
|
+
isFunctionState:()=>k,isMappingState:()=>Ht,registerTriggers:()=>At,tryGetFunctionArn:()=>ge,
|
|
9
|
+
tryGetFunctionState:()=>lt});module.exports=tt(Lt);var De=require("@ez4/aws-common"),Ge=require("@ez4/aws-identity"),ze=require("@ez4/aws-logs"),
|
|
10
|
+
Be=require("@ez4/project/library");var ue=require("@ez4/aws-common");var y=require("@ez4/aws-common"),b=require("@ez4/utils"),W=require("@ez4/aws-logs"),
|
|
11
|
+
$=require("@ez4/aws-identity");var s=require("@aws-sdk/client-lambda"),c=require("@ez4/aws-common");var _=require("@ez4/aws-common"),X=require("@ez4/utils");var p="AWS:Lambda/Function",f="aws:lambda.function";var nt=/[a-z][\w]+/i,rt=r(e=>nt.test(e),"isValidName"),G=r(e=>{for(let t in e)if(!rt(
|
|
12
12
|
t))throw new _.InvalidParameterError(p,`${t} is an invalid variable name .`)},"a\
|
|
13
|
-
ssertVariables"),
|
|
14
|
-
"protectVariables");var Y=
|
|
15
|
-
t,o),n.toBufferPromise()},"getZipBuffer");var
|
|
16
|
-
ne=r(async(e,t)=>{c.Logger.logImport(p,e);try{let n=await
|
|
13
|
+
ssertVariables"),M=r(e=>{let t={};for(let n in e)t[n]=(0,X.hashData)(e[n]);return t},
|
|
14
|
+
"protectVariables");var Y=et(require("adm-zip"),1),ee=require("node:fs/promises");var te=r(async(e,t)=>{let n=new Y.default,o=await(0,ee.readFile)(e);return n.addFile(
|
|
15
|
+
t,o),n.toBufferPromise()},"getZipBuffer");var w=new s.LambdaClient({}),V={minDelay:15,maxWaitTime:1800,maxDelay:60,client:w},
|
|
16
|
+
ne=r(async(e,t)=>{c.Logger.logImport(p,e);try{let n=await w.send(new s.GetFunctionCommand(
|
|
17
17
|
{FunctionName:e,Qualifier:t})),o=n.Configuration.Version,i=n.Configuration.FunctionArn;
|
|
18
18
|
return{functionVersion:o,functionArn:i}}catch(n){if(!(n instanceof s.ResourceNotFoundException))
|
|
19
19
|
throw n;return}},"importFunction"),re=r(async e=>{let{functionName:t,variables:n}=e;
|
|
20
|
-
c.Logger.logCreate(p,t),n&&
|
|
21
|
-
a=await(0,c.waitCreation)(()=>
|
|
20
|
+
c.Logger.logCreate(p,t),n&&G(n);let o=pe(e.handlerName),i=await ae(e.sourceFile),
|
|
21
|
+
a=await(0,c.waitCreation)(()=>w.send(new s.CreateFunctionCommand({FunctionName:e.
|
|
22
22
|
functionName,Description:e.description,MemorySize:e.memory,Timeout:e.timeout,Role:e.
|
|
23
23
|
roleArn,Handler:o,Runtime:"nodejs22.x",PackageType:"Zip",LoggingConfig:{LogGroup:e.
|
|
24
24
|
logGroup,ApplicationLogLevel:e.debug?s.ApplicationLogLevel.Debug:s.ApplicationLogLevel.
|
|
25
25
|
Warn,SystemLogLevel:s.SystemLogLevel.Warn,LogFormat:s.LogFormat.Json},Code:{ZipFile:i},
|
|
26
26
|
Environment:{Variables:n},Tags:{...e.tags,ManagedBy:"EZ4"}})));c.Logger.logWait(
|
|
27
|
-
p,t),await(0,s.waitUntilFunctionActive)(
|
|
27
|
+
p,t),await(0,s.waitUntilFunctionActive)(V,{FunctionName:t});let u=a.FunctionArn;
|
|
28
28
|
return e.publish?{functionVersion:await ie(t),functionArn:u}:{functionArn:u}},"c\
|
|
29
|
-
reateFunction"),
|
|
30
|
-
t.sourceFile),o=await
|
|
31
|
-
publish,ZipFile:n}));c.Logger.logWait(p,e),await(0,s.waitUntilFunctionUpdated)(
|
|
29
|
+
reateFunction"),z=r(async(e,t)=>{c.Logger.logUpdate(p,`${e} source code`);let n=await ae(
|
|
30
|
+
t.sourceFile),o=await w.send(new s.UpdateFunctionCodeCommand({FunctionName:e,Publish:t.
|
|
31
|
+
publish,ZipFile:n}));c.Logger.logWait(p,e),await(0,s.waitUntilFunctionUpdated)(V,
|
|
32
32
|
{FunctionName:e});let i=o.FunctionArn;return t.publish?{functionVersion:await ie(
|
|
33
|
-
e),functionArn:i}:{functionArn:i}},"updateSourceCode"),
|
|
34
|
-
variables:o}=t;c.Logger.logUpdate(p,`${e} configuration`),o&&
|
|
33
|
+
e),functionArn:i}:{functionArn:i}},"updateSourceCode"),B=r(async(e,t)=>{let{handlerName:n,
|
|
34
|
+
variables:o}=t;c.Logger.logUpdate(p,`${e} configuration`),o&&G(o),await w.send(new s.UpdateFunctionConfigurationCommand(
|
|
35
35
|
{FunctionName:e,Description:t.description,MemorySize:t.memory,Timeout:t.timeout,
|
|
36
36
|
Role:t.roleArn,Runtime:"nodejs22.x",...n&&{Handler:pe(n)},LoggingConfig:{LogGroup:t.
|
|
37
37
|
logGroup,ApplicationLogLevel:t.debug?s.ApplicationLogLevel.Debug:s.ApplicationLogLevel.
|
|
38
38
|
Warn,SystemLogLevel:s.SystemLogLevel.Warn,LogFormat:s.LogFormat.Json},Environment:{
|
|
39
|
-
Variables:o}})),c.Logger.logWait(p,e),await(0,s.waitUntilFunctionUpdated)(
|
|
39
|
+
Variables:o}})),c.Logger.logWait(p,e),await(0,s.waitUntilFunctionUpdated)(V,{FunctionName:e})},
|
|
40
40
|
"updateConfiguration"),oe=r(async e=>{c.Logger.logDelete(p,e),await(0,c.waitDeletion)(
|
|
41
|
-
async()=>{try{await
|
|
41
|
+
async()=>{try{await w.send(new s.DeleteFunctionCommand({FunctionName:e}))}catch(t){
|
|
42
42
|
if(!(t instanceof s.ResourceNotFoundException))throw t}})},"deleteFunction"),ie=r(
|
|
43
|
-
async e=>{c.Logger.logPublish(p,e);let t=await
|
|
43
|
+
async e=>{c.Logger.logPublish(p,e);let t=await w.send(new s.PublishVersionCommand(
|
|
44
44
|
{FunctionName:e}));c.Logger.logWait(p,e);let n=t.Version;return await(0,s.waitUntilPublishedVersionActive)(
|
|
45
|
-
|
|
46
|
-
e)?.resourceName??e;c.Logger.logTag(p,n),await
|
|
45
|
+
V,{FunctionName:e,Qualifier:n}),n},"publishFunction"),O=r(async(e,t)=>{let n=(0,c.tryParseArn)(
|
|
46
|
+
e)?.resourceName??e;c.Logger.logTag(p,n),await w.send(new s.TagResourceCommand({
|
|
47
47
|
Resource:e,Tags:{...t,ManagedBy:"EZ4"}}))},"tagFunction"),se=r(async(e,t)=>{let n=(0,c.tryParseArn)(
|
|
48
|
-
e)?.resourceName??e;c.Logger.logUntag(p,n),await
|
|
48
|
+
e)?.resourceName??e;c.Logger.logUntag(p,n),await w.send(new s.UntagResourceCommand(
|
|
49
49
|
{Resource:e,TagKeys:t}))},"untagFunction"),ae=r(e=>te(e,"main.mjs"),"getSourceZi\
|
|
50
|
-
pFile"),pe=r(e=>`main.${e}`,"getSourceHandlerName");var ce=r(()=>({equals:
|
|
51
|
-
getFunctionHandler"),
|
|
52
|
-
"equalsResource"),
|
|
53
|
-
{...n,connections:e.connections,dependencies:e.dependencies,variables:n.
|
|
54
|
-
|
|
55
|
-
getFunctionHash()},{...o,connections:t.connections,dependencies:t.dependencies,
|
|
56
|
-
result?.sourceHash
|
|
57
|
-
functionName}},"previewResource"),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
p,n,t),[u,g,l]=await Promise.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
u||a!==g||o.force){
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
t
|
|
87
|
-
t,n);if(
|
|
88
|
-
|
|
50
|
+
pFile"),pe=r(e=>`main.${e}`,"getSourceHandlerName");var ce=r(()=>({equals:ot,create:me,replace:st,preview:it,update:at,delete:pt}),"\
|
|
51
|
+
getFunctionHandler"),ot=r((e,t)=>!!e.result&&e.result.functionArn===t.result?.functionArn,
|
|
52
|
+
"equalsResource"),it=r(async(e,t)=>{let n=e.parameters,o=t.parameters,i=(0,b.deepCompare)(
|
|
53
|
+
{...n,connections:e.connections,dependencies:e.dependencies,variables:M(await n.
|
|
54
|
+
getFunctionVariables()),sourceHash:await(0,y.getBundleHash)(...n.getFunctionFiles()),
|
|
55
|
+
valuesHash:n.getFunctionHash()},{...o,connections:t.connections,dependencies:t.dependencies,
|
|
56
|
+
variables:t.result?.variables,sourceHash:t.result?.sourceHash,valuesHash:t.result?.
|
|
57
|
+
valuesHash});if(i.counts)return{...i,name:n.functionName}},"previewResource"),st=r(
|
|
58
|
+
async(e,t,n)=>{if(t.result)throw new y.ReplaceResourceError(p,e.entryId,t.entryId);
|
|
59
|
+
return me(e,n)},"replaceResource"),me=r(async(e,t)=>{let{functionName:n,...o}=e.
|
|
60
|
+
parameters,i=(0,W.getLogGroupName)(p,n,t),a=(0,$.getRoleArn)(p,n,t),[u,g,l,F]=await Promise.
|
|
61
|
+
all([(0,y.getBundleHash)(...o.getFunctionFiles()),o.getFunctionBundle(t),o.getFunctionHash(),
|
|
62
|
+
o.getFunctionVariables()]),d=await ne(n),R=await(0,b.hashFile)(g);if(d)return await B(
|
|
63
|
+
n,{...o,variables:F,logGroup:i,roleArn:a}),await z(n,{publish:!1,sourceFile:g}),
|
|
64
|
+
await O(d.functionArn,{...o.tags}),{functionArn:d.functionArn,functionVersion:d.
|
|
65
|
+
functionVersion,variables:M(F),valuesHash:l,sourceHash:u,bundleHash:R,logGroup:i,
|
|
66
|
+
roleArn:a};let H=await re({...o,publish:!0,functionName:n,sourceFile:g,variables:F,
|
|
67
|
+
logGroup:i,roleArn:a});return{functionArn:H.functionArn,functionVersion:H.functionVersion,
|
|
68
|
+
variables:M(F),valuesHash:l,sourceHash:u,bundleHash:R,logGroup:i,roleArn:a}},"cr\
|
|
69
|
+
eateResource"),at=r(async(e,t,n)=>{let{parameters:o,result:i}=e;if(!i)return;let a=o.
|
|
70
|
+
functionName,u=await o.getFunctionVariables(),g=t.result?.variables??u,l=(0,$.getRoleArn)(
|
|
71
|
+
p,a,n),F=t.result?.roleArn??l,d=(0,W.getLogGroupName)(p,a,n),R=t.result?.logGroup??
|
|
72
|
+
d,H={...o,variables:u,roleArn:l,logGroup:d},Ze={...t.parameters,variables:g,roleArn:F,
|
|
73
|
+
logGroup:R};await ct(a,H,Ze),await mt(i.functionArn,o,t.parameters);let je=await ut(
|
|
74
|
+
a,o,t.result,n);return{...i,...je,variables:M(u),logGroup:d,roleArn:l}},"updateR\
|
|
75
|
+
esource"),pt=r(async e=>{let{result:t,parameters:n}=e;t&&await oe(n.functionName)},
|
|
76
|
+
"deleteResource"),ct=r(async(e,t,n)=>{!(0,b.deepEqual)(t,n,{exclude:{sourceFile:!0,
|
|
77
|
+
functionName:!0,tags:!0}})&&await B(e,t)},"checkConfigurationUpdates"),mt=r(async(e,t,n)=>{
|
|
78
|
+
await(0,y.applyTagUpdates)(t.tags,n.tags,o=>O(e,o),o=>se(e,o))},"checkTagUpdates"),
|
|
79
|
+
ut=r(async(e,t,n,o)=>{let[i,a]=await Promise.all([(0,y.getBundleHash)(...t.getFunctionFiles()),
|
|
80
|
+
t.getFunctionHash()]),u=n?.sourceHash,g=n?.valuesHash;if(i!==u||a!==g||o.force){
|
|
81
|
+
let l=await t.getFunctionBundle(o),F=await(0,b.hashFile)(l),d=n?.bundleHash;if(F===
|
|
82
|
+
d)return y.Logger.logSkip(p,`${e} source code`),{valuesHash:a,sourceHash:i};let{
|
|
83
|
+
functionVersion:R}=await z(e,{publish:!n?.functionVersion,sourceFile:l});return{
|
|
84
|
+
valuesHash:a,sourceHash:i,bundleHash:F,...R&&{functionVersion:R}}}},"checkSource\
|
|
85
|
+
CodeUpdates");var le=r(()=>{(0,ue.tryRegisterProvider)(f,ce())},"registerFunctionProvider");var xe=require("@ez4/aws-common");var Se=require("@ez4/aws-common");var q=require("@ez4/aws-common");var L=class extends Error{static{r(this,"FunctionNotFoundError")}constructor(t){
|
|
86
|
+
super(`Function ${t} wasn't found.`)}};var k=r(e=>e.type===f,"isFunctionState"),lt=r((e,t,n)=>{try{let o=e.getServiceState(
|
|
87
|
+
t,n);if(k(o))return o}catch{}},"tryGetFunctionState"),gt=r((e,t,n)=>{let o=e.getServiceState(
|
|
88
|
+
t,n);if(!k(o))throw new L(t);return o},"getFunctionState"),A=r((e,t,n)=>{let o=n.
|
|
89
|
+
getDependencies(f).at(0)?.parameters;if(!o?.functionName)throw new q.IncompleteResourceError(
|
|
89
90
|
e,t,"functionName");return o.functionName},"getFunctionName"),ge=r(e=>e.getDependencies(
|
|
90
|
-
|
|
91
|
-
throw new q.IncompleteResourceError(e,t,"functionArn");return o},"getFunctionArn");var
|
|
92
|
-
let t=e.statementId??`ID${Date.now()}`;return await de.send(new
|
|
91
|
+
f)[0]?.result?.functionArn,"tryGetFunctionArn"),dt=r((e,t,n)=>{let o=ge(n);if(!o)
|
|
92
|
+
throw new q.IncompleteResourceError(e,t,"functionArn");return o},"getFunctionArn");var P=require("@aws-sdk/client-lambda"),Z=require("@ez4/aws-common");var C="AWS:Lambda/Permission",x="aws:lambda.permission";var de=new P.LambdaClient({}),fe=r(async e=>{Z.Logger.logCreate(C,e.functionName);
|
|
93
|
+
let t=e.statementId??`ID${Date.now()}`;return await de.send(new P.AddPermissionCommand(
|
|
93
94
|
{StatementId:t,FunctionName:e.functionName,SourceArn:e.sourceArn,Principal:e.principal,
|
|
94
95
|
Action:e.action})),{statementId:t}},"createPermission"),ye=r(async(e,t)=>{Z.Logger.
|
|
95
|
-
logDelete(C,e);try{return await de.send(new
|
|
96
|
-
StatementId:t})),!0}catch(n){if(!(n instanceof
|
|
97
|
-
return!1}},"deletePermission");var Fe=r(()=>({equals:
|
|
98
|
-
getPermissionHandler"),
|
|
99
|
-
functionName,"equalsResource"),
|
|
96
|
+
logDelete(C,e);try{return await de.send(new P.RemovePermissionCommand({FunctionName:e,
|
|
97
|
+
StatementId:t})),!0}catch(n){if(!(n instanceof P.ResourceNotFoundException))throw n;
|
|
98
|
+
return!1}},"deletePermission");var Fe=r(()=>({equals:ft,create:we,replace:St,preview:yt,update:Ft,delete:wt}),"\
|
|
99
|
+
getPermissionHandler"),ft=r((e,t)=>!!e.result&&e.result.functionName===t.result?.
|
|
100
|
+
functionName,"equalsResource"),yt=r((e,t)=>{},"previewResource"),St=r(async(e,t,n)=>{
|
|
100
101
|
if(t.result)throw new Se.ReplaceResourceError(C,e.entryId,t.entryId);return we(e,
|
|
101
|
-
n)},"replaceResource"),we=r(async(e,t)=>{let n=e.parameters,o=
|
|
102
|
+
n)},"replaceResource"),we=r(async(e,t)=>{let n=e.parameters,o=A(C,"permission",t),
|
|
102
103
|
i=await n.getPermission(t);return{statementId:(await fe({action:"lambda:InvokeFu\
|
|
103
104
|
nction",sourceArn:i.sourceArn,principal:i.principal,functionName:o})).statementId,
|
|
104
|
-
functionName:o}},"createResource"),
|
|
105
|
-
let t=e.result;t&&await ye(t.functionName,t.statementId)},"deleteResource");var Pe=r(()=>{(0,xe.tryRegisterProvider)(
|
|
106
|
-
Queue="sqs",n))(j||{});var
|
|
105
|
+
functionName:o}},"createResource"),Ft=r(async()=>{},"updateResource"),wt=r(async e=>{
|
|
106
|
+
let t=e.result;t&&await ye(t.functionName,t.statementId)},"deleteResource");var Pe=r(()=>{(0,xe.tryRegisterProvider)(x,Fe())},"registerPermissionProvider");var Ne=require("@ez4/aws-common");var Ee=require("@ez4/aws-common"),T=require("@ez4/utils");var m=require("@aws-sdk/client-lambda"),h=require("@ez4/aws-common"),Q=require("@ez4/utils");var S="AWS:Lambda/Mapping",v="aws:lambda.mapping",j=(n=>(n.DynamoDB="dynamodb",n.
|
|
107
|
+
Queue="sqs",n))(j||{});var N=new m.LambdaClient({}),ve=r(async(e,t)=>{h.Logger.logImport(S,e);let n=await N.
|
|
107
108
|
send(new m.ListEventSourceMappingsCommand({FunctionName:e,EventSourceArn:t})),[o]=n.
|
|
108
|
-
EventSourceMappings;return o?{eventId:o.UUID}:void 0},"importMapping"),
|
|
109
|
-
let{sourceArn:t,functionName:n}=e;h.Logger.logCreate(
|
|
110
|
-
{FunctionName:n,EventSourceArn:t,...
|
|
111
|
-
"createMapping"),
|
|
112
|
-
(${e})`),await
|
|
113
|
-
...
|
|
114
|
-
try{return await
|
|
109
|
+
EventSourceMappings;return o?{eventId:o.UUID}:void 0},"importMapping"),Re=r(async e=>{
|
|
110
|
+
let{sourceArn:t,functionName:n}=e;h.Logger.logCreate(S,n);let i=(await N.send(new m.CreateEventSourceMappingCommand(
|
|
111
|
+
{FunctionName:n,EventSourceArn:t,...Ae(e)}))).UUID;return await he(i),{eventId:i}},
|
|
112
|
+
"createMapping"),be=r(async(e,t)=>{let{functionName:n}=t;h.Logger.logUpdate(S,`${n}\
|
|
113
|
+
(${e})`),await N.send(new m.UpdateEventSourceMappingCommand({UUID:e,FunctionName:n,
|
|
114
|
+
...Ae(t)})),await he(e)},"updateMapping"),Ce=r(async e=>{h.Logger.logDelete(S,e);
|
|
115
|
+
try{return await N.send(new m.DeleteEventSourceMappingCommand({UUID:e})),!0}catch(t){
|
|
115
116
|
if(!(t instanceof m.ResourceNotFoundException))throw t;return!1}},"deleteMapping"),
|
|
116
|
-
|
|
117
|
-
"getMappingState"),
|
|
118
|
-
until(async()=>{let n=await
|
|
119
|
-
tForReadyState"),
|
|
117
|
+
xt=r(async e=>(await N.send(new m.GetEventSourceMappingCommand({UUID:e}))).State,
|
|
118
|
+
"getMappingState"),he=r(async e=>{let t=new Set(["Enabled","Disabled"]);await Q.Wait.
|
|
119
|
+
until(async()=>{let n=await xt(e);return t.has(n)?!0:Q.Wait.RetryAttempt})},"wai\
|
|
120
|
+
tForReadyState"),Ae=r(e=>{let{sourceArn:t,enabled:n,concurrency:o,batch:i}=e,{service:a}=(0,h.parseArn)(
|
|
120
121
|
t);return{Enabled:n,FunctionResponseTypes:[m.FunctionResponseType.ReportBatchItemFailures],
|
|
121
122
|
MaximumBatchingWindowInSeconds:i?.maxWait,BatchSize:i?.size,...a==="dynamodb"&&{
|
|
122
123
|
StartingPosition:m.EventSourcePosition.LATEST},...a==="sqs"&&{ScalingConfig:{MaximumConcurrency:o}}}},
|
|
123
|
-
"upsertMappingRequest");var Ie=r(()=>({equals:
|
|
124
|
-
getMappingHandler"),
|
|
125
|
-
"equalsResource"),
|
|
126
|
-
o={...t.parameters,dependencies:t.dependencies},i=(0,
|
|
124
|
+
"upsertMappingRequest");var Ie=r(()=>({equals:Pt,create:Me,replace:Rt,preview:vt,update:bt,delete:Ct}),"\
|
|
125
|
+
getMappingHandler"),Pt=r((e,t)=>!!e.result&&e.result.eventId===t.result?.eventId,
|
|
126
|
+
"equalsResource"),vt=r((e,t)=>{let n={...e.parameters,dependencies:e.dependencies},
|
|
127
|
+
o={...t.parameters,dependencies:t.dependencies},i=(0,T.deepCompare)(n,o,{exclude:{
|
|
127
128
|
getSourceArn:!0}});if(i.counts)return{...i,name:n.fromService}},"previewResource"),
|
|
128
|
-
Rt=r(async(e,t,n)=>{if(t.result)throw new Ee.ReplaceResourceError(
|
|
129
|
+
Rt=r(async(e,t,n)=>{if(t.result)throw new Ee.ReplaceResourceError(S,e.entryId,t.
|
|
129
130
|
entryId);return Me(e,n)},"replaceResource"),Me=r(async(e,t)=>{let n=e.parameters,
|
|
130
|
-
o=
|
|
131
|
+
o=A(S,"mapping",t),i=await n.getSourceArn(t);return{eventId:(await ve(o,i)??await Re(
|
|
131
132
|
{...e.parameters,functionName:o,sourceArn:i})).eventId,functionName:o,sourceArn:i}},
|
|
132
|
-
"createResource"),
|
|
133
|
-
a=
|
|
133
|
+
"createResource"),bt=r(async(e,t,n)=>{let o=e.result;if(!o)return;let i=o.sourceArn,
|
|
134
|
+
a=A(S,"mapping",n),u=t.result?.functionName??o.functionName,g={...e.parameters,functionName:a,
|
|
134
135
|
sourceArn:i},l={...t.parameters,functionName:u,sourceArn:i};return await ht(o.eventId,
|
|
135
|
-
g,l),{...o,functionName:a}},"updateResource"),Ct=r(async e=>{let t=e.result;t&&await
|
|
136
|
-
t.eventId)},"deleteResource"),ht=r(async(e,t,n)=>{!(0,
|
|
137
|
-
getSourceArn:!0,fromService:!0}})&&await
|
|
136
|
+
g,l),{...o,functionName:a}},"updateResource"),Ct=r(async e=>{let t=e.result;t&&await Ce(
|
|
137
|
+
t.eventId)},"deleteResource"),ht=r(async(e,t,n)=>{!(0,T.deepEqual)(t,n,{exclude:{
|
|
138
|
+
getSourceArn:!0,fromService:!0}})&&await be(e,t)},"checkGeneralUpdates");var He=r(()=>{(0,Ne.tryRegisterProvider)(v,Ie())},"registerMappingProvider");var Ve=r(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");var U=require("@ez4/aws-identity"),Te=require("@ez4/project/library");var E=require("@ez4/aws-identity");var Le=r(async e=>{let[t,n]=await Promise.all([(0,E.getRegion)(),(0,E.getAccountId)()]);
|
|
138
139
|
return(0,E.createPolicyDocument)([{permissions:["logs:CreateLogStream","logs:Put\
|
|
139
140
|
LogEvents"],resourceIds:[`arn:aws:logs:${t}:${n}:log-group:${e}-*:*`]}])},"getPo\
|
|
140
|
-
licyDocument");var
|
|
141
|
-
-lambda-policy`;return(0,
|
|
142
|
-
policyDocument:await
|
|
143
|
-
(0,Be.tryCreateTrigger)("@ez4/aws-function",{"deploy:prepareIdentityAccount":
|
|
144
|
-
"deploy:prepareExecutionPolicy":
|
|
145
|
-
t.entryId,i),u=[t.entryId];return n&&u.push(n.entryId),(0,Oe.attachEntry)(e,{type:
|
|
146
|
-
entryId:a,dependencies:u,parameters:{...o,functionName:i}})},"createFunction");var $e=require("@ez4/stateful"),J=require("@ez4/utils");var We=r(e=>e.type===
|
|
147
|
-
e,{type:
|
|
148
|
-
rmission"),
|
|
149
|
-
We(i)?i:null},"getPermission");var qe=require("@ez4/utils"),ke=require("@ez4/stateful");var
|
|
150
|
-
e,{type:
|
|
151
|
-
pping");var
|
|
141
|
+
licyDocument");var Ue=r(async e=>{let{state:t,options:n}=e,o=(0,Te.getServiceName)("",n),i=`${o}\
|
|
142
|
+
-lambda-policy`;return(0,U.tryGetPolicy)(t,i)??(0,U.createPolicy)(t,{tags:n.tags,
|
|
143
|
+
policyDocument:await Le(o),policyName:i})},"prepareExecutionPolicy");var At=r(()=>{(0,De.registerTriggers)(),(0,Ge.registerTriggers)(),(0,ze.registerTriggers)(),
|
|
144
|
+
(0,Be.tryCreateTrigger)("@ez4/aws-function",{"deploy:prepareIdentityAccount":Ve,
|
|
145
|
+
"deploy:prepareExecutionPolicy":Ue}),le(),Pe(),He()},"registerTriggers");var D=require("@ez4/utils"),Oe=require("@ez4/stateful");var Et=r((e,t,n,o)=>{let i=(0,D.toKebabCase)(o.functionName),a=(0,D.hashData)(f,
|
|
146
|
+
t.entryId,i),u=[t.entryId];return n&&u.push(n.entryId),(0,Oe.attachEntry)(e,{type:f,
|
|
147
|
+
entryId:a,dependencies:u,parameters:{...o,functionName:i}})},"createFunction");var $e=require("@ez4/stateful"),J=require("@ez4/utils");var We=r(e=>e.type===x,"isPermissionState");var It=r((e,t,n,o)=>{let i=(0,J.hashData)(x,t.entryId,n.entryId);return(0,$e.attachEntry)(
|
|
148
|
+
e,{type:x,entryId:i,dependencies:[t.entryId,n.entryId],parameters:o})},"createPe\
|
|
149
|
+
rmission"),Mt=r((e,t,n)=>{let o=(0,J.hashData)(x,t.entryId,n.entryId),i=e[o];return i&&
|
|
150
|
+
We(i)?i:null},"getPermission");var qe=require("@ez4/utils"),ke=require("@ez4/stateful");var Nt=r((e,t,n,o)=>{let i=(0,qe.hashData)(v,t.entryId,n.entryId);return(0,ke.attachEntry)(
|
|
151
|
+
e,{type:v,entryId:i,dependencies:[t.entryId,n.entryId],parameters:o})},"createMa\
|
|
152
|
+
pping");var Ht=r(e=>e.type===v,"isMappingState");var Vt=r((e,t,n)=>`arn:aws:lambda:${e}:${t}:function:${n}`,"buildFunctionArn");0&&(module.exports={FunctionServiceName,FunctionServiceType,MappingService,MappingServiceName,
|
|
152
153
|
MappingServiceType,PermissionServiceName,PermissionServiceType,buildFunctionArn,
|
|
153
154
|
createFunction,createMapping,createPermission,getFunctionArn,getFunctionName,getFunctionState,
|
|
154
155
|
getPermission,isFunctionState,isMappingState,registerTriggers,tryGetFunctionArn,
|
package/dist/main.mjs
CHANGED
|
@@ -1,140 +1,141 @@
|
|
|
1
|
-
var he=Object.defineProperty;var r=(e,t)=>he(e,"name",{value:t,configurable:!0});import{registerTriggers as
|
|
2
|
-
import{registerTriggers as
|
|
3
|
-
import{deepCompare as
|
|
4
|
-
import{getRoleArn as J}from"@ez4/aws-identity";import{LambdaClient as
|
|
5
|
-
UpdateFunctionCodeCommand as De,UpdateFunctionConfigurationCommand as
|
|
6
|
-
TagResourceCommand as
|
|
7
|
-
waitUntilFunctionUpdated as
|
|
8
|
-
ApplicationLogLevel as C,SystemLogLevel as
|
|
9
|
-
import{Logger as c,tryParseArn as
|
|
10
|
-
t))throw new Ae(a,`${t} is an invalid variable name .`)},"assertVariables"),
|
|
11
|
-
e=>{let t={};for(let n in e)t[n]=
|
|
12
|
-
"getZipBuffer");var
|
|
13
|
-
c.logImport(a,e);try{let n=await
|
|
1
|
+
var he=Object.defineProperty;var r=(e,t)=>he(e,"name",{value:t,configurable:!0});import{registerTriggers as kt}from"@ez4/aws-common";import{registerTriggers as Zt}from"@ez4/aws-identity";
|
|
2
|
+
import{registerTriggers as jt}from"@ez4/aws-logs";import{tryCreateTrigger as Qt}from"@ez4/project/library";import{tryRegisterProvider as it}from"@ez4/aws-common";import{applyTagUpdates as Ze,getBundleHash as V,Logger as je,ReplaceResourceError as Qe}from"@ez4/aws-common";
|
|
3
|
+
import{deepCompare as Je,deepEqual as Ke,hashFile as j}from"@ez4/utils";import{getLogGroupName as Q}from"@ez4/aws-logs";
|
|
4
|
+
import{getRoleArn as J}from"@ez4/aws-identity";import{LambdaClient as Ve,GetFunctionCommand as Le,CreateFunctionCommand as Te,DeleteFunctionCommand as Ue,
|
|
5
|
+
UpdateFunctionCodeCommand as De,UpdateFunctionConfigurationCommand as Ge,PublishVersionCommand as ze,
|
|
6
|
+
TagResourceCommand as Be,UntagResourceCommand as Oe,waitUntilFunctionActive as We,
|
|
7
|
+
waitUntilFunctionUpdated as T,waitUntilPublishedVersionActive as $e,ResourceNotFoundException as U,
|
|
8
|
+
ApplicationLogLevel as C,SystemLogLevel as D,LogFormat as G}from"@aws-sdk/client-lambda";
|
|
9
|
+
import{Logger as c,tryParseArn as z,waitCreation as qe,waitDeletion as ke}from"@ez4/aws-common";import{InvalidParameterError as Ae}from"@ez4/aws-common";import{hashData as Ee}from"@ez4/utils";var a="AWS:Lambda/Function",d="aws:lambda.function";var Ie=/[a-z][\w]+/i,Me=r(e=>Ie.test(e),"isValidName"),I=r(e=>{for(let t in e)if(!Me(
|
|
10
|
+
t))throw new Ae(a,`${t} is an invalid variable name .`)},"assertVariables"),P=r(
|
|
11
|
+
e=>{let t={};for(let n in e)t[n]=Ee(e[n]);return t},"protectVariables");import Ne from"adm-zip";import{readFile as He}from"node:fs/promises";var L=r(async(e,t)=>{let n=new Ne,o=await He(e);return n.addFile(t,o),n.toBufferPromise()},
|
|
12
|
+
"getZipBuffer");var f=new Ve({}),h={minDelay:15,maxWaitTime:1800,maxDelay:60,client:f},B=r(async(e,t)=>{
|
|
13
|
+
c.logImport(a,e);try{let n=await f.send(new Le({FunctionName:e,Qualifier:t})),o=n.
|
|
14
14
|
Configuration.Version,i=n.Configuration.FunctionArn;return{functionVersion:o,functionArn:i}}catch(n){
|
|
15
|
-
if(!(n instanceof
|
|
16
|
-
variables:n}=e;c.logCreate(a,t),n&&
|
|
17
|
-
s=await
|
|
15
|
+
if(!(n instanceof U))throw n;return}},"importFunction"),O=r(async e=>{let{functionName:t,
|
|
16
|
+
variables:n}=e;c.logCreate(a,t),n&&I(n);let o=Z(e.handlerName),i=await k(e.sourceFile),
|
|
17
|
+
s=await qe(()=>f.send(new Te({FunctionName:e.functionName,Description:e.description,
|
|
18
18
|
MemorySize:e.memory,Timeout:e.timeout,Role:e.roleArn,Handler:o,Runtime:"nodejs22\
|
|
19
19
|
.x",PackageType:"Zip",LoggingConfig:{LogGroup:e.logGroup,ApplicationLogLevel:e.debug?
|
|
20
|
-
C.Debug:C.Warn,SystemLogLevel:
|
|
21
|
-
Variables:n},Tags:{...e.tags,ManagedBy:"EZ4"}})));c.logWait(a,t),await
|
|
20
|
+
C.Debug:C.Warn,SystemLogLevel:D.Warn,LogFormat:G.Json},Code:{ZipFile:i},Environment:{
|
|
21
|
+
Variables:n},Tags:{...e.tags,ManagedBy:"EZ4"}})));c.logWait(a,t),await We(h,{FunctionName:t});
|
|
22
22
|
let p=s.FunctionArn;return e.publish?{functionVersion:await $(t),functionArn:p}:
|
|
23
|
-
{functionArn:p}},"createFunction"),
|
|
24
|
-
ode`);let n=await k(t.sourceFile),o=await
|
|
25
|
-
publish,ZipFile:n}));c.logWait(a,e),await
|
|
23
|
+
{functionArn:p}},"createFunction"),M=r(async(e,t)=>{c.logUpdate(a,`${e} source c\
|
|
24
|
+
ode`);let n=await k(t.sourceFile),o=await f.send(new De({FunctionName:e,Publish:t.
|
|
25
|
+
publish,ZipFile:n}));c.logWait(a,e),await T(h,{FunctionName:e});let i=o.FunctionArn;
|
|
26
26
|
return t.publish?{functionVersion:await $(e),functionArn:i}:{functionArn:i}},"up\
|
|
27
|
-
dateSourceCode"),
|
|
28
|
-
`${e} configuration`),o&&
|
|
27
|
+
dateSourceCode"),N=r(async(e,t)=>{let{handlerName:n,variables:o}=t;c.logUpdate(a,
|
|
28
|
+
`${e} configuration`),o&&I(o),await f.send(new Ge({FunctionName:e,Description:t.
|
|
29
29
|
description,MemorySize:t.memory,Timeout:t.timeout,Role:t.roleArn,Runtime:"nodejs\
|
|
30
30
|
22.x",...n&&{Handler:Z(n)},LoggingConfig:{LogGroup:t.logGroup,ApplicationLogLevel:t.
|
|
31
|
-
debug?C.Debug:C.Warn,SystemLogLevel:
|
|
32
|
-
c.logWait(a,e),await
|
|
33
|
-
c.logDelete(a,e),await
|
|
34
|
-
if(!(t instanceof
|
|
35
|
-
e);let t=await
|
|
36
|
-
h,{FunctionName:e,Qualifier:n}),n},"publishFunction"),
|
|
37
|
-
resourceName??e;c.logTag(a,n),await
|
|
38
|
-
EZ4"}}))},"tagFunction"),q=r(async(e,t)=>{let n=
|
|
39
|
-
a,n),await
|
|
40
|
-
main.mjs"),"getSourceZipFile"),Z=r(e=>`main.${e}`,"getSourceHandlerName");var K=r(()=>({equals:
|
|
41
|
-
tFunctionHandler"),
|
|
42
|
-
"equalsResource"),
|
|
43
|
-
connections:e.connections,dependencies:e.dependencies,variables:n.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
sourceHash,valuesHash:t.result?.valuesHash});if(i.counts)return{
|
|
47
|
-
"previewResource"),
|
|
48
|
-
return _(e,n)},"replaceResource"),_=r(async(e,t)=>{let{functionName:n
|
|
49
|
-
i=Q(a,n,t),s=J(a,n,t),[p,u,m]=await Promise.all([
|
|
50
|
-
t),o.getFunctionHash()]),l=await B(
|
|
51
|
-
|
|
52
|
-
H(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
s,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let
|
|
64
|
-
functionName:!0,tags:!0}})&&await
|
|
65
|
-
|
|
66
|
-
let[i,s]=await Promise.
|
|
67
|
-
sourceHash,u=n?.valuesHash;
|
|
68
|
-
o),
|
|
69
|
-
{valuesHash:s,sourceHash:i};let{
|
|
70
|
-
sourceFile:m});return{
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
t
|
|
74
|
-
t,n);if(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
e,t,
|
|
79
|
-
|
|
80
|
-
|
|
31
|
+
debug?C.Debug:C.Warn,SystemLogLevel:D.Warn,LogFormat:G.Json},Environment:{Variables:o}})),
|
|
32
|
+
c.logWait(a,e),await T(h,{FunctionName:e})},"updateConfiguration"),W=r(async e=>{
|
|
33
|
+
c.logDelete(a,e),await ke(async()=>{try{await f.send(new Ue({FunctionName:e}))}catch(t){
|
|
34
|
+
if(!(t instanceof U))throw t}})},"deleteFunction"),$=r(async e=>{c.logPublish(a,
|
|
35
|
+
e);let t=await f.send(new ze({FunctionName:e}));c.logWait(a,e);let n=t.Version;return await $e(
|
|
36
|
+
h,{FunctionName:e,Qualifier:n}),n},"publishFunction"),H=r(async(e,t)=>{let n=z(e)?.
|
|
37
|
+
resourceName??e;c.logTag(a,n),await f.send(new Be({Resource:e,Tags:{...t,ManagedBy:"\
|
|
38
|
+
EZ4"}}))},"tagFunction"),q=r(async(e,t)=>{let n=z(e)?.resourceName??e;c.logUntag(
|
|
39
|
+
a,n),await f.send(new Oe({Resource:e,TagKeys:t}))},"untagFunction"),k=r(e=>L(e,"\
|
|
40
|
+
main.mjs"),"getSourceZipFile"),Z=r(e=>`main.${e}`,"getSourceHandlerName");var K=r(()=>({equals:_e,create:_,replace:Ye,preview:Xe,update:et,delete:tt}),"ge\
|
|
41
|
+
tFunctionHandler"),_e=r((e,t)=>!!e.result&&e.result.functionArn===t.result?.functionArn,
|
|
42
|
+
"equalsResource"),Xe=r(async(e,t)=>{let n=e.parameters,o=t.parameters,i=Je({...n,
|
|
43
|
+
connections:e.connections,dependencies:e.dependencies,variables:P(await n.getFunctionVariables()),
|
|
44
|
+
sourceHash:await V(...n.getFunctionFiles()),valuesHash:n.getFunctionHash()},{...o,
|
|
45
|
+
connections:t.connections,dependencies:t.dependencies,variables:t.result?.variables,
|
|
46
|
+
sourceHash:t.result?.sourceHash,valuesHash:t.result?.valuesHash});if(i.counts)return{
|
|
47
|
+
...i,name:n.functionName}},"previewResource"),Ye=r(async(e,t,n)=>{if(t.result)throw new Qe(
|
|
48
|
+
a,e.entryId,t.entryId);return _(e,n)},"replaceResource"),_=r(async(e,t)=>{let{functionName:n,
|
|
49
|
+
...o}=e.parameters,i=Q(a,n,t),s=J(a,n,t),[p,u,m,g]=await Promise.all([V(...o.getFunctionFiles()),
|
|
50
|
+
o.getFunctionBundle(t),o.getFunctionHash(),o.getFunctionVariables()]),l=await B(
|
|
51
|
+
n),F=await j(u);if(l)return await N(n,{...o,variables:g,logGroup:i,roleArn:s}),await M(
|
|
52
|
+
n,{publish:!1,sourceFile:u}),await H(l.functionArn,{...o.tags}),{functionArn:l.functionArn,
|
|
53
|
+
functionVersion:l.functionVersion,variables:P(g),valuesHash:m,sourceHash:p,bundleHash:F,
|
|
54
|
+
logGroup:i,roleArn:s};let b=await O({...o,publish:!0,functionName:n,sourceFile:u,
|
|
55
|
+
variables:g,logGroup:i,roleArn:s});return{functionArn:b.functionArn,functionVersion:b.
|
|
56
|
+
functionVersion,variables:P(g),valuesHash:m,sourceHash:p,bundleHash:F,logGroup:i,
|
|
57
|
+
roleArn:s}},"createResource"),et=r(async(e,t,n)=>{let{parameters:o,result:i}=e;if(!i)
|
|
58
|
+
return;let s=o.functionName,p=await o.getFunctionVariables(),u=t.result?.variables??
|
|
59
|
+
p,m=J(a,s,n),g=t.result?.roleArn??m,l=Q(a,s,n),F=t.result?.logGroup??l,b={...o,variables:p,
|
|
60
|
+
roleArn:m,logGroup:l},be={...t.parameters,variables:u,roleArn:g,logGroup:F};await nt(
|
|
61
|
+
s,b,be),await rt(i.functionArn,o,t.parameters);let Ce=await ot(s,o,t.result,n);return{
|
|
62
|
+
...i,...Ce,variables:P(p),logGroup:l,roleArn:m}},"updateResource"),tt=r(async e=>{
|
|
63
|
+
let{result:t,parameters:n}=e;t&&await W(n.functionName)},"deleteResource"),nt=r(
|
|
64
|
+
async(e,t,n)=>{!Ke(t,n,{exclude:{sourceFile:!0,functionName:!0,tags:!0}})&&await N(
|
|
65
|
+
e,t)},"checkConfigurationUpdates"),rt=r(async(e,t,n)=>{await Ze(t.tags,n.tags,o=>H(
|
|
66
|
+
e,o),o=>q(e,o))},"checkTagUpdates"),ot=r(async(e,t,n,o)=>{let[i,s]=await Promise.
|
|
67
|
+
all([V(...t.getFunctionFiles()),t.getFunctionHash()]),p=n?.sourceHash,u=n?.valuesHash;
|
|
68
|
+
if(i!==p||s!==u||o.force){let m=await t.getFunctionBundle(o),g=await j(m),l=n?.bundleHash;
|
|
69
|
+
if(g===l)return je.logSkip(a,`${e} source code`),{valuesHash:s,sourceHash:i};let{
|
|
70
|
+
functionVersion:F}=await M(e,{publish:!n?.functionVersion,sourceFile:m});return{
|
|
71
|
+
valuesHash:s,sourceHash:i,bundleHash:g,...F&&{functionVersion:F}}}},"checkSource\
|
|
72
|
+
CodeUpdates");var X=r(()=>{it(d,K())},"registerFunctionProvider");import{tryRegisterProvider as St}from"@ez4/aws-common";import{ReplaceResourceError as ut}from"@ez4/aws-common";import{IncompleteResourceError as Y}from"@ez4/aws-common";var A=class extends Error{static{r(this,"FunctionNotFoundError")}constructor(t){
|
|
73
|
+
super(`Function ${t} wasn't found.`)}};var ee=r(e=>e.type===d,"isFunctionState"),zn=r((e,t,n)=>{try{let o=e.getServiceState(
|
|
74
|
+
t,n);if(ee(o))return o}catch{}},"tryGetFunctionState"),Bn=r((e,t,n)=>{let o=e.getServiceState(
|
|
75
|
+
t,n);if(!ee(o))throw new A(t);return o},"getFunctionState"),v=r((e,t,n)=>{let o=n.
|
|
76
|
+
getDependencies(d).at(0)?.parameters;if(!o?.functionName)throw new Y(e,t,"functi\
|
|
77
|
+
onName");return o.functionName},"getFunctionName"),st=r(e=>e.getDependencies(d)[0]?.
|
|
78
|
+
result?.functionArn,"tryGetFunctionArn"),On=r((e,t,n)=>{let o=st(n);if(!o)throw new Y(
|
|
79
|
+
e,t,"functionArn");return o},"getFunctionArn");import{LambdaClient as at,AddPermissionCommand as pt,RemovePermissionCommand as ct,
|
|
80
|
+
ResourceNotFoundException as mt}from"@aws-sdk/client-lambda";import{Logger as te}from"@ez4/aws-common";var x="AWS:Lambda/Permission",S="aws:lambda.permission";var ne=new at({}),re=r(async e=>{te.logCreate(x,e.functionName);let t=e.statementId??
|
|
81
|
+
`ID${Date.now()}`;return await ne.send(new pt({StatementId:t,FunctionName:e.functionName,
|
|
81
82
|
SourceArn:e.sourceArn,Principal:e.principal,Action:e.action})),{statementId:t}},
|
|
82
83
|
"createPermission"),oe=r(async(e,t)=>{te.logDelete(x,e);try{return await ne.send(
|
|
83
|
-
new
|
|
84
|
-
return!1}},"deletePermission");var ie=r(()=>({equals:
|
|
85
|
-
getPermissionHandler"),
|
|
86
|
-
functionName,"equalsResource"),
|
|
87
|
-
if(t.result)throw new
|
|
88
|
-
se=r(async(e,t)=>{let n=e.parameters,o=
|
|
84
|
+
new ct({FunctionName:e,StatementId:t})),!0}catch(n){if(!(n instanceof mt))throw n;
|
|
85
|
+
return!1}},"deletePermission");var ie=r(()=>({equals:lt,create:se,replace:dt,preview:gt,update:ft,delete:yt}),"\
|
|
86
|
+
getPermissionHandler"),lt=r((e,t)=>!!e.result&&e.result.functionName===t.result?.
|
|
87
|
+
functionName,"equalsResource"),gt=r((e,t)=>{},"previewResource"),dt=r(async(e,t,n)=>{
|
|
88
|
+
if(t.result)throw new ut(x,e.entryId,t.entryId);return se(e,n)},"replaceResource"),
|
|
89
|
+
se=r(async(e,t)=>{let n=e.parameters,o=v(x,"permission",t),i=await n.getPermission(
|
|
89
90
|
t);return{statementId:(await re({action:"lambda:InvokeFunction",sourceArn:i.sourceArn,
|
|
90
91
|
principal:i.principal,functionName:o})).statementId,functionName:o}},"createReso\
|
|
91
|
-
urce"),
|
|
92
|
-
t.functionName,t.statementId)},"deleteResource");var ae=r(()=>{
|
|
93
|
-
deepEqual as
|
|
94
|
-
UpdateEventSourceMappingCommand as
|
|
95
|
-
FunctionResponseType as
|
|
96
|
-
import{Logger as
|
|
97
|
-
n.Queue="sqs",n))(pe||{});var R=new
|
|
92
|
+
urce"),ft=r(async()=>{},"updateResource"),yt=r(async e=>{let t=e.result;t&&await oe(
|
|
93
|
+
t.functionName,t.statementId)},"deleteResource");var ae=r(()=>{St(S,ie())},"registerPermissionProvider");import{tryRegisterProvider as Gt}from"@ez4/aws-common";import{ReplaceResourceError as It}from"@ez4/aws-common";import{deepCompare as Mt,
|
|
94
|
+
deepEqual as Nt}from"@ez4/utils";import{LambdaClient as Ft,GetEventSourceMappingCommand as wt,CreateEventSourceMappingCommand as xt,
|
|
95
|
+
UpdateEventSourceMappingCommand as Pt,DeleteEventSourceMappingCommand as vt,ListEventSourceMappingsCommand as Rt,
|
|
96
|
+
FunctionResponseType as bt,EventSourcePosition as Ct,ResourceNotFoundException as ht}from"@aws-sdk/client-lambda";
|
|
97
|
+
import{Logger as E,parseArn as At}from"@ez4/aws-common";import{Wait as ce}from"@ez4/utils";var y="AWS:Lambda/Mapping",w="aws:lambda.mapping",pe=(n=>(n.DynamoDB="dynamodb",
|
|
98
|
+
n.Queue="sqs",n))(pe||{});var R=new Ft({}),me=r(async(e,t)=>{E.logImport(y,e);let n=await R.send(new Rt({FunctionName:e,
|
|
98
99
|
EventSourceArn:t})),[o]=n.EventSourceMappings;return o?{eventId:o.UUID}:void 0},
|
|
99
|
-
"importMapping"),ue=r(async e=>{let{sourceArn:t,functionName:n}=e;
|
|
100
|
-
n);let i=(await R.send(new
|
|
100
|
+
"importMapping"),ue=r(async e=>{let{sourceArn:t,functionName:n}=e;E.logCreate(y,
|
|
101
|
+
n);let i=(await R.send(new xt({FunctionName:n,EventSourceArn:t,...fe(e)}))).UUID;
|
|
101
102
|
return await de(i),{eventId:i}},"createMapping"),le=r(async(e,t)=>{let{functionName:n}=t;
|
|
102
|
-
|
|
103
|
-
await de(e)},"updateMapping"),ge=r(async e=>{
|
|
104
|
-
send(new
|
|
105
|
-
eteMapping"),
|
|
103
|
+
E.logUpdate(y,`${n} (${e})`),await R.send(new Pt({UUID:e,FunctionName:n,...fe(t)})),
|
|
104
|
+
await de(e)},"updateMapping"),ge=r(async e=>{E.logDelete(y,e);try{return await R.
|
|
105
|
+
send(new vt({UUID:e})),!0}catch(t){if(!(t instanceof ht))throw t;return!1}},"del\
|
|
106
|
+
eteMapping"),Et=r(async e=>(await R.send(new wt({UUID:e}))).State,"getMappingSta\
|
|
106
107
|
te"),de=r(async e=>{let t=new Set(["Enabled","Disabled"]);await ce.until(async()=>{
|
|
107
|
-
let n=await
|
|
108
|
+
let n=await Et(e);return t.has(n)?!0:ce.RetryAttempt})},"waitForReadyState"),fe=r(
|
|
108
109
|
e=>{let{sourceArn:t,enabled:n,concurrency:o,batch:i}=e,{service:s}=At(t);return{
|
|
109
|
-
Enabled:n,FunctionResponseTypes:[
|
|
110
|
+
Enabled:n,FunctionResponseTypes:[bt.ReportBatchItemFailures],MaximumBatchingWindowInSeconds:i?.
|
|
110
111
|
maxWait,BatchSize:i?.size,...s==="dynamodb"&&{StartingPosition:Ct.LATEST},...s===
|
|
111
|
-
"sqs"&&{ScalingConfig:{MaximumConcurrency:o}}}},"upsertMappingRequest");var ye=r(()=>({equals:
|
|
112
|
-
getMappingHandler"),
|
|
113
|
-
"equalsResource"),
|
|
114
|
-
o={...t.parameters,dependencies:t.dependencies},i=
|
|
115
|
-
if(i.counts)return{...i,name:n.fromService}},"previewResource"),
|
|
116
|
-
if(t.result)throw new
|
|
117
|
-
Se=r(async(e,t)=>{let n=e.parameters,o=
|
|
112
|
+
"sqs"&&{ScalingConfig:{MaximumConcurrency:o}}}},"upsertMappingRequest");var ye=r(()=>({equals:Ht,create:Se,replace:Lt,preview:Vt,update:Tt,delete:Ut}),"\
|
|
113
|
+
getMappingHandler"),Ht=r((e,t)=>!!e.result&&e.result.eventId===t.result?.eventId,
|
|
114
|
+
"equalsResource"),Vt=r((e,t)=>{let n={...e.parameters,dependencies:e.dependencies},
|
|
115
|
+
o={...t.parameters,dependencies:t.dependencies},i=Mt(n,o,{exclude:{getSourceArn:!0}});
|
|
116
|
+
if(i.counts)return{...i,name:n.fromService}},"previewResource"),Lt=r(async(e,t,n)=>{
|
|
117
|
+
if(t.result)throw new It(y,e.entryId,t.entryId);return Se(e,n)},"replaceResource"),
|
|
118
|
+
Se=r(async(e,t)=>{let n=e.parameters,o=v(y,"mapping",t),i=await n.getSourceArn(t);
|
|
118
119
|
return{eventId:(await me(o,i)??await ue({...e.parameters,functionName:o,sourceArn:i})).
|
|
119
|
-
eventId,functionName:o,sourceArn:i}},"createResource"),
|
|
120
|
-
result;if(!o)return;let i=o.sourceArn,s=
|
|
120
|
+
eventId,functionName:o,sourceArn:i}},"createResource"),Tt=r(async(e,t,n)=>{let o=e.
|
|
121
|
+
result;if(!o)return;let i=o.sourceArn,s=v(y,"mapping",n),p=t.result?.functionName??
|
|
121
122
|
o.functionName,u={...e.parameters,functionName:s,sourceArn:i},m={...t.parameters,
|
|
122
123
|
functionName:p,sourceArn:i};return await Dt(o.eventId,u,m),{...o,functionName:s}},
|
|
123
|
-
"updateResource"),
|
|
124
|
-
esource"),Dt=r(async(e,t,n)=>{!
|
|
125
|
-
await le(e,t)},"checkGeneralUpdates");var Fe=r(()=>{
|
|
124
|
+
"updateResource"),Ut=r(async e=>{let t=e.result;t&&await ge(t.eventId)},"deleteR\
|
|
125
|
+
esource"),Dt=r(async(e,t,n)=>{!Nt(t,n,{exclude:{getSourceArn:!0,fromService:!0}})&&
|
|
126
|
+
await le(e,t)},"checkGeneralUpdates");var Fe=r(()=>{Gt(w,ye())},"registerMappingProvider");var we=r(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");import{createPolicy as Wt,tryGetPolicy as $t}from"@ez4/aws-identity";import{getServiceName as qt}from"@ez4/project/library";import{getAccountId as zt,getRegion as Bt,createPolicyDocument as Ot}from"@ez4/aws-identity";var xe=r(async e=>{let[t,n]=await Promise.all([Bt(),zt()]);return Ot([{permissions:[
|
|
126
127
|
"logs:CreateLogStream","logs:PutLogEvents"],resourceIds:[`arn:aws:logs:${t}:${n}\
|
|
127
|
-
:log-group:${e}-*:*`]}])},"getPolicyDocument");var Pe=r(async e=>{let{state:t,options:n}=e,o
|
|
128
|
-
t,i)??
|
|
129
|
-
tionPolicy");var
|
|
130
|
-
unt":we,"deploy:prepareExecutionPolicy":Pe}),X(),ae(),Fe()},"registerTriggers");import{toKebabCase as
|
|
131
|
-
return n&&p.push(n.entryId),
|
|
132
|
-
functionName:i}})},"createFunction");import{attachEntry as
|
|
133
|
-
dependencies:[t.entryId,n.entryId],parameters:o})},"createPermission"),
|
|
134
|
-
let o=
|
|
135
|
-
dependencies:[t.entryId,n.entryId],parameters:o})},"createMapping");var
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
128
|
+
:log-group:${e}-*:*`]}])},"getPolicyDocument");var Pe=r(async e=>{let{state:t,options:n}=e,o=qt("",n),i=`${o}-lambda-policy`;return $t(
|
|
129
|
+
t,i)??Wt(t,{tags:n.tags,policyDocument:await xe(o),policyName:i})},"prepareExecu\
|
|
130
|
+
tionPolicy");var kr=r(()=>{kt(),Zt(),jt(),Qt("@ez4/aws-function",{"deploy:prepareIdentityAcco\
|
|
131
|
+
unt":we,"deploy:prepareExecutionPolicy":Pe}),X(),ae(),Fe()},"registerTriggers");import{toKebabCase as Jt,hashData as Kt}from"@ez4/utils";import{attachEntry as _t}from"@ez4/stateful";var _r=r((e,t,n,o)=>{let i=Jt(o.functionName),s=Kt(d,t.entryId,i),p=[t.entryId];
|
|
132
|
+
return n&&p.push(n.entryId),_t(e,{type:d,entryId:s,dependencies:p,parameters:{...o,
|
|
133
|
+
functionName:i}})},"createFunction");import{attachEntry as Xt}from"@ez4/stateful";import{hashData as Re}from"@ez4/utils";var ve=r(e=>e.type===S,"isPermissionState");var ao=r((e,t,n,o)=>{let i=Re(S,t.entryId,n.entryId);return Xt(e,{type:S,entryId:i,
|
|
134
|
+
dependencies:[t.entryId,n.entryId],parameters:o})},"createPermission"),po=r((e,t,n)=>{
|
|
135
|
+
let o=Re(S,t.entryId,n.entryId),i=e[o];return i&&ve(i)?i:null},"getPermission");import{hashData as Yt}from"@ez4/utils";import{attachEntry as en}from"@ez4/stateful";var fo=r((e,t,n,o)=>{let i=Yt(w,t.entryId,n.entryId);return en(e,{type:w,entryId:i,
|
|
136
|
+
dependencies:[t.entryId,n.entryId],parameters:o})},"createMapping");var wo=r(e=>e.type===w,"isMappingState");var vo=r((e,t,n)=>`arn:aws:lambda:${e}:${t}:function:${n}`,"buildFunctionArn");export{a as FunctionServiceName,d as FunctionServiceType,pe as MappingService,y as MappingServiceName,
|
|
137
|
+
w as MappingServiceType,x as PermissionServiceName,S as PermissionServiceType,vo as buildFunctionArn,
|
|
138
|
+
_r as createFunction,fo as createMapping,ao as createPermission,On as getFunctionArn,
|
|
139
|
+
v as getFunctionName,Bn as getFunctionState,po as getPermission,ee as isFunctionState,
|
|
140
|
+
wo as isMappingState,kr as registerTriggers,st as tryGetFunctionArn,zn as tryGetFunctionState};
|
|
140
141
|
//# sourceMappingURL=main.mjs.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ez4/aws-function",
|
|
3
3
|
"description": "EZ4: Self-managed AWS lambda function provider",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.37.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@aws-sdk/client-lambda": "^3.913.0",
|
|
46
|
-
"@ez4/aws-common": "^0.
|
|
47
|
-
"@ez4/aws-identity": "^0.
|
|
48
|
-
"@ez4/aws-logs": "^0.
|
|
49
|
-
"@ez4/project": "^0.
|
|
50
|
-
"@ez4/stateful": "^0.
|
|
51
|
-
"@ez4/utils": "^0.
|
|
46
|
+
"@ez4/aws-common": "^0.37.0",
|
|
47
|
+
"@ez4/aws-identity": "^0.37.0",
|
|
48
|
+
"@ez4/aws-logs": "^0.37.0",
|
|
49
|
+
"@ez4/project": "^0.37.0",
|
|
50
|
+
"@ez4/stateful": "^0.37.0",
|
|
51
|
+
"@ez4/utils": "^0.37.0",
|
|
52
52
|
"@types/adm-zip": "^0.5.5",
|
|
53
53
|
"adm-zip": "^0.5.14"
|
|
54
54
|
}
|