2

I am trying to put a variable in the AWS CLI DynamoDB command for add a row in a table:

aws dynamodb put-item --table-name table_name --item '{"id_proceso": {"N": "1"}, "fecha_proceso": {"S": "20210707170486"}, "status": {"S": "OK"}, "fecha_termino": {"S": "fecha_termino_var"  } }' --region us-east-1

Where fecha_termino_var it should be a variable. example: fecha_termino_var=(date +'%Y/%m/%d %H:%M:%S')

but I have tried various ways but I have not managed to do it, is there any way to enter a variable in a aws cli command line?

The goal it is to add a row, which will contain a variable of the date in real time.

I've tried various ways but it just adds the variable type, in this case "date", or just the variable name in text plain "fecha_termino_var".

I'm working in a shell (.sh) to do this.

Failed image adds:

enter image description here enter image description here

7
  • " without success" its not specific. Exactly what is happening? Why do you have space in $ {date}? Why do you use single quotes? Commented Jul 9, 2021 at 3:26
  • what date=(date +'%Y/%m/%d %H:%M:%S') is supposed to do? Can you explain? You are overwriting date with date? Commented Jul 9, 2021 at 3:27
  • without success I mean that sometimes it inserts the row but only the text or it gives syntax error Commented Jul 9, 2021 at 3:28
  • "date" is just an example to save the date inside that column, it doesn't necessarily have to have the same variable name. the goal is to save a variable within the command line Commented Jul 9, 2021 at 3:29
  • This is date=(date +'%Y/%m/%d %H:%M:%S') wrong. Is this bash? What do you think it does? Commented Jul 9, 2021 at 3:32

1 Answer 1

1

Your screenshot shows that you are missng " infront of fecha_termino. So it should be:

, "fecha_termino":

not:

, fecha_termino":

Update:

The full correct command is:

aws dynamodb put-item --table-name mcp_control_proceso --item '{"id_proceso": {"N": "1"}, "fecha_proceso": {"S": "20210707170487"}, "status": {"S": "OK"}, "fecha_termino": {"S": "'"${fecha_termino_var}"'"} }' --region us-east-1
Sign up to request clarification or add additional context in comments.

12 Comments

thanks for the answer, after this fix it adds the row, but in another way like "$fecha_termino" prnt.sc/19n297b
@Sebastián This is due to single quotes. Check my first comment "Why do you use single quotes? " Don't use single quotes to wrap your string. It does not resolve veriables.
How it should be? The code I added last one it's: "fecha_termino": {"S": "$fecha_termino" }
@Sebastián Sorry, I don't know. Your real code is different than in the question. Its difficult to speculate what actually you are actually using.
sorry, already fixed, I just want to insert a variable inside variable, "data": {"S": "$variable"} but it seems to be very difficult
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.