简体   繁体   English

Visual Studio 为非生产环境部署 AWS Lambda

[英]Visual studio deploy AWS Lambda for non prod environment

I have deployed and able to use a webApi published to AWS Lambda, but it is always "prod"我已经部署并能够使用发布到 AWS Lambda 的 webApi,但它始终是“产品”

I want to now setup test/dev environments我现在想设置测试/开发环境

If i right click the project and choose to "Publish to AWS Lambda", there is no option to change the env.如果我右键单击项目并选择“发布到 AWS Lambda”,则没有更改环境的选项。

I have however, found in my project a "serverless.template" file, which contains the following:但是,我在我的项目中找到了一个“serverless.template”文件,其中包含以下内容:

"Outputs": {
    "ApiURL": {
      "Description": "API endpoint URL for Prod environment",
      "Value": {
        "Fn::Sub": "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
      }
    },

So, my question is, do i just need to change the Fn::Sub to be "/Dev/" instead of "/Prod/" and if not, how will i publish to a dev environment?所以,我的问题是,我是否只需将 Fn::Sub 更改为“/Dev/”而不是“/Prod/”,如果没有,我将如何发布到开发环境?

Thank you谢谢

UPDATE: I have created a stages "stage" called Dev now:更新:我现在创建了一个名为 Dev 的阶段“阶段”: 在此处输入图像描述

so i guess the next stop is to deploy from visual studio, however, there is no way to select this stage when trying to deploy?所以我想下一站是从visual studio部署,但是,在尝试部署时没有办法到select这个阶段?

If you change the Prod to Dev it will output the URL for a API Gateway stage named Dev .如果将Prod更改为Dev ,它将 output 和 URL 用于名为Dev的 API 网关阶段。

If you're using API Gateway then having a separate stage for each environment is a good approach to seperate.如果您使用的是 API 网关,那么为每个环境设置一个单独的阶段是一个很好的分离方法。

Regarding deploying Lambdas you should use an Alias for each environments version to ensure you don't accidently update prod.关于部署 Lambda,您应该为每个环境版本使用别名,以确保您不会意外更新 prod。

Then within API Gateway create a stage variable and reference this for the Arn to the Lambda alias so that the Dev stage will use the Dev Alias.然后在 API 网关中创建一个阶段变量,并将其作为 Arn 引用到 Lambda 别名,以便开发阶段将使用开发别名。

If you have seperate accounts between prod and non prod then these won't collide, although I always believe its better to us clear naming conventions for environments to avoid confusion.如果您在 prod 和 non prod 之间有单独的帐户,那么这些帐户就不会发生冲突,尽管我始终认为最好为我们明确环境的命名约定以避免混淆。

Hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM