Search code examples
.net-coreaws-cdk

Using AwsSdkCall from C#


I want to create a Custom Resource in C#. In this resource I want to make an AwsSdkCall, something like this:

var sdkCall = new AwsSdkCall
{
    Service = "SSM",
    Action = "putParameter",
    Parameters = new PutParameters
    {
        Name = "/my-param",
        Tier = Amazon.SimpleSystemsManagement.ParameterTier.Standard,
        Type = Amazon.SimpleSystemsManagement.ParameterType.String,
        Value = "My value"
    }
};

The Parameters field is of type object?. I tried using an anonymous object here but I get an exception from JSII runtime that it can't handle anonymous objects. I tried to define my own class and use that, but JSII runtime didn't like that either.

What type am I supposed to use for this field to correctly specify parameters of the SDK call?


Solution

  • You should use a dictionary for the Parameters.

    Parameters = new Dictionary<string, object> 
    {
      { "Name", "/my-param" },
      { "WithDecryption", true }
    }
    

    Ref: https://docs.aws.amazon.com/cdk/api/v2/dotnet/api/Amazon.CDK.CustomResources.AwsSdkCall.html