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 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);
@rcoundon Thanks ross. It's working now . But I'm able to do a post request using a curl command. But when I'm testing the API with fetch I'm getting cors error(CORS Missing Allow origin). But I haven't enabled cors while deploying in Aws Api gateway and in aws lamba also?
Hi - you can specify cors on the http event:
events:
- http:
path: somepath
method: post
cors: true
But you also need to return the necessary CORS headers from your lambda function.
For example, you could define a function to add the necessary headers to your returned objects something like
export function addCorsHeaders(response: APIGatewayProxyResult): APIGatewayProxyResult {
if (!response.headers) {
response.headers = {};
}
response.headers['Access-Control-Allow-Headers'] = 'Content-Type';
response.headers['Access-Control-Allow-Origin'] = '*';
response.headers['Access-Control-Allow-Methods'] = 'OPTIONS,POST,GET,PATCH,PUT,DELETE';
return response;
}
Then you'd use it like:
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'some data',
}),
};
return addCorsHeaders(response);
Ive been looking into ways to bundle a serverless node application. I see serverless-webpack has the option for
includeModules
but is there a reason that you wouldn't just want webpack to bundle/treeshake everything for you and just output a single file?
includeModules just gives you some options around including/excluding certain packages. For example, you might use something that is OS specific like sharp for local testing but not want this bundled in the package, so you can then use includeModules/forceExclude with sharp. Also, if you wanted to be specific about what to include you can use forceInclude, maybe you might want to do that with aws-sdk rather than use the version that lambda containers automatically include
Hello, can someone please advise if the following makes sense?
functions:
myCloudWatch:
handler: myCloudWatch.handler
events:
- cloudwatchEvent:
event:
arn: "arn:aws:events:us-east-1:123456789012:rule/MyScheduledRule"
source:
- 'aws.events'
detail-type:
- 'Scheduled Event'
Generally I want to grant the λ function with a permission to be invoked by some scheduled rules, which are dynamic and therefore cannot be defined in the configuration yaml.
Thanks