Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ class UpdateLambdaFunctionAssociationPlugin {
}))
}

async getLatestFunction(functionName) {
async getLatestFunction(functionName, previousFunction = { Version: "0" }, previousMarker = "") {
const functions = await this.provider.request('Lambda', 'listVersionsByFunction', {
FunctionName: functionName
FunctionName: functionName,
...(previousMarker.length ? { Marker: previousMarker } : {}),
})
const initialData = {Version: '0'}
const latestFunction = functions['Versions'].reduce((prev, current) => {

const nextMarker = functions['NextMarker'];
const latestFunction = functions['Versions'].reduce((prev,current) => {
const prevVersion = parseInt(prev['Version'])
const currentVersion = parseInt(current['Version'])
if (Number.isNaN(currentVersion)) {
Expand All @@ -70,10 +72,17 @@ class UpdateLambdaFunctionAssociationPlugin {
return prev
}
return current
}, initialData)
if (latestFunction['Version'] === initialData['Version']) {
}, previousFunction)

const parseVersion = parseInt(latestFunction['Version']);
if (!parseVersion || parseVersion === 0) {
throw new this.serverless.classes.Error("LambdaEdge: Couldn't get latest lambda function")
}

if (nextMarker && nextMarker.length) {
return this.getLatestFunction(functionName,latestFunction,nextMarker)
}

return latestFunction
}

Expand Down