serverless-framework

custom authorizers in Amazon API Gateway 500 error

别等时光非礼了梦想. 提交于 2019-12-30 09:27:46
问题 I use Serverless-Authentication-boilerplate and want to map custom error response. But it always return 500 error. authorize.js // Authorize function authorize(event, callback) { let providerConfig = config(event); try { let data = utils.readToken(event.authorizationToken, providerConfig.token_secret); console.log("Decrypted data: " + JSON.stringify(data)); let methodArn = event.methodArn.replace(/(GET|POST|PUT|DELETE)/g, '*').replace(/mgnt.+/g, 'mgnt/*'); console.log(`Change methodArn to: $

Request validation using serverless framework

巧了我就是萌 提交于 2019-12-30 04:29:08
问题 I am using serverless framework for the backend. How can I implement request validation? (do not want to write validation inside lambda functions). 回答1: To implement request validation using serverless you need to do a couple of things: Include your model/header definitions in your stack, and then tell API gateway to use them for request validation. You'll need to install the following packages: serverless-aws-documentation serverless-reqvalidator-plugin And then you'll need to include them

How to test aws lambda functions locally

房东的猫 提交于 2019-12-29 06:36:45
问题 I have a mobile application backend developed with node.js express. I tried it to deploy it as lambda service. For that I created a Serverless Framework project (https://github.com/serverless). Previously I tested mobile app locally by starting express backend application. Now I can't find a method to test my mobile app locally without local backend. jaws run command only run once I called it. Is there any method to start the lambda function as a web service? Or is there any alternative to

Can't debug serverless app in Visual Studio Code

守給你的承諾、 提交于 2019-12-24 12:19:33
问题 I'm trying to find out how can I use Visual Studio Code debugger to debug serverless lambda function. For testing purposes I have very simple test lambda function: module.exports.handler = async (event) => { debugger; console.log(111, event); }; Then, in launch.json I created such a configuration: { "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch via NPM", "runtimeVersion": "8.4.0", "runtimeExecutable": "node", "program": "${workspaceFolder}/node

Serverless Framework with custom packaging

本小妞迷上赌 提交于 2019-12-24 08:23:20
问题 I'm using the Serverless Framework and I can't seem to package my functions the way I want. My current folder directory looks like this: service/ serverless.yml function1/ package.json handler.js node_modules/ ... function2/ handler.py requirements.txt venv/ ... Is it possible to cherry pick which folder I want to include in the zip file and also specify the corresponding destination path inside the zip file? For example, I want to zip everything inside function1 folder but all of them should

s3.upload() works but uploads broken image

为君一笑 提交于 2019-12-24 04:43:05
问题 I've got a Lambda function in AWS that is hooked up to a POST method which basically takes an image URL and uploads the image to an S3 bucket. My Lambda function looks like this: var s3 = new AWS.S3(); exports.handler = (event, context, callback) => { let encodedImage = JSON.parse(event.body).user_avatar; let decodedImage = Buffer.from(encodedImage, 'base64'); var filePath = "avatars/" + event.queryStringParameters.username + ".jpg" var params = { "Body": decodedImage, "Bucket": "MYBUCKETNAME

Serverless Cron Job firing twice

人盡茶涼 提交于 2019-12-24 00:46:21
问题 I am not sure why but my webhook is being fired twice in my cron job. So this cron job is suppose to run once every 15 min which it does, but it is firing off twice. I will post the logs, handler and yml file to help out. Basically my cron job will make some request to a salsify api to store a url inside a mongodb. Once that file has been completed and built the next time the cron job runs it should trigger the webhook for netlify. Then the process starts all over again. In my netlify I

How to access dataset of an identity in cognito federated identities from lambda

旧街凉风 提交于 2019-12-23 18:19:53
问题 Let me start with the overall description of what I'm trying to achieve. I'm building a serverless API using Lambda, Cognito (Federated Identities), API Gateway etc. I'm using aws_iam as the authorizer in API Gateway. In some endpoints, I need to access for example user e-mail or username or whatever so I can send it back in the response (also data of users who did not make the request). I guess I'm looking for some kind of "admin" access to the identity pool so I can retrieve data based on

How to create multiple stages in serverless framwork

橙三吉。 提交于 2019-12-23 16:43:08
问题 i'm trying yo create multiple stages in serverless with no success. Here is my serverless.yml : service: some-cache-updater provider: name: aws runtime: nodejs8.10 stage: dev functions: scheduledUpdater: handler: handler.scheduledUpdater timeout: 120 What i wish to add is a prod stage with a different timeout. Can i do it in the same yml? Any way an example or a reference will be helpful... thanks. 回答1: Use Serverless' $self reference interpolation which can include further interpolation.

Serverless Framework Dynamo DB Table Resource Definition with Sort Key

孤者浪人 提交于 2019-12-23 09:37:27
问题 I have some code in my serverless.yml like this currently. resources: Resources: uploadBucket: Type: AWS::S3::Bucket Properties: BucketName: ${self:service}-${self:custom.stage}-uploads visitsTable: Type: AWS::DynamoDB::Table Properties: TableName: ${self:custom.visitsTable} AttributeDefinitions: - AttributeName: userId AttributeType: S - AttributeName: visitId AttributeType: S - AttributeName: comments AttributeType: S - AttributeName: attachments AttributeType: S - AttributeName: ph