Is there any possible way to log the name of the Lambda in CloudWatch ?
Ex:
START RequestId: 4b453a3-f239-461f-94ab-ebesdfsdb04de Version: $LATEST
The "RequestId" is already getting logged. Any property I can use to log the name of the lambda as well ?
I don't want an explicit console.log statement but a property/parameter which directly gives out my lambda's name along with START , END and INFO fields.
You should be using context property (function_name).
def lambda_handler(event, context):
print("lambda function: {}".format(context.function_name))
Please refer below link for more details.
You coud use environment variable AWS_LAMBDA_FUNCTION_NAME (see full list). If your Lambda are written on Python it could looks like this:
import os
def lambda_handler(event, context):
print("Running function '%s'" % os.environ.get('AWS_LAMBDA_FUNCTION_NAME', None))
could do this in nodejs
console.log(process.env.AWS_LAMBDA_FUNCTION_NAME)
Related
I have a conftest.py file looking like this:
from testdevice import TestDevice
from pytest import fixture
def pytest_addoption(parser):
parser.addoption("--n", action="store", default="Name")
#fixture()
def name(request):
return request.config.getoption("--n")
def pytest_configure(config):
"""
Allows plugins and conftest files to perform initial configuration.
This hook is called for every plugin and initial conftest
file after command line options have been parsed.
"""
def pytest_sessionstart(session):
"""
Called after the Session object has been created and
before performing collection and entering the run test loop.
"""
name = 'device_name'
TestDevice(name)
def pytest_sessionfinish(session, exitstatus):
"""
Called after whole test run finished, right before
returning the exit status to the system.
"""
def pytest_unconfigure(config):
"""
called before test process is exited.
"""
I am testing an embedded device, using ssh in the tests. Before the test I want to prepare the device, using the class TestDevice(name). "name" is the key of a dictionary containing device information.
Instead of hardcoding name in sessionstart. I have created a fixture where i can access the name argument, however I am only able to use the fixture in the tests. I am not able to access the fixture in "pytest_sessionstart", as i am not able to access the "request" argument.
Can anything be done to access the python arguments on "pytest_sessionstart"?
You don't have to use an extra fixture.
You can get name in pytest_sessionstart via session object:
def pytest_addoption(parser):
parser.addoption("--n", action="store", default="Name")
def pytest_sessionstart(session):
name = session.config.getoption('--n'):
TestDevice(name)
In Discord.py, we have created a command to banish a user. However, the result is output as Nameerror: name'app' is not definded. This is my code.
Do you have any problems with #app.command?
I use client run instead of app run.
#app.command(name="<<kick", pass_context= True)
#commands.has_permissions(administrator=True)
async def _kick(ctx, *, username: discord.Member, reason=None):
await user_name.kick(reason=reason)
await ctx.send(str(user_name) + '\n```User was kick!```')```
If you use client.run you also have to use #client.command(...).
Judging from your comments, you're using a discord.Client instead of a commands.Bot. If you want to use the commands module, you need to use commands.Bot instead.
So I'm making an afk command, and I want to store everything I type after !afk into the reason, instead of having to put "" around it. Is there any way I can do this? Thanks in advance :)
The text after the command is passed on as all variables in your program you can get all of those with *args and merge them back into a sentence with ' '.join(args).
Example code:
bot.command()
async def afk(ctx, *args):
reason = ' '.join(args)
ctx.send(f'{ctx.author.name} has gone afk with the following reason: "{reason}", bye')
I have a inspec test, this is great:
inspec exec scratchpad/profiles/forum_profile --reporter yaml
Trouble is I want to run this in a script and output this to an array
I cannot find the documentation that indicated what method i need to use to simulate the same
I do this
def my_func
http_checker = Inspec::Runner.new()
http_checker.add_target('scratchpad/profiles/forum_profile')
http_checker.run
puts http_checker.report
So the report method seems to give me load of the equivalent type and much more - does anyone have any documentation or advice on returning the same output as the --reporter yaml type response but in a script? I want to parse the response so I can share output with another function
I've never touched inspec, so take the following with a grain of salt, but according to https://github.com/inspec/inspec/blob/master/lib/inspec/runner.rb#L140, you can provide reporter option while instantiating the runner. Looking at https://github.com/inspec/inspec/blob/master/lib/inspec/reporters.rb#L11 I think it should be smth. like ["yaml", {}]. So, could you please try
# ...
http_checker = Inspec::Runner.new(reporter: ["yaml", {}])
# ...
(chances are it will give you the desired output)
I have separated quite small Jenkins jobs.
Now I need to configure another job which depending on the selected by the user parameters (selected probably through checkboxes?) will execute some of them.
I would like to start them from Powershell or Bash or Groovy script. Is it possible?
If you are using Groovy in a Postbuild/pipeline step, you can start the job via the Jenkins API.
For example, something like this for parameterless builds:
import hudson.model.*
Jenkins.instance.getItem("My Job").scheduleBuild(5)
And something like this for parameterized builds:
import hudson.model.*
Jenkins.instance.getItem("My Job").scheduleBuild( 5, new Cause.UpstreamCause( currentBuild ), new ParametersAction([ new StringParameterValue( "My Parameter Name", "My Parameter Value" ) ]));
You can also use the Jenkins Rest API for the rest. For example, by hitting the following url:
Parameterless:
curl -X POST JENKINS_URL/job/JOB_NAME/build
Parameterized:
curl -X POST JENKINS_URL/job/JOB_NAME/buildWithParameters?MyParameterName=MyParameterValue
sample:
import hudson.model.*
def actions=[]
def plist=[ ];
["ok":"ok","label":"master"].each {k,v->
plist << new hudson.model.StringParameterValue(k,"$v","");
}
actions.add(new hudson.model.ParametersAction(plist));
def future = Jenkins.instance.getItemByFullName("samples/testPipeline").scheduleBuild2(0,actions as hudson.model.Action[] );
future.get().getLog()