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