2

I am using Elastic Beanstalk to deploy a worker tier environment using SQS.

In my .ebextensions I have the following file:

option_settings:
  aws:elasticbeanstalk:sqsd:
    WorkerQueueURL:
      Ref: WorkerQueue
    HttpPath: "/sqs/"
    InactivityTimeout: 1650
    VisibilityTimeout: 1680
    MaxRetries: 1

Resources:
  WorkerQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: "tpc-clients-aws-queue"
      VisibilityTimeout: 1680

However, this fails with the following error:

"option_settings" in one of the configuration files failed validation. More details to follow.

Invalid option value: 'Ref=WorkerQueue' (Namespace: 'aws:elasticbeanstalk:sqsd', OptionName: 'WorkerQueueURL'): Value does not satisfy regex: '^$|^http(s)?://.+$' [Valid non empty URL starting with http(s)]

It seems that the AWSCloudFormation Ref function cannot be used in the option_settings. Can someone confirm if this is the case?

I have seen some code snippets here on StackOverflow using intrinsic functions in the option_settings, such as in the mount-config.config of this answer and also on this question. So, are these examples using an invalid syntax? Or there are some intrinsic functions or specific resources that can be used on the option_settings?

And lastly, if I cannot use the Ref function, how can I go about this?

Martín De la Fuente
  • 6,155
  • 4
  • 27
  • 28
  • How did it go? Still unclear what you can do? Do you know you can accept your own answer to make the issue as solved? – Marcin Aug 22 '21 at 23:50

2 Answers2

2

Yes, you can reference in .ebextentions, but the syntax is a bit strange. It is shown in the docs here.

You can try something along these lines (note the various quotations marks):

option_settings:
  aws:elasticbeanstalk:sqsd:
    WorkerQueueURL: '`{"Ref" : "WorkerQueue"}`'
    HttpPath: "/sqs/"
    InactivityTimeout: 1650
    VisibilityTimeout: 1680
    MaxRetries: 1

Resources:
  WorkerQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: "tpc-clients-aws-queue"
      VisibilityTimeout: 1680

You can also use ImportValue, if you export the WorkerQueue in outputs.

Update

To check the value obtained, you can set it as an env variable, and inspect in EB console:

option_settings:
    aws:elasticbeanstalk:application:environment:
        SQS_NAME: '`{"Ref" : "WorkerQueue"}`'
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • I just tried using that syntax but I am still getting the `Invalid option value:..` error. I also tried using the outputs and the `Fn::ImportValue` function but the problem persists. Maybe the functions are not returning a proper URL? Do you know how I could check that (i.e. the value being returned by the intrinsic functions)? – Martín De la Fuente Sep 29 '20 at 02:23
  • @MartínDelaFuente You can go to CloudFormation console, locate stack that EB creates, and check its outputs. Also you can use the value in env variables to see its value as in the updated answer. – Marcin Sep 29 '20 at 02:27
  • Inspecting the EB console to check the env variable is useless, I had to check it using hooks and it worked. However, using the same expression for `aws:elasticbeanstalk:sqsd:WorkerQueueURL` doesn't seem to be possible. Check the answer I posted. – Martín De la Fuente Sep 30 '20 at 03:11
  • @MartínDelaFuente Thanks for letting me know. – Marcin Sep 30 '20 at 03:40
2

After digging further in this issue I made some discoveries I would like to share with future readers.

Ref can be used on option_settings

As @Marcin answer states, the Ref intrinsic function can be used in the option_settings. The syntax is different though:

'`{"Ref" : "ResourceName"}`'

Using Ref on aws:elasticbeanstalk:application:environment (environment variable)

An use case of the above is to store the queue URL in an environment variable, as follows:

option_settings:
  aws:elasticbeanstalk:application:environment:
    QUEUE_URL: '`{"Ref" : "WorkerQueue"}`'

This will let your .sh script access the URL of the queue: env var printed by hook

Note that if you check the Elastic Beanstalk console (Environment > Config > Software), you won't see the actual value: env var in eb console

Using Ref on aws:elasticbeanstalk:sqsd:WorkerQueueURL

If you try to use the following setting:

option_settings:
  aws:elasticbeanstalk:sqsd:
    WorkerQueueURL: '`{"Ref" : "WorkerQueue"}`'
    HttpPath: "/sqs/"

It will fail:

Invalid option value: '`{"Ref" : "WorkerQueue"}`' (Namespace: 'aws:elasticbeanstalk:sqsd', OptionName: 'WorkerQueueURL'): Value does not satisfy regex: '^$|^http(s)?://.+$' [Valid non empty URL starting with http(s)]

It seems that this configuration option don't accept a reference.

Instead of creating a new queue and assign it to the sqs daemon, you can just update the queue that Elastic Beanstalk creates:

option_settings:
  # SQS daemon will use default queue created by EB (AWSEBWorkerQueue)
  aws:elasticbeanstalk:sqsd:
    HttpPath: "/sqs/"

Resources:
  # Update the queue created by EB
  AWSEBWorkerQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: "tpc-clients-aws-queue"
Martín De la Fuente
  • 6,155
  • 4
  • 27
  • 28