import AWS from 'aws-sdk' ; import { AwsLambdaApi } from './AWSLambdaApi' ; import { LambdaData } from '../types' ; async function generateCredentials ( backendUrl , options ) { const respData = await fetch ( `${ backendUrl }/api/aws/credentials` , { headers : { ... ( options == null ? void 0 : options . token ) && { Authorization : `Bearer ${ options == null ? void 0 : options . token }` } } } ) ; try { const resp = await respData . json ( ) ; return new AWS . Credentials ( { accessKeyId : resp . AccessKeyId , secretAccessKey : resp . SecretAccessKey , sessionToken : resp . SessionToken , } ) ; } catch ( e ) { throw new Error ( 'MissingBackendAwsAuthException' ) ; } } export class AwsLambdaClient implements AwsLambdaApi { async getFunctionByName ( { awsRegion , backendUrl , functionName , token } ) { AWS . config . region = awsRegion ; AWS . config . credentials = await generateCredentials ( backendUrl , { token } ) ; const lambdaApi = new AWS . Lambda ( { } ) ; const resp = await lambdaApi . getFunction ( { FunctionName : functionName , } ) . promise ( ) ; const v = resp . Configuration ! ; return { codeSize : v . CodeSize ! , description : v . Description ! , functionName : v . FunctionName ! , lastModifiedDate : v . LastModified ! , runtime : v . Runtime ! , memory : v . MemorySize ! , region : awsRegion , state : v . State ! , lastUpdateStatus : v . LastUpdateStatus ! , lastUpdateStatusReason : v . LastUpdateStatusReason ! , } ; } }