Getting exception for putItem when accessing dynamoDB (local) on windows - amazon-web-services

Started running DynamoDB on my local and below powershell script I'm using to perform a test insert, from the output I see it is able to read the table but fails on putitem operation,
Appreciate any suggestions or references on this, not sure what I'm missing here.
$localEndpoint = 'http://localhost:8000'
$region = 'us-west-2'
$table = Get-DDBTable -TableName test01 -EndpointUrl $localEndpoint
$table
$client = New-Object Amazon.DynamoDBv2.AmazonDynamoDBClient($localEndpoint, $region)
$client
$req = New-Object Amazon.DynamoDBv2.Model.PutItemRequest
$req.TableName = 'test01'
$req.Item = New-Object 'system.collections.generic.dictionary[string,Amazon.DynamoDBv2.Model.AttributeValue]'
$valObj = New-Object Amazon.DynamoDBv2.Model.AttributeValue
$valObj.S = 'MyName'
$req.Item.Add('Name',$valObj)
$req
$client.PutItem($req)
Results with exception:
ArchivalSummary :
AttributeDefinitions : {Name}
BillingModeSummary :
CreationDateTime : 3/11/2022 11:49:44 PM
GlobalSecondaryIndexes : {}
GlobalTableVersion :
ItemCount : 0
KeySchema : {Name}
LatestStreamArn :
LatestStreamLabel :
LocalSecondaryIndexes : {}
ProvisionedThroughput : Amazon.DynamoDBv2.Model.ProvisionedThroughputDescription
Replicas : {}
RestoreSummary :
SSEDescription :
StreamSpecification :
TableArn : arn:aws:dynamodb:ddblocal:000000000000:table/test01
TableId :
TableName : test01
TableSizeBytes : 0
TableStatus : ACTIVE
Config : Amazon.DynamoDBv2.AmazonDynamoDBConfig
ConditionalOperator :
ConditionExpression :
Expected : {}
ExpressionAttributeNames : {}
ExpressionAttributeValues : {}
Item : {[Name, Amazon.DynamoDBv2.Model.AttributeValue]}
ReturnConsumedCapacity :
ReturnItemCollectionMetrics :
ReturnValues :
TableName : test01
StreamUploadProgressCallback :
RequestState : {}
UseSigV4 : False
Exception calling "PutItem" with "1" argument(s): "Credential must have exactly 5 slash-delimited elements, e.g. keyid/date/region/service/term, got 'http://localhost:8000/20220312/us-west-2/dynamodb/aws4_request'"
At line:19 char:1
+ $client.PutItem($req)
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : AmazonDynamoDBException

Related

TRC20 curl for getaccount/getbalance

What is the correct curl format to view trc20 balance of an account? I tried the below command, but the output showed no balance.
curl -X POST http://127.0.0.1:8090/wallet/triggersmartcontract -d
'{
"contract_address":"TCFLL5dx5ZJdKnWuesXxi1VPwjLVmWZZy9",
"address":"TUT5SVvKmnxKpKdHi2tXMzPfffQNg7e3MU",
"function_selector":"balanceOf(address)",
"owner_address":"TUT5SVvKmnxKpKdHi2tXMzPfffQNg7e3MU",
"visible":true
}'
output:
{
"result" : {
"result" : true
},
"transaction" : {
"raw_data" : {
"ref_block_hash" : "0d9745f14e11d7fa",
"expiration" : 1605942390000,
"ref_block_bytes" : "9c45",
"contract" : [
{
"type" : "TriggerSmartContract",
"parameter" : {
"type_url" : "type.googleapis.com/protocol.TriggerSmartContract",
"value" : {
"contract_address" : "TCFLL5dx5ZJdKnWuesXxi1VPwjLVmWZZy9",
"owner_address" : "TUT5SVvKmnxKpKdHi2tXMzPfffQNg7e3MU",
"data" : "70a08231"
}
}
}
],
"timestamp" : 1605942331560
},
"txID" : "a3bdcb595a94f9805301fb74b33f2b536d3a6bb5050b7eb7b12808bb1e36fcd7",
"visible" : true,
"ret" : [
{}
],
"raw_data_hex" : "0a029c4522080d9745f14e11d7fa40f0d980cdde2e5a6d081f12690a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412340a1541cab799601a50938457902e1a31d3faa26ca1d76012154118fd0626daf3af02389aef3ed87db9c33f638ffa220470a0823170a891fdccde2e"
},
"constant_result" : [
"0000000000000000000000000000000000000000000000000000000000000000"
]
}
I use the default main_net_config with supportConstant = true. Do I have to enable anything else in my config file?

elasticsearch-dsl-py query filter with term and range

I'm trying to filter a query with term and range along with query-string. filter(range) and query string works but not filter(term). am i doing something wrong?
es = Elasticsearch([{'host': '192.168.121.121', 'port': 9200}])
index = Index("filebeat-*",using=es)
search = index.search()
searchStr = "OutOfMemoryError"
search = search.query("query_string", query=searchStr)
search = search.filter('range' , **{'#timestamp': {'gte': 1589399137000 , 'lt': 1589399377000, 'format' : 'epoch_millis'}})
search = search.filter('term' , **{'can.deployment': 'can-*' })
response = search.execute(ignore_cache=True)
print(response.hits.total)
print(response.hits.hits._source.can.deployment)
json:
filter-term - ['hits']['hits']['_source']['can']['deployment']
filter-range- ['hits']['hits']['_source']['#timestamp']
{
"hits" : {
"total" : 138351328,
"max_score" : 6.5700893,
"hits" : [
{
"_index" : "filebeat-6.1.2-2020.05.13",
"_type" : "doc",
"_score" : 2.0166037,
"_source" : {
"#timestamp" : "2020-05-13T01:14:03.354Z",
"source" : "/var/log/gw_rest/gw_rest.log",
"message" : "[2020-05-13 01:14:03.354] WARN can_gw_rest [EventLoopGroup-3-2]: An exceptionCaught() event was fired.OutOfMemoryError,
"fileset" : {...},
"can" : {
"level" : "WARN",
>>>>>>>> "message" : "An exceptionCaught() event was fired- OutOfMemoryError,
"timestamp" : "2020-05-13 01:14:03.354",
>>>>>>>> "deployment" : "can-6b721b93965b-w3we4-4074-9903"
}
}
}
]
}
}
I actually didn't need a filter(term). this worked:
dIds=response['hits']['hits'][1]['_source']['can']['deployment']
print(dIds)
#loop through the response
for i in response['hits']['hits']:
id = i['_source']['can']['deployment']
print(id)

Mongodb db.collection.distinct() on aws documentdb doesn't use index

Transitioning to new AWS documentDB service. Currently, on Mongo 3.2. When I run db.collection.distinct("FIELD_NAME") it returns the results really quickly. I did a database dump to AWS document DB (Mongo 3.6 compatible) and this simple query just gets stuck.
Here's my .explain() and the indexes on the working instance versus AWS documentdb:
Explain function on working instance:
> db.collection.explain().distinct("FIELD_NAME")
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "db.collection",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [ ]
},
"winningPlan" : {
"stage" : "PROJECTION",
"transformBy" : {
"_id" : 0,
"FIELD_NAME" : 1
},
"inputStage" : {
"stage" : "DISTINCT_SCAN",
"keyPattern" : {
"FIELD_NAME" : 1
},
"indexName" : "FIELD_INDEX_NAME",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 1,
"direction" : "forward",
"indexBounds" : {
"FIELD_NAME" : [
"[MinKey, MaxKey]"
]
}
}
},
"rejectedPlans" : [ ]
},
Explain on AWS documentdb, not working:
rs0:PRIMARY> db.collection.explain().distinct("FIELD_NAME")
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "db.collection",
"winningPlan" : {
"stage" : "AGGREGATE",
"inputStage" : {
"stage" : "HASH_AGGREGATE",
"inputStage" : {
"stage" : "COLLSCAN"
}
}
}
},
}
Index on both of these instances:
{
"v" : 1,
"key" : {
"FIELD_NAME" : 1
},
"name" : "FIELD_INDEX_NAME",
"ns" : "db.collection"
}
Also, this database has a couple million documents but there are only about 20 distinct values for that "FIELD_NAME". Any help would be appreciated.
I tried it with .hint("index_name") and that didn't work. I tried clearing plan cache but I get Feature not supported: planCacheClear
COLLSCAN and IXSCAN don't have too much difference in this case, both need to scan all the documents or index entries.

AppSync to DynamoDB update query mapping error

I have the following DynamoDB mapping template, to update an existing DynamoDB item:
{
"version" : "2017-02-28",
"operation" : "UpdateItem",
"key" : {
"id": $util.dynamodb.toDynamoDBJson($ctx.args.application.id),
"tenant": $util.dynamodb.toDynamoDBJson($ctx.identity.claims['http://domain/tenant'])
},
"update" : {
"expression" : "SET #sourceUrl = :sourceUrl, #sourceCredential = :sourceCredential, #instanceSize = :instanceSize, #users = :users",
"expressionNames" : {
"#sourceUrl" : "sourceUrl",
"#sourceCredential" : "sourceCredential",
"#instanceSize" : "instanceSize",
"#users" : "users"
},
"expressionValues" : {
":sourceUrl" : $util.dynamodb.toDynamoDbJson($ctx.args.application.sourceUrl),
":sourceCredential" : $util.dynamodb.toDynamoDbJson($ctx.args.application.sourceCredential),
":instanceSize" : $util.dynamodb.toDynamoDbJson($ctx.args.application.instanceSize),
":users" : $util.dynamodb.toDynamoDbJson($ctx.args.application.users)
}
},
"condition" : {
"expression" : "attribute_exists(#id) AND attribute_exists(#tenant)",
"expressionNames" : {
"#id" : "id",
"#tenant" : "tenant"
}
}
}
But I'm getting the following error:
message: "Unable to parse the JSON document: 'Unrecognized token '$util': was expecting ('true', 'false' or 'null')↵ at [Source: (String)"{↵ "version" : "2017-02-28",↵ "operation" : "UpdateItem",↵ "key" : {↵ "id": {"S":"abc-123"},↵ "tenant": {"S":"test"}↵ },↵ "update" : {↵ "expression" : "SET #sourceUrl = :sourceUrl, #sourceCredential = :sourceCredential, #instanceSize = :instanceSize, #users = :users",↵ "expressionNames" : {↵ "#sourceUrl" : "sourceUrl",↵ "#sourceCredential" : "sourceCredential",↵ "#instanceSize" : "instanceSize",↵ "#users" : "users"↵ }"[truncated 400 chars]; line: 17, column: 29]'"
I've tried removing parts, and it seems to be related to the expressionValues, but I can't see anything wrong with the syntax.
Seems like you misspelled the toDynamoDBJson method
Replace
$util.dynamodb.toDynamoDbJson($ctx.args.application.sourceUrl)
with
$util.dynamodb.toDynamoDBJson($ctx.args.application.sourceUrl)
Note the uppercase B in toDynamoDBJson.

Dynamo DB filter expression using IN operator with numeric array variable

I am trying to execute a query with the following payload
payload = {
TableName : "fleet_list",
IndexName : "vehicle_type-department-index",
KeyConditionExpression : "vehicle_type = :v",
FilterExpression : "(id IN (:list))",
ExpressionAttributeValues : {
":v" : "Car",
":list" : [1947, 4397].join()
}
}
However the query does not work. it does work however if :list : 1947 . Any help will be appreciated
Try the following:
Change FilterExpression : "(id IN (:list))", to FilterExpression : "(id IN (:id1, :id2))",.
Change ":list" : [1947, 4397].join() to ":id1": 1947, ":id2": 4397.