For support requests please search or create posts on Serverless Forum: https://forum.serverless.com
carlosandrebp on master
upload email icon (compare)
carlosandrebp on master
Icons update (compare)
carlosandrebp on master
updates animations (compare)
andrepiresbp on master
Updates (compare)
andrepiresbp on master
Update (compare)
Hi,
I have a graphql API with authorizer configured. This works fine offline but when deployed to AWS, Authorizer is getting triggered but not getting redirected back to Service. I am getting the below response. (In AWS, i have given Admin access too). Please let me know if i am missed anything.
Response - 500
{
"message": null
}
Serverless.yml
functions:
authorize:
handler: handlers/authHandler.authenticate
graphql:
handler: handlers/graphqlHandler.handler
events:
- http:
path: graphql
method: post
cors: true
authorizer: authorize
Auth Handler
module.exports.authenticate = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
const token = event.authorizationToken;
try {
// Verify JWT
const decoded = jwt.verify(token, process.env.JWT_SECRET);
const user = decoded.user;
const effect = "Allow";
const userId = user.username || user.email;
const authorizerContext = { user: JSON.stringify(user) };
// Return an IAM policy document for the current endpoint
const policyDocument = utils.buildIAMPolicy(
userId,
effect,
event.methodArn,
authorizerContext
);
callback(null, policyDocument);
} catch (e) {
callback("Unauthorized"); // Return a 401 Unauthorized response
}
};
Hi all,
I’ve an issue with the settings in the serverless dashboard. I recently joined an organisation which had 4 existing apps, all of them have 2 stages and some have extra parameters. I’ve added a 5th app and wanted to add a few parameters. But when I open the ‘settings’ of any app, the stages section is empty (it only shows the ‘default’ stage), and when I click on the default stage, it always shows the parameters that belong to one specific app, regardless of which app I’m currently watching. And when I add a new parameter, it will show up in the settings of all apps. So to me it seems like there’s an issue with the dashboard interface itself.
Anyone who has the same issue? And / or a solution? Thanks!
sls invoke local --config serverless-project.yml -f myFunction
, the result is this:
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.HashMap
at com.serverless.InvokeBridge.getContext(InvokeBridge.java:54)
at com.serverless.InvokeBridge.<init>(InvokeBridge.java:38)
at com.serverless.InvokeBridge.main(InvokeBridge.java:137)
lib/plugins/aws/invokeLocal/index.js:invokeLocalJava
the customContext
variable is set to the name of the config file. When the string is passed to the InvokeBridge it cannot be case to a hash map
@rcoundon They should still be available as variables using ${} syntax.
They can be referenced inside the configuration using the likes of
stage: '${opt:stage, self:provider.stage}',
But what I'd like to do is to reference them outside of the configuration e.g.
import type { AWS } from '@serverless/typescript';
console.log('${opt:stage, self:provider.stage}');
const serverlessConfiguration: AWS = {
...
provider: {
name: 'aws',
stage: 'dev',
stackTags: {
stage: '${opt:stage, self:provider.stage}',
}
}
const serverless = require('serverless'); // Haven't worked out why I can't use import here yet
const sls = new serverless();
console.log(sls.service.provider.stage); // prints 'dev'
So, looking through source code of serverless led me to the processedInput variable.
Doing this
const serverless = require('serverless');
const sls = new serverless();
sls.init();
console.log(JSON.stringify(sls.processedInput, null, 2));
Produces
{
"commands": [
"offline",
"start"
],
"options": {
"stage": "production"
}
}
processedInput isn't marked as private so I guess this is 'safe'...
Hey! Is there a way to keep deletionPolicy on an s3 bucket and dynamodb table and use the same buckets / s3 from old deployments on new stacks?
I want to use the same serverless.yml to deploy new stacks and redeploy stack using the previously retained s3 buckets / dynamodb tables.
I've set up the:
DeletionPolicy: Retain
but currently getting
An error occurred: xxxx - xx-xx-xx-xx already exists.
on redeployments
const serverless = require('serverless-http');
const express = require("express");
const qs = require("qs");
const bodyParser = require("body-parser");
const axios = require("axios");
const app = express();
//app.use(
//cors({
//origin: "https://xxx",
//})
//);
//
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(bodyParser.text());
app.use(bodyParser.raw());
// let corsOptions = {
// origin: "https://xxx",
// // allowedHeaders: [
// // "Content-Type",
// // "Authorization",
// // "Content-Length",
// // "X-Requested-With",
// // "Accept",
// // ],
// methods: ["GET", "PUT", "POST", "DELETE", "OPTIONS"],
// optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
// };
// // app.use(cors(corsOptions));
// const corsm = (req, res, next) => {
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Methods", "GET, POST");
// res.header(
// "Access-Control-Allow-Headers",
// "Origin, X-Requested-With, Content-Type, Accept, Authorization"
// );
// next();
// };
// app.use(function (req, res, next) {
// res.setHeader(
// "Access-Control-Allow-Origin",
// "xxx"
// ); // update to match the domain you will make the request from
// res.setHeader(
// "Access-Control-Allow-Headers",
// "Origin, X-Requested-With, Content-Type, Accept"
// );
// next();
// });
// app.options(function (req, res, next) {
// res.setHeader(
// "Access-Control-Allow-Origin",
// "xxxx"
// ); // update to match the domain you will make the request from
// res.setHeader(
// "Access-Control-Allow-Headers",
// "Origin, X-Requested-With, Content-Type, Accept"
// );
// next();
// });
app.post("/punctuate", async (req, res) => {
console.log("called");
let { text } = req.body;
text = text.replace(/\b((Applause)|(Laughter)|(thank you))\b/g, match => "");
text = text.replace(/[()|`|-|``|'']/g, "");
text = text.replace(/\s+/g, " ").trim();
try {
const data = await axios({
method: "post",
url: "https://xxxx",
data: qs.stringify({ text }),
headers: {
"content-type": "application/x-www-form-urlencoded;charset=utf-8",
"Access-Control-Allow-Origin": "*",
},
});
res.status(200).json({ text: JSON.stringify(data.data) });
} catch (error) {
console.log(error.response);
res.json({ text: "" });
}
});
app.post("/summary", async (req, res) => {
let talk = req.body;
const result = await axios({
url: "https://xxxx",
method: "post",
headers: {
"Content-Type": "text/plain",
},
data: talk,
});
res.status(200).send(result.data.summary);
});
// app.listen(8080, () => {
// console.log("server started 🚀,port 8080");
// });
module.exports.handler = serverless(app);