6

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?

Anthon
  • 69,918
  • 32
  • 186
  • 246
4kakarendset
  • 61
  • 1
  • 2
  • When you have environment variables used in lambda they need to be there on the machine where the lambda runs. You need to create environment variable with name `QueueUrl` and proper value so that lambda will pick it up when you run it locally. – Chetan Mar 31 '19 at 02:18

0 Answers0