How to provide JSON inside AWS CLI SNS message? - json

How to send via aws cli exact JSON structure in command line (NOT via file):
aws sns publish --topic-arn "arn:aws:sns:us-east-1:12345:myproject_serverlessscheduler_sns" --message '{"key1":"value1", "key2":"value2"}' --profile myprofile
Is this above a correct structure of JSON provided directly inside command line?

The JSON structure you provided is the correct way of passing JSON inside AWS CLI for SNS.
I tested on my test environment as shown below and confirmed to be working 100% :

Related

Using aws cli without a homedirectory

I need to use aws cli on an OpenShift Cluster that is quite restricted - it looks like the homedirectory is set to /, while the user in the container does not have permissions to write to /.
The only directory that is writeable from that user is /tmp. Now I need to use aws cli from within a pod of this OpenShift cluster. I came across the environment variables AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE. So I would place each a credentials file and a config file to /tmp.
When running aws configure list-profiles with this setup, only the one profile from AWS_SHARD_CREDENTIALS_FILE is listed. Not the one from AWS_CONFIG_FILE.
So it looks to me like AWS_CONFIG_FILE is not respected by aws cli.
Do you have an idea why these files might not be respected by the aws executable? Is there a way to pass the location of these files directly to the cli as parameter or s.th.?
Instead of configuring files for the AWS CLI, I would assume you could set the following 2 environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and issue your CLI commands immediately.
bruno#pop-os ~> export AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE"
bruno#pop-os ~> export AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
bruno#pop-os ~> aws cloudformation list-stacks --region us-east-2
{
"StackSummaries": []
}
To answer on:
So it looks to me like AWS_CONFIG_FILE is not respected by aws cli.
The AWS CLI does respect this.
You can specify a non-default location for the config file by setting
the AWS_CONFIG_FILE environment variable to another local path.

OCI IAAS Object Update API

Is there any API available in OCI to update an existing object in the bucket. Or can you please suggest any other alternative to this? I'm looking for a way to update the existing file.
As I said in the comments, Can you try using object versioning.
To enable object versioning after bucket creation
oci os bucket update --namespace <object_storage_namespace> --name <bucket_name> --compartment-id <target_compartment_id> --versioning Enabled
To list object versions
oci os object list-object-versions --namespace <object_storage_namespace> --bucket-name <bucket_name>
To get the contents of an object version
oci os object get --name <object_name> --file path/to/file/name --version-id <version_identifier> --namespace <object_storage_namespace> --bucket-name <bucket_name>
To delete an object version
oci os object delete --name <object_name> --version-id <version_identifier> --namespace <object_storage_namespace> --bucket-name <bucket_name>
to load continue to use oci os object put
More in the documentation https://docs.oracle.com/en-us/iaas/Content/Object/Tasks/usingversioning.htm. You can find also the way to do using the API or the SDK
Since you are trying to append additional content to an uploaded object, you would need to download the existing object using the GetObject API, append to the downloaded content locally, and then upload that original+appended content back to object storage using the PutObject API.

My API on heroku sends JSON as plain text in the response instead of sending the JSON itself

I made a REST API in python using flask-RESTful, to run it locally I can use flask and it works fine, but to deploy on heroku I have to use gunicorn, the problem is that gunicorn sents the json as plain text and it is ugly, I use gunicorn because i cant use flask by itself, It fails to work on vanilla heroku and also there are no guides that actually use flask without gunicorn on heroku.
PS[1]: I dont specify an ip address in flask or gunicorn, i let it decide by itself.
PS[2]: my api link on heroku using gunicorn: https://arjixgamersapi.herokuapp.com/
Local JSON image
Deployed JSON image
For sending Json formatted responses in Flask I used to use the jsonify() function from the flask package.
"It creates a Response with the JSON representation of the given arguments with an application/json mimetype" (https://kite.com/python/docs/flask.jsonify)

How to download logs created by ECS container to make them look the old-fashined way remove JSON?

My good old application creates log caught by AWS Cloudwatch logs
However it is ugly to read them trapped inside JSON. Can I get them in a raw form?
Install jq (a C++ application without dependency hell) from your favourite package repository (or from GitHub).
Download the logs and parse them with
#profile=...
#lgn=...
aws --profile $profile logs get-log-events --log-stream-name
$lsn --log-group-name /$lgn | jq --raw-output '.events[] | .message'

Uploading a file through CKAN's API (1.8): How to do it?

I am trying to automate dataset and resource uploading in my CKAN instance. I am using Ubuntu Linux 10.04 64-bit and my CKAN instance version is 1.8.
I can create a new dataset using the command like like so:
$ curl http://ckan.installation.com/api/rest/dataset -H "Authorization:<my api key>" -d '{"name": "dataset-name", "title": "The Name of the Dataset"}'
{... JSON text recieved in response, including the id of the dataset ...}
Now, how do I go about creating and uploading resources (like image files) in my CKAN instance using the command line?
Thanks!
Uploading a file through the FileStore API is somewhat complicated. You'll be better reusing ckanclient's upload_file method. A simple Python script that uses this could solve your problem of uploading from the command-line.
Or, if you're feeling brave, that's the best place to start understanding how to upload a file using cURL.