Deploy AWS ECS tasks from Octopus

On Octopus Cloud instance I am updating AWS ECS service. I have followed steps defined in this blog

I am running the powershell script inside docker container using Execution containers. My script is failing at below step

$ContainerDefinitions = New-Object “System.Collections.Generic.List[Amazon.ECS.Model.ContainerDefinition]”

InvalidType: Cannot find type [System.Collections.Generic.List[Amazon.ECS.Model.ContainerDefinition]]: verify that the assembly containing this type is loaded.

My docker container has powershell version 4.1.2

What assembly do I need to add to my docker container here to get the script working? Or what other worker I can use for this script to work?

Hi @vaibhavn,

Thanks for reaching out and providing all that info!

From the error message provided it seems that the ‘Amazon.ECS.Model.ContainerDefinition’ isn’t known by Powershell. Could you please confirm that the AWS SDK is installed in the container you are running the script from?

Feel free to let me know if you have any questions or if you run into any issues!

Thanks, I already had the AWSPowerShell.NetCore installed in the Octopus worker Docker container (docker file from here WorkerTools/Dockerfile at master · OctopusDeploy/WorkerTools · GitHub)

Although PowerShell 3.0 and later releases typically load modules into your PowerShell session the first time you run a cmdlet in the module, the AWSPowerShell.NetCore module is too large to support this functionality. So must instead explicitly load the AWSPowerShell.NetCore Core module into your PowerShell session by running the following command.

Import-Module AWSPowerShell.NetCore

In above Octopus docker file I added below
ADD Profile.ps1 C:\Windows\System32\WindowsPowerShell\v1.0

where profile.ps1 has
C:>type Profile.ps1
Import-Module AWSPowerShell.NetCore

After adding profile to import AWSPowerShell.NetCore module, script is working.

Hi @vaibhavn,

That’s great to hear you managed to get it working!

Thanks for sharing the answer too, hopefully this helps someone in the future.

Feel free to reach out again in future.

Happy Deployments!