https://pulumi.com logo
Title
h

hallowed-postman-2096

03/24/2023, 11:32 PM
Hello there, I'm getting a type mismatch error when defining the key_schema(with only the hashkey) for dynamodb using the aws_native provider ,
import pulumi_aws_native as aws_native

aws_native.dynamodb.Table(
       table_id,
       table_name="example",
       billing_mode="PROVISIONED",
       opts=pulumi.ResourceOptions(protect=True),
       attribute_definitions=[
           aws_native.dynamodb.TableAttributeDefinitionArgs(
               attribute_name="PrimaryKey",
               attribute_type="S",
            )
        ],
        provisioned_throughput=aws_native.dynamodb.TableProvisionedThroughputArgs(
            read_capacity_units=100,  
            write_capacity_units=1,
        ),
        key_schema=[
            aws_native.dynamodb.TableKeySchemaArgs(
                attribute_name="PrimaryKey",
                key_type="HASH",
             ),
        ],
)
And here is the error:
raise AssertionError(f"Unexpected type. Expected 'list' got '{typ}'")
AssertionError: Unexpected type. Expected 'list' got 'typing.Union[typing.Sequence[typing.Union[pulumi_aws_native.dynamodb._inputs.TableKeySchemaArgs, typing.Awaitable[pulumi_aws_native.dynamodb._inputs.TableKeySchemaArgs], pulumi.output.Output[NoneType]]], typing.Any, typing.Awaitable[typing.Union[typing.Sequence[typing.Union[pulumi_aws_native.dynamodb._inputs.TableKeySchemaArgs, typing.Awaitable[pulumi_aws_native.dynamodb._inputs.TableKeySchemaArgs], pulumi.output.Output[NoneType]]], typing.Any]], pulumi.output.Output[NoneType]]'
More info here. Appreciate any guidance, Thanks !
c

creamy-monkey-35142

03/25/2023, 1:15 PM
not sure, how Union work in this case, you should check the module code
Union typing is only needed when you have a statically typed language, as you need to declare that an object can return one of multiple types (in your case an int or str, or in the other example str or NoneType)
it’s support from python 3.5
what is your python version?
h

hallowed-postman-2096

03/27/2023, 4:45 PM
@creamy-monkey-35142 we use python 3.9.16 for our deploys with pulumi. Here is the sdk code: https://github.com/pulumi/pulumi-aws-native/blob/v0.54.0/sdk/python/pulumi_aws_native/dynamodb/table.py#L19 https://github.com/pulumi/pulumi/blob/v3.59.0/sdk/python/lib/pulumi/runtime/rpc.py#L150 Probably the issue is with defining the key_schema with only the hashkey and not the rangekey in the list.