How to pass variable inside the json input for aws cli command?

Hi,
I am using “RUN AN AWS CLI SCRIPT” step template to run following code

$lamdaArn = aws ssm get-parameter --name “MyStringParameter”
$lamdaArn = $lamdaArn.Parameter.Value
aws s3api put-bucket-notification-configuration --bucket #{testBucketName} --notification-configuration file://lambdaNotificationSettings.json

The Json file is as below -

{
	"LambdaFunctionConfigurations": 
		[
			{
				"LambdaFunctionArn":<USE LAMBDA ARN OCTOPUS Variable HERE>,
				"Events": 
					[
						"s3:ObjectCreated:*"
					]
			}
		]
}

As you can see I want to use Octopus variable inside the json file, how can I achieve this?

Hi @harsh_tech,

Welcome to the community!

That is a great question which will have multiple answers!

I’ve reached out to our Solutions team for some advice about the best approach to this and we’ll keep you updated!

I believe the difficulty is targeting a file on the local system, if the JSON file was in a package uploaded to the Octopus Built-in Feed, then you could leverage ‘Structured configuration variables’ or ‘Substitute variables in templates’ to achieve the variable substitution. Both of these are configurable features for the deployment process found at the bottom of the page.

Feel free to let me know if you have any questions!

Best Regards,

Thanks @finnian.dempsey for your reply, can I then add one step before this to dynamically push the json file/object with variable name in it to the octo package? but how would the local variable value be replaced in json? variable would need to populated by reading SSM Parameter store…

Hi @harsh_tech,

Finnian asked me to take a look at your request.

Before talking about changing your process, I’d like to start basic to make sure I understand all the pieces of the puzzle. Where does that .json file currently live? How does that file make it to a location for that step to access?

Best regards

Thanks @Bob_Walker for looking into this. The .json file is currently in the shared folder and I am passing the shared path in the aws cli command like below -

$testSSMParameter = aws ssm get-parameter --name “testLambdaArn”
$testLambdaArn = $testSSMParameter.Parameter.Value
aws s3api put-bucket-notification-configuration --bucket #{testBucketName} --notification-configuration file:////shared.dev01.com/notificationSettings.json

I manually created and copied that file in the shared path because I can not hold/store file in Octopus deploy(based on my knowledge).