@serverless/aws-lambda-layer
Advanced tools
{ | ||
"name": "@serverless/aws-lambda-layer", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"main": "./serverless.js", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -6,6 +6,5 @@ const aws = require('aws-sdk') | ||
const outputMask = ['name', 'description', 'arn'] | ||
const outputsList = ['name', 'description', 'arn', 'region'] | ||
const defaults = { | ||
name: 'serverless', | ||
description: 'Serverless Layer', | ||
@@ -24,2 +23,4 @@ code: process.cwd(), | ||
config.name = this.state.name || this.context.resourceId() | ||
const lambda = new aws.Lambda({ | ||
@@ -30,2 +31,7 @@ region: config.region, | ||
this.context.debug( | ||
`Starting deployment of layer ${config.name} to the ${config.region} region.` | ||
) | ||
// todo we should probably remove this now that we are auto generating names | ||
if (this.state.name && this.state.name !== config.name) { | ||
@@ -40,2 +46,3 @@ this.context.status('Replacing') | ||
this.context.status('Packaging') | ||
this.context.debug(`Packaging directory ${config.code} for layer ${config.name}.`) | ||
@@ -45,2 +52,3 @@ config.zipPath = await pack(config.code, config.prefix, config.include) | ||
this.context.debug(`Checking if layer ${config.name} already exists.`) | ||
const prevLayer = await getLayer(lambda, config.arn) | ||
@@ -57,2 +65,4 @@ | ||
this.context.status('Uploading') | ||
this.context.debug(`Uploading layer package ${config.zipPath} to ${config.bucket}.`) | ||
const bucket = await this.load('@serverless/aws-s3') | ||
@@ -62,5 +72,12 @@ await bucket.upload({ name: config.bucket, file: config.zipPath }) | ||
this.context.status('Publishing') | ||
this.context.debug(`Publishing layer ${config.name} to the ${config.region} region.`) | ||
config.arn = await publishLayer({ lambda, ...config }) | ||
} | ||
this.context.debug( | ||
`Successfully published layer ${config.name} to the ${config.region} region.` | ||
) | ||
this.context.debug(`Published layer ARN is ${config.arn}.`) | ||
this.state.name = config.name | ||
@@ -72,9 +89,4 @@ this.state.arn = config.arn | ||
const outputs = pick(outputMask, config) | ||
const outputs = pick(outputsList, config) | ||
this.context.log() | ||
this.context.output('name', ` ${outputs.name}`) | ||
this.context.output('description', `${outputs.description}`) | ||
this.context.output('arn', ` ${outputs.arn}`) | ||
return outputs | ||
@@ -84,24 +96,29 @@ } | ||
// todo remove all versions? | ||
async remove(inputs = {}) { | ||
if (!inputs.arn && !this.state.arn) { | ||
this.state = {} | ||
async remove() { | ||
this.context.status('Removing') | ||
await this.save() | ||
if (!this.state.arn) { | ||
this.context.debug(`Aborting removal. Layer ARN not found in state.`) | ||
return | ||
} | ||
this.context.status('Removing') | ||
const lambda = new aws.Lambda({ | ||
region: inputs.region || defaults.region, | ||
region: this.state.region, | ||
credentials: this.context.credentials.aws | ||
}) | ||
const arn = inputs.arn || this.state.arn | ||
await deleteLayer(lambda, arn) | ||
this.context.debug(`Removing layer ${this.state.name} from the ${this.state.region} region.`) | ||
await deleteLayer(lambda, this.state.arn) | ||
this.context.debug( | ||
`Successfully removed layer with arn ${this.state.arn} from the ${this.state.region} region.` | ||
) | ||
const outputs = pick(outputsList, this.state) | ||
this.state = {} | ||
await this.save() | ||
return { arn } | ||
return outputs | ||
} | ||
@@ -108,0 +125,0 @@ } |
27287
3.06%304
3.75%