Hello there, I'm getting a type mismatch error whe...
# general
h
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 ,
Copy code
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:
Copy code
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
not sure, how Union work in this case, you should check the module code
Copy 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
@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.