我尝试从 Azure PowerShell函数提供 HTML 页面。我能够返回 HTML,但我知道在哪里可以将内容类型设置为 text/htm l 以便浏览器解释 HTML。
以下是Anythony Chu 提供的示例,说明如何使用 C# 实现此目的:
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log)
{
var response = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(@"d:\home\site\wwwroot\ShoppingList\index.html", FileMode.Open);
response.Content = new StreamContent(stream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
return response;
}
Run Code Online (Sandbox Code Playgroud)
但在 PowerShell 函数中,我只是使用 cmdlet 返回文件Out-File,并且没有设置内容类型的选项。这是一个你好世界的例子:
# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$name = $requestBody.name
# GET method: each querystring parameter is its own variable …Run Code Online (Sandbox Code Playgroud) 我对无服务器还很陌生,我正在尝试从无服务器 yaml 文件为 Cognito 设置自定义挑战。我有以下功能
functions:
t-challenge-define:
handler: t-auth-challenge.define
t-challenge-create:
handler: t-auth-challenge.create
t-challenge-response:
handler: t-auth-challenge.verifyResponse
resources:
Resources:
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: my_user_pool_name
MfaConfiguration: "OFF"
UsernameAttributes:
- phone_number
Schema:
- Name: phone_number
AttributeDataType: String
Mutable: false
Required: true
- Name: locale
AttributeDataType: String
Mutable: true
Required: true
LambdaConfig:
DefineAuthChallenge: (how do i reference func here)
我正在使用无服务器框架来使用来自 SQS 的消息。发送到队列的一些消息不会被消耗。他们直接进入飞行中的 SQS 状态,然后从那里进入我的死信队列。当我查看消费者日志时,我可以看到它消费并成功处理了 9/10 消息。一个总是不会被消耗并最终进入死信队列。我设置reservedConcurrency为 1,以便一次只有一个消费者可以运行。函数消费者timeout设置为 30 秒。这是消费者代码:
module.exports.mySQSConsumer = async (event, context) => {
context.callbackWaitsForEmptyEventLoop = false;
console.log(event.Records);
await new Promise((res, rej) => {
setTimeout(() => {
res();
}, 100);
});
console.log('DONE');
return true;
}
Run Code Online (Sandbox Code Playgroud)
消费者功能配置如下:
functions:
mySQSConsumer:
handler: handler.mySQSConsumer
timeout: 30 # seconds
reservedConcurrency: 1
events:
- sqs:
arn: arn:aws:sqs:us-east-1:xyz:my-test-queue
batchSize: 1
enabled: true
Run Code Online (Sandbox Code Playgroud)
如果我删除该await功能,它将处理所有消息。如果我将超时增加到 200 毫秒,更多的消息将直接进入运行中状态,并从那里进入死信队列。这段代码非常简单。知道为什么它会跳过一些消息吗?使用第一条语句时,未使用的消息甚至不会显示在日志中console.log()。他们似乎完全被忽视了。
我在 React 应用程序中使用基于 AWS 的无服务器架构以及 AppSync、Cognito 和 GraphQL。过去,我能够在本地更新我的 graphql 架构并运行amplify api push,它成功地将我的所有更改推送到云。
amplify api push最近我一直在尝试通过我在通行证中更新云,并且终端显示“所有资源都在云中更新”。但是,它将我的架构恢复为上次推送时的架构版本。不用说,它也没有在云端更新。
终端中没有显示任何错误消息。
我想要做的改变如下:
前-
type Topic @model {
id: ID!
postID: ID!
name: String!
}
Run Code Online (Sandbox Code Playgroud)
后-
type Topic @model {
id: ID!
name: String!
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都感激不尽
我们最近尝试了 Azure 功能的高级计划,我们注意到有很多“管理/预热”请求。我的猜测是,这是让职能人员存活的高级计划的一部分,但我找不到任何相关文档。有人知道情况是否如此吗?
我有一个无服务器项目,已成功部署到 AWS,其中包含多个 Lambda 函数和一个带有 API 网关事件的 Step Function 状态机。我手动删除了 AWS 中的 Step Function,现在sls deploy不部署 Step Function。
如何让事情恢复同步?
谢谢!
编写 lambda 函数来执行一些数据库查询,然后向某些用户组发送电子邮件。
会员收到该电子邮件两次。
该应用程序是一款音乐流媒体应用程序,用户可以在其中创建歌曲。他们还可以创建群组、邀请成员加入这些群组并向这些群组分享他们的歌曲。
这是通过 API 调用的 lambda:
const shareWithGroup = async event => {
const { songCuid, groupCuids } = JSON.parse(event.body);
const shareSongDB = await query(
sql.queryShareWithGroup(songCuid, groupCuids),
); //share to group in DB
if (!shareSongDB) {
return corsUtil.failureWithCors("Couldn't Share Song with group");
}
const song = await query(sql.queryRead(songCuid));
if (!song) {
return corsUtil.failureWithCors('Song doesnt exist');
}
const songTitle = song.rows[0].songTitle; //retrieve songTitle
const promises = groupCuids.map(async groupCuid => { …Run Code Online (Sandbox Code Playgroud) 我的问题是,如果我在 VSCode 中编写 Lambda 函数,我无法将其部署到 AWS 控制台。
我有一个 AWS 帐户并提供了在 VSCode 中使用的凭据。只是测试使用命令将简单的 Lambda 函数部署到 AWS 控制台serverless deploy。到目前为止还没有成功。它在 S3 上创建存储桶并将邮政编码放在那里。
ConsoleTest 函数是在 AWS Lambda 控制台中手动创建的。

我的 serverless.yml 如下所示:
service: myservice
provider:
name: aws
runtime: nodejs12.x
functions:
hello:
handler: handler.hello
events:
- http:
path: users/create
method: get
Run Code Online (Sandbox Code Playgroud)
我遵循官方指南:https://serverless.com/framework/docs/providers/aws/guide/deploying/
有什么帮助吗?
我正在开发使用Twilio 可编程 SMS 的无服务器AWS 服务来传送文本消息。
当我在本地运行堆栈时(例如sls offline start),我的设置始终成功地传递消息,但在部署的环境中,我似乎甚至无法在Twilio 客户端上调用该方法上调用该方法。
消息传递的设置方式如下:
const twilio = require('twilio');
const twilioClient = twilio(
process.env.TWILIO_SID,
process.env.TWILIO_TOKEN,
{
lazyLoading: true,
}
);
export function sendMessage(user, message) {
twilioClient.messages.create({
from: process.env.TWILIO_NUMBER,
to: user.phone,
body: message,
}, function(err, message) {
console.log('error', err);
console.log('message', message);
});
}
// And then usage in a Serverless Function Handler
function example(event, context, callback) {
context.callbackWaitsForEmptyEventLoop = false;
// user is also determined here
sendMessage(user, 'This is …Run Code Online (Sandbox Code Playgroud) 我在SAM 项目文件requred query string params中指定时遇到问题。template.yml到目前为止,我没有找到这样的方法,只发现我们可以通过标头访问 lambda 函数中的查询字符串参数event.queryStringParameters。
那么我应该检查 lambda 层是否需要参数吗?或者有没有办法在 API 层本身做到这一点。因为我知道在serverless框架中我们可以指定是否需要查询字符串参数,如下所示:
functions:
create:
handler: posts.create
events:
- http:
path: posts
method: get
request:
parameters:
querystrings:
type: true
Run Code Online (Sandbox Code Playgroud) sam amazon-web-services serverless-framework serverless aws-sam
serverless ×10
aws-lambda ×4
node.js ×3
azure ×2
amazon-ses ×1
amazon-sns ×1
amazon-sqs ×1
aws-amplify ×1
aws-appsync ×1
aws-sam ×1
faas ×1
graphql ×1
powershell ×1
sam ×1
schema ×1
twilio ×1
twilio-api ×1