@ez4/aws-function 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Silas B.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # EZ4: AWS Function
@@ -0,0 +1,31 @@
1
+ import type { Arn, ResourceTags } from '@ez4/aws-common';
2
+ import type { Variables } from '../types/variables.js';
3
+ export type CreateRequest = {
4
+ roleArn: Arn;
5
+ sourceFile: string;
6
+ functionName: string;
7
+ handlerName: string;
8
+ description?: string;
9
+ variables?: Variables;
10
+ timeout?: number;
11
+ memory?: number;
12
+ tags?: ResourceTags;
13
+ };
14
+ export type CreateResponse = {
15
+ functionArn: Arn;
16
+ functionName: string;
17
+ };
18
+ export type UpdateConfigRequest = {
19
+ roleArn?: Arn;
20
+ handlerName?: string;
21
+ description?: string;
22
+ variables?: Variables;
23
+ timeout?: number;
24
+ memory?: number;
25
+ };
26
+ export declare const createFunction: (request: CreateRequest) => Promise<CreateResponse>;
27
+ export declare const tagFunction: (functionArn: Arn, tags: ResourceTags) => Promise<void>;
28
+ export declare const untagFunction: (functionArn: Arn, tagKeys: string[]) => Promise<void>;
29
+ export declare const updateSourceCode: (functionName: string, sourceFile: string) => Promise<void>;
30
+ export declare const updateConfiguration: (functionName: string, request: UpdateConfigRequest) => Promise<void>;
31
+ export declare const deleteFunction: (functionName: string) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { StepHandler } from '@ez4/stateful';
2
+ import type { FunctionState } from './types.js';
3
+ export declare const getFunctionHandler: () => StepHandler<FunctionState>;
@@ -0,0 +1,3 @@
1
+ import type { Variables } from '../../types/variables.js';
2
+ export declare const isValidVariableName: (name: string) => boolean;
3
+ export declare const assertVariables: (variables: Variables) => void;
@@ -0,0 +1 @@
1
+ export declare const getZipBuffer: (filePath: string, entryName: string) => Promise<Buffer>;
@@ -0,0 +1,11 @@
1
+ import type { RoleState } from '@ez4/aws-identity';
2
+ import type { EntryState, EntryStates } from '@ez4/stateful';
3
+ import type { FunctionParameters, FunctionState } from './types.js';
4
+ import { FunctionServiceType } from './types.js';
5
+ export declare const isFunction: (resource: EntryState) => resource is FunctionState;
6
+ export declare const createFunction: <E extends EntryState>(state: EntryStates<E>, roleState: RoleState, parameters: FunctionParameters) => FunctionState;
7
+ export declare const getFunction: <E extends EntryState>(state: EntryStates<E>, roleState: RoleState, functionName: string) => (E & EntryState & {
8
+ type: typeof FunctionServiceType;
9
+ parameters: FunctionParameters;
10
+ result?: import("./types.js").FunctionResult;
11
+ }) | null;
@@ -0,0 +1,15 @@
1
+ import type { EntryState } from '@ez4/stateful';
2
+ import type { Arn } from '@ez4/aws-common';
3
+ import type { CreateRequest, CreateResponse } from './client.js';
4
+ export declare const FunctionServiceName = "AWS:Lambda/Function";
5
+ export declare const FunctionServiceType = "aws:lambda.function";
6
+ export type FunctionParameters = Omit<CreateRequest, 'roleArn'>;
7
+ export type FunctionResult = CreateResponse & {
8
+ sourceHash: string;
9
+ roleArn: Arn;
10
+ };
11
+ export type FunctionState = EntryState & {
12
+ type: typeof FunctionServiceType;
13
+ parameters: FunctionParameters;
14
+ result?: FunctionResult;
15
+ };
@@ -0,0 +1,4 @@
1
+ import type { EntryState, StepContext } from '@ez4/stateful';
2
+ import type { FunctionState } from './types.js';
3
+ export declare const getFunctionName: <E extends EntryState>(serviceName: string, resourceId: string, context: StepContext<E | FunctionState>) => any;
4
+ export declare const getFunctionArn: <E extends EntryState>(serviceName: string, resourceId: string, context: StepContext<E | FunctionState>) => any;
package/dist/main.cjs ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";var ce=Object.create;var w=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var ye=(e,t)=>{for(var r in t)w(e,r,{get:t[r],enumerable:!0})},z=(e,t,r,n)=>{if(t&&
2
+ typeof t=="object"||typeof t=="function")for(let o of pe(t))!le.call(e,o)&&o!==r&&
3
+ w(e,o,{get:()=>t[o],enumerable:!(n=me(t,o))||n.enumerable});return e};var fe=(e,t,r)=>(r=e!=null?ce(ue(e)):{},z(t||!e||!e.__esModule?w(r,"default",{value:e,
4
+ enumerable:!0}):r,e)),de=e=>z(w({},"__esModule",{value:!0}),e);var Le={};ye(Le,{FunctionServiceName:()=>i,FunctionServiceType:()=>a,PermissionServiceName:()=>u,
5
+ PermissionServiceType:()=>l,createFunction:()=>Te,createPermission:()=>He,getFunction:()=>ze,
6
+ getFunctionArn:()=>Ne,getFunctionName:()=>I,isFunction:()=>re,isPermission:()=>De,
7
+ registerTriggers:()=>je});module.exports=de(Le);var T=require("@ez4/aws-common");var O=require("@aws-sdk/client-lambda"),N=require("@ez4/aws-identity"),x=require("@ez4/aws-common"),
8
+ p=require("@ez4/utils");var s=require("@aws-sdk/client-lambda"),V=require("@ez4/utils"),c=require("@ez4/aws-common");var D=require("@ez4/aws-common");var i="AWS:Lambda/Function",a="aws:lambda.function";var ge=/[a-z][\w]+/i,Se=e=>ge.test(e),A=e=>{for(let t in e)if(!Se(t))throw new D.InvalidParameterError(
9
+ i,`name ${t} for variable unsupported.`)};var H=fe(require("adm-zip"),1),j=require("node:fs/promises"),U=async(e,t)=>{let r=new H.default,
10
+ n=await(0,j.readFile)(e);return r.addFile(t,n),r.toBufferPromise()};var m=new s.LambdaClient({}),L=async e=>{c.Logger.logCreate(i,e.functionName),e.
11
+ variables&&A(e.variables);let t=await m.send(new s.CreateFunctionCommand({Publish:!0,
12
+ FunctionName:e.functionName,Description:e.description,MemorySize:e.memory,Timeout:e.
13
+ timeout,Role:e.roleArn,Handler:K(e.handlerName),Runtime:"nodejs20.x",PackageType:"\
14
+ Zip",Code:{ZipFile:await M(e.sourceFile)},Environment:{Variables:e.variables},Tags:{
15
+ ...e.tags,ManagedBy:"EZ4"}})),r=t.FunctionName,n=t.FunctionArn;return await E(r),
16
+ {functionName:r,functionArn:n}},$=async(e,t)=>{c.Logger.logTag(i,e),await m.send(
17
+ new s.TagResourceCommand({Resource:e,Tags:{...t,ManagedBy:"EZ4"}}))},Z=async(e,t)=>{
18
+ c.Logger.logUntag(i,e),await m.send(new s.UntagResourceCommand({Resource:e,TagKeys:t}))},
19
+ G=async(e,t)=>{c.Logger.logUpdate(i,`${e} source code`),await m.send(new s.UpdateFunctionCodeCommand(
20
+ {FunctionName:e,ZipFile:await M(t),Publish:!0})),await E(e)},k=async(e,t)=>{c.Logger.
21
+ logUpdate(i,`${e} configuration`),t.variables&&A(t.variables),await m.send(new s.UpdateFunctionConfigurationCommand(
22
+ {FunctionName:e,Description:t.description,MemorySize:t.memory,Timeout:t.timeout,
23
+ Role:t.roleArn,...t.handlerName&&{Handler:K(t.handlerName)},Environment:{Variables:t.
24
+ variables}})),await E(e)},B=async e=>{c.Logger.logDelete(i,e),await m.send(new s.DeleteFunctionCommand(
25
+ {FunctionName:e}))},M=e=>U(e,"main.mjs"),K=e=>`main.${e}`,Fe=async e=>{let t=await m.
26
+ send(new s.GetFunctionConfigurationCommand({FunctionName:e}));return[t.State,t.LastUpdateStatus]},
27
+ E=async e=>{await(0,V.waitFor)(async()=>{let[t,r]=await Fe(e);return t!=="Pendin\
28
+ g"&&r!=="InProgress"})};var W=()=>({equals:Pe,replace:we,create:J,update:xe,delete:Re}),Pe=(e,t)=>!!e.result&&
29
+ e.result.functionArn===t.result?.functionArn,we=async(e,t,r)=>{if(t.result)throw new x.ReplaceResourceError(
30
+ i,e.entryId,t.entryId);return J(e,r)},J=async(e,t)=>{let r=e.parameters,n=r.functionName,
31
+ o=(0,N.getRoleArn)(i,n,t),y=r.sourceFile,C=await(0,p.hashFile)(y),P,S=await(0,p.waitFor)(
32
+ async()=>{try{return await L({...r,sourceFile:y,roleArn:o})}catch(F){if(!(F instanceof
33
+ O.InvalidParameterValueException))throw F;return P=F,null}});if(!S)throw P;return{
34
+ functionName:S.functionName,functionArn:S.functionArn,sourceHash:C,roleArn:o}},xe=async(e,t,r)=>{
35
+ let n=e.result;if(!n)return;let o=e.parameters.functionName,y=(0,N.getRoleArn)(i,
36
+ o,r),C=t.result?.roleArn??y,P={...e.parameters,roleArn:y},S={...t.parameters,roleArn:C};
37
+ await Promise.all([Ce(o,P,S),Ae(n.functionArn,e.parameters,t.parameters)]);let F=await Ee(
38
+ o,e.parameters,t.result);return{...n,sourceHash:F,roleArn:y}},Re=async e=>{let t=e.
39
+ result;t&&await B(t.functionName)},Ce=async(e,t,r)=>{!(0,p.deepEqual)(t,r,{sourceFile:!0,
40
+ functionName:!0,tags:!0})&&await k(e,t)},Ae=async(e,t,r)=>{await(0,x.applyTagUpdates)(
41
+ t.tags,r.tags,n=>$(e,n),n=>Z(e,n))},Ee=async(e,t,r)=>{let n=t.sourceFile,o=await(0,p.hashFile)(
42
+ n);return o!==r?.sourceHash&&await G(e,n),o};var _=require("@ez4/aws-common");var b=require("@ez4/aws-common");var I=(e,t,r)=>{let n=r.getDependencies(a).at(0)?.result;if(!n?.functionName)throw new b.IncompleteResourceError(
43
+ e,t,"functionName");return n.functionName},Ne=(e,t,r)=>{let n=r.getDependencies(
44
+ a).at(0)?.result;if(!n?.functionArn)throw new b.IncompleteResourceError(e,t,"fun\
45
+ ctionArn");return n.functionArn};var f=require("@aws-sdk/client-lambda"),v=require("@ez4/aws-common");var u="AWS:Lambda/Permission",l="aws:lambda.permission";var Q=new f.LambdaClient({}),X=async e=>{v.Logger.logCreate(u,e.functionName);let t=e.
46
+ statementId??`SID${Date.now()}`;return await Q.send(new f.AddPermissionCommand({
47
+ StatementId:t,FunctionName:e.functionName,SourceArn:e.sourceArn,Principal:e.principal,
48
+ Action:e.action})),{statementId:t}},Y=async(e,t)=>{v.Logger.logDelete(u,e),await Q.
49
+ send(new f.RemovePermissionCommand({FunctionName:e,StatementId:t}))};var q=()=>({equals:be,replace:Ie,create:ee,update:ve,delete:he}),be=(e,t)=>!!e.result&&
50
+ e.result.functionName===t.result?.functionName,Ie=async(e,t,r)=>{if(t.result)throw new _.ReplaceResourceError(
51
+ u,e.entryId,t.entryId);return ee(e,r)},ee=async(e,t)=>{let r=I(u,"permission",t),
52
+ n=await e.parameters(t);return{statementId:(await X({functionName:r,principal:n.
53
+ principal,sourceArn:n.sourceArn,action:"lambda:InvokeFunction"})).statementId,functionName:r}},
54
+ ve=async()=>{},he=async e=>{let t=e.result;t&&await Y(t.functionName,t.statementId)};var d=require("@ez4/utils"),te=require("@ez4/stateful");var re=e=>e.type===a,Te=(e,t,r)=>{let n=(0,d.toKebabCase)(r.functionName),o=(0,d.hashData)(
55
+ a,t.entryId,n);return(0,te.attachEntry)(e,{type:a,entryId:o,dependencies:[t.entryId],
56
+ parameters:{...r,functionName:n}})},ze=(e,t,r)=>{let n=(0,d.hashData)((0,d.toKebabCase)(
57
+ r)),o=e[t.entryId,n];return o&&re(o)?o:null};var ne=require("@ez4/utils"),oe=require("@ez4/stateful");var De=e=>e.type===l,He=(e,t,r,n)=>{let o=(0,ne.hashData)(l,t.entryId,r.entryId);
58
+ return(0,oe.attachEntry)(e,{type:l,entryId:o,dependencies:[t.entryId,r.entryId],
59
+ parameters:n})};var ie=require("@ez4/aws-common"),R=require("@ez4/aws-identity"),ae=require("@ez4/project");var g=require("@ez4/aws-identity"),se=async e=>{let[t,r]=await Promise.all([(0,g.getRegion)(),
60
+ (0,g.getAccountId)()]);return(0,g.createPolicyDocument)([{permissions:["logs:Cre\
61
+ ateLogGroup","logs:CreateLogStream","logs:PutLogEvents"],resourceIds:[`arn:aws:l\
62
+ ogs:${t}:${r}:log-group:/aws/lambda/${e}-*:*`]}])};var h=!1,je=()=>(h||((0,ie.registerTriggers)(),(0,R.registerTriggers)(),(0,ae.createTrigger)(
63
+ "@ez4/aws-function",{"deploy:prepareIdentityAccount":Ue,"deploy:prepareExecution\
64
+ Policy":Ve}),h=!0),h),Ue=()=>[{account:"lambda.amazonaws.com"}],Ve=async e=>{let{
65
+ state:t,options:r}=e,{resourcePrefix:n,projectName:o}=r;return(0,R.createPolicy)(
66
+ t,{policyName:`${n}-${o}-lambda-policy`,policyDocument:await se(n)})};(0,T.registerProvider)(a,W());(0,T.registerProvider)(l,q());0&&(module.exports={FunctionServiceName,FunctionServiceType,PermissionServiceName,
67
+ PermissionServiceType,createFunction,createPermission,getFunction,getFunctionArn,
68
+ getFunctionName,isFunction,isPermission,registerTriggers});
package/dist/main.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './function/service.js';
2
+ export * from './function/types.js';
3
+ export * from './function/utils.js';
4
+ export * from './permission/service.js';
5
+ export * from './permission/types.js';
6
+ export * from './triggers/register.js';
package/dist/main.mjs ADDED
@@ -0,0 +1,60 @@
1
+ import{registerProvider as B}from"@ez4/aws-common";import{InvalidParameterValueException as se}from"@aws-sdk/client-lambda";import{
2
+ getRoleArn as I}from"@ez4/aws-identity";import{applyTagUpdates as ie,ReplaceResourceError as ae}from"@ez4/aws-common";
3
+ import{deepEqual as ce,hashFile as v,waitFor as me}from"@ez4/utils";import{CreateFunctionCommand as Q,DeleteFunctionCommand as X,GetFunctionConfigurationCommand as Y,
4
+ LambdaClient as _,TagResourceCommand as q,UntagResourceCommand as ee,UpdateFunctionCodeCommand as te,
5
+ UpdateFunctionConfigurationCommand as re}from"@aws-sdk/client-lambda";import{waitFor as ne}from"@ez4/utils";
6
+ import{Logger as m}from"@ez4/aws-common";import{InvalidParameterError as M}from"@ez4/aws-common";var s="AWS:Lambda/Function",i="aws:lambda.function";var K=/[a-z][\w]+/i,O=e=>K.test(e),g=e=>{for(let t in e)if(!O(t))throw new M(s,`\
7
+ name ${t} for variable unsupported.`)};import W from"adm-zip";import{readFile as J}from"node:fs/promises";var P=async(e,t)=>{
8
+ let r=new W,n=await J(e);return r.addFile(t,n),r.toBufferPromise()};var a=new _({}),w=async e=>{m.logCreate(s,e.functionName),e.variables&&g(e.variables);
9
+ let t=await a.send(new Q({Publish:!0,FunctionName:e.functionName,Description:e.description,
10
+ MemorySize:e.memory,Timeout:e.timeout,Role:e.roleArn,Handler:b(e.handlerName),Runtime:"\
11
+ nodejs20.x",PackageType:"Zip",Code:{ZipFile:await N(e.sourceFile)},Environment:{
12
+ Variables:e.variables},Tags:{...e.tags,ManagedBy:"EZ4"}})),r=t.FunctionName,n=t.
13
+ FunctionArn;return await S(r),{functionName:r,functionArn:n}},x=async(e,t)=>{m.logTag(
14
+ s,e),await a.send(new q({Resource:e,Tags:{...t,ManagedBy:"EZ4"}}))},R=async(e,t)=>{
15
+ m.logUntag(s,e),await a.send(new ee({Resource:e,TagKeys:t}))},C=async(e,t)=>{m.logUpdate(
16
+ s,`${e} source code`),await a.send(new te({FunctionName:e,ZipFile:await N(t),Publish:!0})),
17
+ await S(e)},A=async(e,t)=>{m.logUpdate(s,`${e} configuration`),t.variables&&g(t.
18
+ variables),await a.send(new re({FunctionName:e,Description:t.description,MemorySize:t.
19
+ memory,Timeout:t.timeout,Role:t.roleArn,...t.handlerName&&{Handler:b(t.handlerName)},
20
+ Environment:{Variables:t.variables}})),await S(e)},E=async e=>{m.logDelete(s,e),
21
+ await a.send(new X({FunctionName:e}))},N=e=>P(e,"main.mjs"),b=e=>`main.${e}`,oe=async e=>{
22
+ let t=await a.send(new Y({FunctionName:e}));return[t.State,t.LastUpdateStatus]},
23
+ S=async e=>{await ne(async()=>{let[t,r]=await oe(e);return t!=="Pending"&&r!=="I\
24
+ nProgress"})};var h=()=>({equals:pe,replace:ue,create:T,update:le,delete:ye}),pe=(e,t)=>!!e.result&&
25
+ e.result.functionArn===t.result?.functionArn,ue=async(e,t,r)=>{if(t.result)throw new ae(
26
+ s,e.entryId,t.entryId);return T(e,r)},T=async(e,t)=>{let r=e.parameters,n=r.functionName,
27
+ o=I(s,n,t),c=r.sourceFile,d=await v(c),f,l=await me(async()=>{try{return await w(
28
+ {...r,sourceFile:c,roleArn:o})}catch(y){if(!(y instanceof se))throw y;return f=y,
29
+ null}});if(!l)throw f;return{functionName:l.functionName,functionArn:l.functionArn,
30
+ sourceHash:d,roleArn:o}},le=async(e,t,r)=>{let n=e.result;if(!n)return;let o=e.parameters.
31
+ functionName,c=I(s,o,r),d=t.result?.roleArn??c,f={...e.parameters,roleArn:c},l={
32
+ ...t.parameters,roleArn:d};await Promise.all([fe(o,f,l),de(n.functionArn,e.parameters,
33
+ t.parameters)]);let y=await ge(o,e.parameters,t.result);return{...n,sourceHash:y,
34
+ roleArn:c}},ye=async e=>{let t=e.result;t&&await E(t.functionName)},fe=async(e,t,r)=>{
35
+ !ce(t,r,{sourceFile:!0,functionName:!0,tags:!0})&&await A(e,t)},de=async(e,t,r)=>{
36
+ await ie(t.tags,r.tags,n=>x(e,n),n=>R(e,n))},ge=async(e,t,r)=>{let n=t.sourceFile,
37
+ o=await v(n);return o!==r?.sourceHash&&await C(e,n),o};import{ReplaceResourceError as we}from"@ez4/aws-common";import{IncompleteResourceError as z}from"@ez4/aws-common";var D=(e,t,r)=>{let n=r.getDependencies(i).at(0)?.result;if(!n?.functionName)throw new z(
38
+ e,t,"functionName");return n.functionName},at=(e,t,r)=>{let n=r.getDependencies(
39
+ i).at(0)?.result;if(!n?.functionArn)throw new z(e,t,"functionArn");return n.functionArn};import{AddPermissionCommand as Se,LambdaClient as Fe,RemovePermissionCommand as Pe}from"@aws-sdk/client-lambda";
40
+ import{Logger as H}from"@ez4/aws-common";var p="AWS:Lambda/Permission",u="aws:lambda.permission";var j=new Fe({}),U=async e=>{H.logCreate(p,e.functionName);let t=e.statementId??
41
+ `SID${Date.now()}`;return await j.send(new Se({StatementId:t,FunctionName:e.functionName,
42
+ SourceArn:e.sourceArn,Principal:e.principal,Action:e.action})),{statementId:t}},
43
+ V=async(e,t)=>{H.logDelete(p,e),await j.send(new Pe({FunctionName:e,StatementId:t}))};var L=()=>({equals:xe,replace:Re,create:$,update:Ce,delete:Ae}),xe=(e,t)=>!!e.result&&
44
+ e.result.functionName===t.result?.functionName,Re=async(e,t,r)=>{if(t.result)throw new we(
45
+ p,e.entryId,t.entryId);return $(e,r)},$=async(e,t)=>{let r=D(p,"permission",t),n=await e.
46
+ parameters(t);return{statementId:(await U({functionName:r,principal:n.principal,
47
+ sourceArn:n.sourceArn,action:"lambda:InvokeFunction"})).statementId,functionName:r}},
48
+ Ce=async()=>{},Ae=async e=>{let t=e.result;t&&await V(t.functionName,t.statementId)};import{toKebabCase as Z,hashData as G}from"@ez4/utils";import{attachEntry as Ee}from"@ez4/stateful";var Ne=e=>e.type===i,Rt=(e,t,r)=>{let n=Z(r.functionName),o=G(i,t.entryId,n);return Ee(
49
+ e,{type:i,entryId:o,dependencies:[t.entryId],parameters:{...r,functionName:n}})},
50
+ Ct=(e,t,r)=>{let n=G(Z(r)),o=e[t.entryId,n];return o&&Ne(o)?o:null};import{hashData as be}from"@ez4/utils";import{attachEntry as Ie}from"@ez4/stateful";var It=e=>e.type===u,vt=(e,t,r,n)=>{let o=be(u,t.entryId,r.entryId);return Ie(e,
51
+ {type:u,entryId:o,dependencies:[t.entryId,r.entryId],parameters:n})};import{registerTriggers as ze}from"@ez4/aws-common";import{createPolicy as De,registerTriggers as He}from"@ez4/aws-identity";
52
+ import{createTrigger as je}from"@ez4/project";import{getAccountId as ve,getRegion as he,createPolicyDocument as Te}from"@ez4/aws-identity";
53
+ var k=async e=>{let[t,r]=await Promise.all([he(),ve()]);return Te([{permissions:[
54
+ "logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"],resourceIds:[`\
55
+ arn:aws:logs:${t}:${r}:log-group:/aws/lambda/${e}-*:*`]}])};var F=!1,Vt=()=>(F||(ze(),He(),je("@ez4/aws-function",{"deploy:prepareIdentityAc\
56
+ count":Ue,"deploy:prepareExecutionPolicy":Ve}),F=!0),F),Ue=()=>[{account:"lambda\
57
+ .amazonaws.com"}],Ve=async e=>{let{state:t,options:r}=e,{resourcePrefix:n,projectName:o}=r;
58
+ return De(t,{policyName:`${n}-${o}-lambda-policy`,policyDocument:await k(n)})};B(i,h());B(u,L());export{s as FunctionServiceName,i as FunctionServiceType,p as PermissionServiceName,
59
+ u as PermissionServiceType,Rt as createFunction,vt as createPermission,Ct as getFunction,
60
+ at as getFunctionArn,D as getFunctionName,Ne as isFunction,It as isPermission,Vt as registerTriggers};
@@ -0,0 +1,13 @@
1
+ import type { Arn } from '@ez4/aws-common';
2
+ export type CreateRequest = {
3
+ functionName: string;
4
+ statementId?: string;
5
+ sourceArn?: Arn;
6
+ principal: string;
7
+ action: string;
8
+ };
9
+ export type CreateResponse = {
10
+ statementId: string;
11
+ };
12
+ export declare const createPermission: (request: CreateRequest) => Promise<CreateResponse>;
13
+ export declare const deletePermission: (functionName: string, statementId: string) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { StepHandler } from '@ez4/stateful';
2
+ import type { PermissionState } from './types.js';
3
+ export declare const getPermissionHandler: () => StepHandler<PermissionState>;
@@ -0,0 +1,5 @@
1
+ import type { EntryState, EntryStates } from '@ez4/stateful';
2
+ import type { FunctionState } from '../function/types.js';
3
+ import type { PermissionParametersGenerator, PermissionState } from './types.js';
4
+ export declare const isPermission: (resource: EntryState) => resource is PermissionState;
5
+ export declare const createPermission: <E extends EntryState>(state: EntryStates<E>, sourceState: EntryState, functionState: FunctionState, getParameters: PermissionParametersGenerator) => PermissionState;
@@ -0,0 +1,14 @@
1
+ import type { EntryState, StepContext } from '@ez4/stateful';
2
+ import type { CreateRequest, CreateResponse } from './client.js';
3
+ export declare const PermissionServiceName = "AWS:Lambda/Permission";
4
+ export declare const PermissionServiceType = "aws:lambda.permission";
5
+ export type PermissionParameters = Omit<CreateRequest, 'functionName' | 'statementId' | 'action'>;
6
+ export type PermissionResult = CreateResponse & {
7
+ functionName: string;
8
+ };
9
+ export type PermissionParametersGenerator = (context: StepContext) => Promise<PermissionParameters> | PermissionParameters;
10
+ export type PermissionState = EntryState & {
11
+ type: typeof PermissionServiceType;
12
+ parameters: PermissionParametersGenerator;
13
+ result?: PermissionResult;
14
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Register all triggers.
3
+ */
4
+ export declare const registerTriggers: () => true;
@@ -0,0 +1,3 @@
1
+ export type Variables = {
2
+ [name: string]: string;
3
+ };
@@ -0,0 +1,2 @@
1
+ import type { PolicyDocument } from '@ez4/aws-identity';
2
+ export declare const getPolicyDocument: (resourcePrefix: string) => Promise<PolicyDocument>;
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@ez4/aws-function",
3
+ "description": "EZ4: Self-managed AWS lambda functions",
4
+ "version": "0.0.0",
5
+ "author": "Silas B.",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/main.d.ts",
11
+ "require": "./dist/main.cjs",
12
+ "import": "./dist/main.mjs"
13
+ }
14
+ },
15
+ "workspaces": [
16
+ "packages/*"
17
+ ],
18
+ "scripts": {
19
+ "clean": "rm -f *.tsbuildinfo && rm -rf dist/*",
20
+ "build": "tsc -p tsconfig.json && node tools/bundler.mjs",
21
+ "test": "npm run test:types && node --env-file ../../local.env --test --import ../../tools/tsnode.mjs test/*.spec.ts",
22
+ "test:only": "npm run test:types && node --env-file ../../local.env --test-only --test --import ../../tools/tsnode.mjs test/*.spec.ts",
23
+ "test:types": "npm run build && tsc -p tsconfig.test.json",
24
+ "local:publish": "npm run build && npm run clean:registry && npm publish --registry http://localhost:4873",
25
+ "clean:registry": "rm -rf ../../.registry/@ez4/aws-function",
26
+ "prepublishOnly": "npm run clean && npm run build && npm run test",
27
+ "publish": "npm publish --access public"
28
+ },
29
+ "dependencies": {
30
+ "@aws-sdk/client-lambda": "^3.614.0",
31
+ "@ez4/aws-common": "^0.0.0",
32
+ "@ez4/aws-identity": "^0.0.0",
33
+ "@ez4/project": "^0.0.0",
34
+ "@ez4/stateful": "^0.0.0",
35
+ "@ez4/utils": "^0.0.0",
36
+ "@types/adm-zip": "^0.5.5",
37
+ "adm-zip": "^0.5.14"
38
+ }
39
+ }