【问题标题】:How to read aws sam parameter in .NET lambda function如何在 .NET lambda 函数中读取 aws sam 参数
【发布时间】:2020-03-16 04:33:25
【问题描述】:

我有一个 SAM 模板,它接受 .yml 文件中的参数,我想访问用 c# 编写的 lambda 函数中的参数值

这里是 SAM 模板

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >      
Globals:
  Function:
    Timeout: 60
    Runtime: dotnetcore2.1
Parameters: 
  ApiBaseUri: 
    Type: String
    Default: https://postb.in/1584332032935-8906962152104
    Description: The API URL where the received events will be pushed by the lambda function
Resources:
  PushUpdates:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./src/PushAPIs/
      Handler: Localgov.Microservices::LambPaymentTracker.UpdateHandler::PushBurtonUpdates
      Runtime: dotnetcore2.1
      Policies: AWSLambdaDynamoDBExecutionRole
      Events:
        Stream:
          Type: DynamoDB
          Properties:
            Stream: !GetAtt UpdatesTable.StreamArn
            BatchSize: 100
            StartingPosition: TRIM_HORIZON 

【问题讨论】:

    标签: amazon-web-services aws-sam sam


    【解决方案1】:

    将 cloudformation(或 sam)变量传递给 lambda 的常用方法是通过 Environment Variables

    在您的模板中,您使用Environment 属性指定变量。

    然后,在您的代码中,您可以使用您的编程语言特定功能来阅读它们。

    【讨论】:

    • 感谢@Marcin 参数和环境变量之间的区别是什么?
    • @طارقالشيخورق Parameters 是模板的一部分,您无法在 lambda 函数中访问。 environment variable 可以从 lambda 访问。
    猜你喜欢
    • 2022-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 2021-01-30
    • 2019-10-04
    • 1970-01-01
    • 2021-01-24
    相关资源
    最近更新 更多