dprc88435 2019-03-30 15:34
浏览 34

使用SAM在本地运行时,如何在go lambda的环境变量中获取SQS URL?

I'm trying to develop a serverless application using cloudformation. I need a go lambda function to send messages in a SQS. To send these messages, I need a queue URL. I am supposed to store this URL in my lambda function's environment variables.

But when I run it locally, with sam local start-api, my variable is empty. When I deploy it, it works, but I can't test it locally.

Here is my template.yaml:

  APIGetFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: service_get_person 
      Runtime: go1.x
      CodeUri: ./src/person/service/get_person
      Description: 'Get a person'
      MemorySize: 128
      Timeout: 30
      Role: !GetAtt LambdaExecutionRole.Arn
      Events:
        GetEvent:
          Type: Api
          Properties:
            Path: /person
            Method: get
      Environment:
        Variables:
          QueueUrl: !Ref MyQueue
          REGION: eu-west-3

  MyQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: test_queue
      DelaySeconds: 0
      VisibilityTimeout: 120

I'm using os.Getenv("QueueUrl") to get my variables.

Do any of you have the solution to solve this problem?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 易康econgnition精度验证
    • ¥15 线程问题判断多次进入
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致