I'm trying to create a CDK app that will deploy a pipeline-stack and a lambda-stack. Similar to the tutorial here. I'm trying to implement a basic CI/CD application that is triggered with every push to a Github Enterprise Repo.
I chose to use PythonFunction from (#aws-cdk/aws-lambda-python) instead of function from #aws-cdk/aws-lambda because PythonFunction builds the dependencies from requirements.txt. I have various lambdas that use different packages (like awswrangler, pandas, requests, etc.).
But, PythonFunction does not support CfnParametersCode (Where the code is passed through CDK instead of being read from an asset).
What other option do I have to pass my code from GithubEnterprise to
the PythonFunction?
If function from #aws-cdk/aws-lambda is the only option I have, how
can I include the packages from requirements.txt
This does seem like an option for #aws-cdl/aws-lambda, but how would I pass my code from Github? This example relates to building from asset code.
I apologize if I'm missing something obvious, I just started working with AWS CDK last week.
First of all I would recommend to take a look at pipelines.CdkPipeline which is able to deal with Assets. That means you can directly use lambda.Code.from_asset instead of overriding CfnParametersCode in the Pipeline.
Regarding your other question, you can deal with the requirements by installing them into your lambda folder during the build step with: pip install -r requirements.txt -t .
CfnParametersCode gives you the ability to upload your code from an S3 file.
You can do the same via lambda.Code.fromBucket.
Taking your link from the third point (https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda#bundling-asset-code) You just need to use lambda.Code.fromBucket instead of code: lambda.Code.fromAsset. Docs can be found here: https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda
Related
I am trying to find a portable way to produce code annotations for GitHub in a way that would avoid a vendor-lockin.
Mainly I want to dump annotations inside a file (yaml, json,...) during build process and have a task at the end that does transform this file into github annotations.
The main goal here is to avoid hardcoding support for github-annotation into the tools that produce them, so other CI/CD systems could also consume the annotation-reports and display them in their UI.
linters -> annotations.report -> github-upload
Tools like flake8 are able to produce output in parsable format file:line:column: message, but I need to know if there is any attempt to standardize annotations so we can collect and combine them from multiple tools and feed them to the CI/CD engine.
Today I googled up what the heck those "Github Action Annotations" are all, and this was among the hits:
https://github.com/marketplace/actions/annotations-action
GitHub action for creating annotations from JSON file
As of now that page also contains:
This repository uses npm packages from #attest scope on github; we are working hard to open source these packages.
Annotations Action is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.
I didn't try it, again, just a random google hit.
I am currently using https://github.com/yuzutech/annotations-action
Sample action code:
- name: Annotate
uses: yuzutech/annotations-action#v0.3.0
with:
repo-token: ${{secrets.GITHUB_TOKEN}}
input: ./annotations.json
title: 'Findings'
ignore-missing-file: true
It does its job well but with one minor defect. If you have a findings on a commit/PR you get to see the finding with a beautiful annotation right where you need it. If you re-push changes, even if the finding persists, the annotation is not displayed on later commits. I have opened an issue but I have not yet received an answer.
The annotations-action mentioned above has not been updated and it does not work with me at all (deprecated calls).
I haven't found anything else that worked exactly as I wanted it to.
Update: I found that you can use reviewdog to annotate based on findings. I also created a GitHub action that can be used for Static Code Analysis here https://github.com/tsigouris007/action-semgrep-reviewdog. You can visit the entrypoint.sh file and check how I piped the custom output to reviewdog utilizing jq.
I wrote a small app returning routes with my public transport.
I'd like to package the app and use it via cli like: $ app_name start destination which is than handled by the app etc.
I've used the entry_points option in setup.py by defining an interface file, which is referenced when running the above code from command line.
However, I do not know if that's a best practice to accomplish that (as I have not found it on python.org.
So: What is a best practice to provide a cli?
An example I've seen:
with pytube you can do
$ pytube http://youtube.com/watch?v=9bZkp7q19f0 --itag=22
[EDIT:] thanks for the comments so far; they hint me to rephrase my question
I am a new NativeScript user and I am trying to understand how to have my app make a GET call to a remote server, depending upon environment. In Java world we pass in an environment variable, but I have not found an example (that I understand) demonstrating how my NativeScript mobile app will know which environment it is running in, and how to get values based upon that.
I am presuming that I will have a config/ with files such as
prod.conf.js and dev.conf.js - and there is where I will put in my urls and other config values.
How do I get my NativeScript (which I will eventually build into iOS) to reach those values to use in an http request upon startup. Any example to direction to documentation would be greatly appreciated.
Answer:
I finally got the problem solved by using Manoj suggestion of nativescript-dev-appconfig. For any newbie looking for help, try this:
{PROJECT_ROOT}/config - create the environment files as {env}.json. These files are just json, with name-value pairs of the values you want. In may case that is
When you do your build: tns build ios --bundle --env.config {dev | test | prod }
This will take the contents of the selected env.config file (ie -env.config dev and copy it as - {PROJECT_ROOT}/app/config.json .
To use it within your code,
import config from "../config.json";
axios.get(config.MY_URL).then(result => {...}
Unfortunately using environment based config files are not officially supported but there is a plugin hook you could try.
We also have webpack based environment variable support, read more about that in the docs.
So I am learning how to create alexa skills and I have create two sucessfully following the steps below but for some reason when I follow these steps now I am missing the node_modules folder and the package.json. This is causing the following error when I test my skill:
Unable to import module 'index': Error
The steps I am following are:
- go to the aws console select lambda
- select create new function
- blueprints -> select alexa-skill-kit-sdk-factskill -> configure
- select existing role -> lambda_basic_execution
- create function
It was my understanding that the alexa-skill-kit-sdk-factskill came with these dependencies. Is there a way to add them in manually if so how? I have tried to find a console but I don't see where that is in the lambda workspace.
Here is a screen shots of the project where it did add the folder and json file
Here is on of my current project
I have had this problem, but unfortunately, Lambda console doesn't give us console to install nodejs dependencies.
So, you have to actually deploy your lambda function. There are many ways to do that, but more popular are:
Node Lambda package (for node)
Create ZIP and deploy it in console (Not recommended because of size limitation)
AWS CLI
As you're learning the Alexa Skills, I would suggest you the way Amazon suggests devs to create and organise Alexa Skill and Lambda function.
Use ASK CLI
For creating new Alexa Skill.
This will create a directory, which will have:
Skill's intent Schema
Skill's lambda function
Plus, you can pass a template to create skill for a specific template. Here is list of templates created by Amazon devs.
For eg, command for creating Skill code, for a fact-template skill
ask new [--template [template-name] [--url <url>]]
[-n|--skill-name <name>]
[-p| --profile <profile>] [--lambda-name <lambda-name>]
Using ASK CLI, will give you the advantage of deploying your skill and lambda simultaneously.
I know ASK CLI is a lot to take in so quickly, but once you get the hang of it, it is a very useful tool for Alexa developers.
You can zip the whole directory content locally and upload the zip to
lambda. But yeah you can't edit the code in the console then.
Remember that your handler file name must be mentioned as it is in Handler section.
Like if your file name is app.js then app.handler.
I'm using a AWS Lambda function to merge PDF files stored on S3. In addition to that, I need now to create a PDF file (from HTML and CSS). I was trying to use wkhtmltopdf, but it seems that I would have to install it using apt-get install (which I don`t think I have access on AWS Lambda).
Any ideas on how can I do it?
Any suggestions for wkhtmltopdf replacements?
Thanks!
There are multiple projects on GitHub claiming to run wkhtmltopdf on Lambda. Here are a few.
https://github.com/lubos/aws-lambda-wkhtmltopdf
https://github.com/dimiro1/lambda-wkhtmltopdf
https://github.com/jpaolin/aws-lambda-s3-wkhtmltopdf
Include the wkhtmltopdf binary and making sure it has execution permission(chmod 755). Add the binary path to your language runtime. e.g. with nodejs
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'] + '/bin/linux';
There is a specific download of wkhtmltopdf for use with AWS Lambda.
It is meant to be used as a separately uploaded Layer.
Upload the binary inside a folder of your project for example in a folder "binary /" so that at the time of lambda execution you can call it by reference
Important caveat: If you want to use wkhtmltopdf successfully on AWS Lambda, you will need to use v0.12.4.
It turns out that newer versions have some issues with dynamic libraries. If you drill into it, you'll find some .so files missing.
Source: Richard Keller