Debug scenario for lambda - node.js

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

Related

Using pyautogui.screenshot in AWS Workspaces

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.

How do I add environment variables to a AWS Lightsail Node.js instance?

The Problem
I'm dipping my toes into AWS by deploying a simple API built with NestJS. This will be the first app I've deployed to a cloud service. I've already cloned my repository on an AWS Lightsail Linux instance with Node.js and installed all of my dependencies. However, I'm confused on how best to provide environment variables to my app.
Obviously, I has a local .env file that I used during development with credentials for my database, port info, etc. Do I just create a new .env file on the machine running my instance through the command line? I've read that for other AWS services you can provide env variables through that service's UI, but I can't find the same thing for Lightsail.
I would greatly appreciate it if someone could give me an explanation of env variables, and how we should generally provide them to cloud services.
Thank you!
There could be a better method. But, you could add a file locally on the LightSail server itself. If you don't know how to do so through console, I'll explain below.
Create the file: touch .env
Open up the file in console: vim .env.
Now you will see the file opened up in console, with weird UI if you haven't seen it before.
Prepare to write to file: press i.
Now you should see a the ~Insert~ mode appear at the bottom.
Add the variables: copy and paste your .env from your local laptop to your lightsail console.
close out: press esc, then type in :wq, and click on enter
This should work as normal with any .env file. I'm unsure if there are security issues with this, but I don't believe so.

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

Post-build actions in Python/Linux webapp do not run

I have a Django-based web app deployed from Github, running in Python 3.9. The app deploys and starts successfully.
I need to add post-build actions to complete the deployment; the exceeding common Django task of running "manage.py". Following the general and python-specific docs I have added the an app setting of
POST_BUILD_SCRIPT_PATH=postbuild.sh
There is a shell script, postbuild.sh in the root of my app, which runs fine if I SSH into the running container. The expected behaviour is that after deployment, this should run, and output to the deployment log. Neither of these things happen.
I have tested the app setting POST_BUILD_COMMAND with a very simple echo, and that does nothing either.
Can you tell me either what I need to do to make these app settings work, or suggest an alternative method of running the post-build script?
Please note that this is a Linux app using Oryx, so answers concerning Windows/Kudu like this one aren't related.
I noticed you asked your question over here as well. Your setting needs to be set to a relative path, /postbuild.sh.

How to Save Images from A Program Ran from Ubuntu Application Start-up Command

We're trying to run a program at start with Ubuntu's Application Start-up command. We're successfully starting the camera and viewing the images. But the images are not saving to the folder we expect them to be saved too.
The program works flawlessly when started manually from the terminal. Saving into the appropriate folder.
Does anyone have any idea of how to get the images saved but when started from the Application Start-up command upon start-up?
Thanks.
You're not providing a whole lot of details, so my answer may be totally off. To me it sounds like you've created an app that takes a picture with the webcam and saves it to disk. Now you want the app run it when the user logs in, so you've added your app to the list of Startup Applications. The app starts, takes a picture, but can't write it do disk. If that's the case, I'd consider:
Try adding debug logging to your app, so you can see why it fails opening the file. What ever language this app is written in, if opening a file fails, the API will tell you. This information is vital. The easiest is to print to stdout and then, when starting the app, forward it to a log .e.g. /usr/local/bin/myapp &>> /tmp/myapp.log.
Try writing to a location like /tmp where permissions aren't that much of an issue.
Try adding a delay before starting the app, see this list of various approaches on how to do this, the most simple being using this a the command: sleep 10 ; /usr/local/bin/myapp &>> /tmp/myapp.log
If this is all rubbish you need to add more details in your question.

Resources