Skip to content

Commit

Permalink
Merge pull request #1308 from jormaechea/Lambda-integration-authorizer
Browse files Browse the repository at this point in the history
Add support for the AUTHORIZER env variable for LambdaIntegration
  • Loading branch information
dherault committed Apr 13, 2022
2 parents c97e2a6 + 059e061 commit 050fcb5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/events/http/lambda-events/LambdaIntegrationEvent.js
@@ -1,6 +1,8 @@
import renderVelocityTemplateObject from './renderVelocityTemplateObject.js'
import VelocityContext from './VelocityContext.js'

const { parse } = JSON

export default class LambdaIntegrationEvent {
#path = null
#request = null
Expand All @@ -16,6 +18,30 @@ export default class LambdaIntegrationEvent {
}

create() {
if (process.env.AUTHORIZER) {
try {
const authorizerContext = parse(process.env.AUTHORIZER)
if (authorizerContext) {
this.#request.auth = {
...this.#request.auth,
credentials: {
authorizer: authorizerContext,
},
}
}
} catch (error) {
if (this.log) {
this.log.error(
'Could not parse process.env.AUTHORIZER, make sure it is correct JSON',
)
} else {
console.error(
'Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.',
)
}
}
}

const velocityContext = new VelocityContext(
this.#request,
this.#stage,
Expand Down

0 comments on commit 050fcb5

Please sign in to comment.