Using pyautogui.screenshot in AWS Workspaces - python-3.x

I'm running a python script in the AWS Workspaces to take a screensot of my entire desktop (inside AWS).
The script is working fine but when I "ended" the AWS Workspace, the screenshot being taken is the login page. Please find attached.
Inside the AWS Workspace, I already did any possible ways to prevent "my computer" from sleeping. Likewise, its Running Mode is AlwaysOn.
What I want to achieve is even though my AWS Workspace is not "active" I want my python script to capture the active desktop not the login page.

Related

creating a GNU screen during deployment by AWS codeDeploy

I am trying to create a Linux screen during the deployment using AWS codeDeploy.
The purpose is to run the application inside a screen. I want codeDeploy being able to create a screen in detached mode and start the application inside it.
I tried these commands in AfterInstall and BeforeInstall stages:
screen -RS
screen -dm
But, when the deployment finishes successfully, the screen has not been created.
Also, if I try to send a command to the screen that I have tried to create in the previous stage, I get this error:
[stdout]Must be connected to a terminal.
So, my questions are:
How to get codeDeploy running the application inside a screen
Is it even a decent way of deployment? Maybe I am not supposed to do that at all.
Well, I had made a couple of mistakes that caused the failure.
codeDeploy runs under root user by default. And any screen it creates is not visible to other users. You may want to run codeDeploy as another user (there is a tutorial in Amazon for this), or run your commands in the codeDeploy scripts with runuser (as a user other than root)
any try to attach to a screen (or create a screen in the attached mode) is doomed to fail, because codeDeploy is not connected to a terminal. You need to create the screen in the detached mode. For example, by: screen -dmS name

Debug scenario for lambda

As usual many things to do and no time to do it, so I need some suggestions.
This the scenario. AWS Lambda development based on SAM cli (aws cli/sam cli/docker/IntelliJ with AWS plugin) on Ubuntu 18.04
Developing a lambda function on node.js 12 - Javascript.
Everything is almost working perfectly. I edit the function, run from IntelliJ, docker is executed with the lambda function, logs are happily popping up.
I say almost because I have a problem.
I create a text file in the function and is saved on /tmp/myTextFile.txt
I would like to be able to see the content of this file.
So I was wondering if exists a way to do it accessing the docker image.
I did try to "debug" the function rather than just execute it, putting a breakpoint after generating and saving the file.
I verified that the docker image remains open when the breakpoint is hit.
Then I did try to attach a terminal to the open docker image, no errors but also nothiing happens.
On a terminal I did open a terminal and :
docker container ls
I did see the docker image opened from the the local SAM development
Then :
docker container attach "ID of the opened image"
and .. nothing.
There is a way to login and execute commands like "ls" or "cat" ?
In this way I could see if the file was generated and if is correct.
Thanks for any suggestion !
Steve

Google Cloud python project has localhost error

I've been following the instructions for this guide:
https://developers.google.com/gmail/api/quickstart/python
to run a basic program which reads a Gmail inbox.
Basically, the program opens up a new window asking you to login with your gmail account - once that is done, it gives the information back to the program which should print results on the google cloud shell terminal.
Whenever I login with the correct google account, the page shows "localhost refused to connect". For this reason, the rest of the program cannot continue, so the google cloud shell is stuck waiting for the login to occur. Would anyone have any ideas on why this localhost error is happening? Thanks in advance.
Solution
Run the code from your desktop.
The OAuth Flow that you are using requires a web browser. This means the webserver process must be running on your system.
You are trying to run code in Cloud Shell. And it does not have one. If you look at the source code run_local_server() starts a webserver. The server is running on the wrong system.
There are methods to create a public webserver (not using localhost). Then the issue becomes how to start the webserver on Cloud Shell.
Except for experimenting you are using the wrong services (Cloud Shell).

Opening the browser from Python running in Google Cloud Shell

I'm developing a small script on Python 3.6, and I'll most likely use it from Google Cloud Shell. In said script, I want to do some API calls, and then, open the web browser with an URL, result of those calls. The following code works in other environments that I have tested on, but not in Cloud Shell:
import webbrowser as wb
# different calls and process here, not relevant to the issue
wb.open('URL_HERE')
#This just echoes the URL.
Is there anyway to make Python 'tell' Cloud Shell to use the browser from where it's running? i.e: if I'm using Chrome to open Cloud Shell, is there any way to open the link in Chrome? It doesn't matter if it's with webbrowser or other library.
Cloud Shell is just a “window” displaying a command line from a remote and temporary Compute Engine virtual machine instance. Meaning that when you run the script, you are actually running it in the remote VM (not in Chrome), and that specific VM does not have a browser by itself.
For example, when you try to run an app in Cloud Shell (here you can find a quick example using "mvn appengine:run"), once the application is running, you will see a message in Cloud Shell, something like:
[INFO] GCLOUD: INFO: Module instance default is running at http://localhost:8080/
If you click on http://localhost:8080/ , you will actually be redirected to the temporary address assigned for the Cloud Shell VM instance (something like 8080-dot-VM-ID-devshell.appspot.com).
In summary, you can’t command Cloud Shell to open the browser with a specific URL shown in the remote VM command line. Also, you should consider that there are outgoing connections limitations and Cloud Shell is intended for interactive use only.

How could I prohibit anonymous access to my NodeRed UI Dashboard on IBM Cloud(Bluemix)?

I'm working with node-red, on boilerplate IBM cloud. I know that there is a way, changing the value of enviroments variables(NODE_RED_USERNAME and NODE_RED_PASSWORD), to change username and password of the editor flow. But, what about UI dashboard? I mean using dashboard nodes. Forbid access to
https://noderedservicename.mybluemix.net/ui/
I know that on the code, changing the variable httpNodeAuth on the file settings.js I can do what I want. What is the way for doing that on IBM Cloud?
Thank you in advance!
You need to add the httpNodeAuth (not the httpAdminAuth as this is for controlling access to the Node-RED editor and can done with the environment variables discussed in the other answer.) to the app/bluemix-settings.js file.
Something like this:
...
httpStatic: path.join(__dirname,"public"),
httpNodeAuth: {user:"user",pass:"$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN."},
functionGlobalContext: { },
...
Details of how to generate the pass can be found here
There are a number of ways you can edit the file, some of which include linking the Node-RED deployment to a git repository or downloading the whole app, editing the file and pushing it back to Bluemix (when you first deploy Node-RED from the starter pack it gives you instructions on how to download the source to make changes and then push them back. You can get to these instructions by clicking on the "Getting started" link in your Node-RED Bluemix console page).
But the quickest/simplest/dirtiest way is probably to just SSH into the instance and change the file with something like vi. Details on how to ssh to an app instance can be found here. But the following should work:
cf ssh [app name]
Once you have edited the file you will need to tell bluemix to restart the app. You can do this from the web console or with the cf command line tool.
(The changes made by this method will not survive if the app is restaged, or bluemix decides to move your instance to another machine internally because it will rebuild the app from the pushed sources. The permanent solution is to download the source, edit and push back)
This link will help you but it's written in Japanese.
http://dotnsf.blog.jp/archives/1030376575.html
Summary
You can define the "user-defined" environment variables through the IBM Cloud dashboard.
It contains the variables to protect Node-RED GUI.
You have to be set as follows
NODE_RED_USERNAME : username
NODE_RED_PASSWORD : password

Resources