Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

serverless-lambda-edge-pre-existing-cloudfront

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serverless-lambda-edge-pre-existing-cloudfront - npm Package Compare versions

Comparing version 1.1.4 to 1.1.5

75

index.js

@@ -29,23 +29,8 @@ 'use strict'

const event = events[idx]
if (event.preExistingCloudFront.stage !== undefined &&
event.preExistingCloudFront.stage != `${serverless.service.provider.stage}`) { continue }
const functionArn = await this.getlatestVersionLambdaArn(functionObj.name)
const config = await this.provider.request('CloudFront', 'getDistribution', {
Id: event.preExistingCloudFront.distributionId
})
if (event.preExistingCloudFront.pathPattern === '*') {
config.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations = await this.associateFunction(
config.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations,
event,
functionObj.name,
functionArn
)
} else {
config.DistributionConfig.CacheBehaviors = await this.associateNonDefaultCacheBehaviors(
config.DistributionConfig.CacheBehaviors,
event,
functionObj.name,
functionArn
)
}
this.serverless.cli.consoleLog(

@@ -55,7 +40,46 @@ `${functionArn} is associating to ${event.preExistingCloudFront.distributionId} CloudFront Distribution. waiting for deployed status.`

await this.provider.request('CloudFront', 'updateDistribution', {
Id: event.preExistingCloudFront.distributionId,
IfMatch: config.ETag,
DistributionConfig: config.DistributionConfig
})
let retryCount = 5
const updateDistribution = async () => {
const config = await this.provider.request('CloudFront', 'getDistribution', {
Id: event.preExistingCloudFront.distributionId
})
if (event.preExistingCloudFront.pathPattern === '*') {
config.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations = await this.associateFunction(
config.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations,
event,
functionObj.name,
functionArn
)
} else {
config.DistributionConfig.CacheBehaviors = await this.associateNonDefaultCacheBehaviors(
config.DistributionConfig.CacheBehaviors,
event,
functionObj.name,
functionArn
)
}
await this.provider
.request('CloudFront', 'updateDistribution', {
Id: event.preExistingCloudFront.distributionId,
IfMatch: config.ETag,
DistributionConfig: config.DistributionConfig
})
.catch(async (error) => {
if (error.providerError.code === 'PreconditionFailed' && retryCount > 0) {
this.serverless.cli.consoleLog(
`received precondition failed error, retrying... (${retryCount}/5)`
)
retryCount -= 1
await new Promise((res) => setTimeout(res, 5000))
return updateDistribution()
}
this.serverless.cli.consoleLog(error)
throw error
})
}
await updateDistribution()
}

@@ -90,3 +114,4 @@ })

pathPattern: { type: 'string' },
includeBody: { type: 'boolean' }
includeBody: { type: 'boolean' },
stage: { type: 'string' }
},

@@ -93,0 +118,0 @@ required: ['distributionId', 'eventType', 'pathPattern', 'includeBody']

{
"name": "serverless-lambda-edge-pre-existing-cloudfront",
"version": "1.1.4",
"version": "1.1.5",
"description": "The Serverless Framework plugin which creates Lambda@Edge against pre-existing CloudFront.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -22,2 +22,3 @@ # Serverless Lambda Edge PreExisting CloudFront

- preExistingCloudFront:
# ---- Mandatory Properties -----
distributionId: xxxxxxx # CloudFront distribution ID you want to associate

@@ -27,2 +28,4 @@ eventType: viewer-request # Choose event to trigger your Lambda function, which are `viewer-request`, `origin-request`, `origin-response` or `viewer-response`

includeBody: false # Whether including body or not within request
# ---- Optional Property -----
stage: dev # Specify the stage at which you want this CloudFront distribution to be updated

@@ -46,2 +49,9 @@ plugins:

- production
```
```
### How `validStages` and `stage` properties work
This plugin will first check for `validStages` property defined in the `custom` section. If `validStages` is used, then all the `preExistingCloudFront` events are only possible to be updated at the `validStages`. If not used, all the `preExistingCloudFront` events are possible to be updated at any stage.
Then at all valid stages, the plugin checks - for each `preExistingCloudFront` event - if the provider's stage is the same as the `stage` property defined for each `preExistingCloudFront` event. If they match, then that particular `preExistingCloudFront` event will be updated.
If `stage` is not used for a `preExistingCloudFront` event, then that event will be updated at all `validStages` or all stages if `validStages` is not used.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc