How do I create a serverless template from a local boiler template - aws-lambda

I have a boiler template saved in my local. How do I create a template using it? I tried the below command, but it did not work:
serverless create --template-path '.\Boiler plate\' --name UserRegistration
I got the following error:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at validateString (internal/validators.js:120:11)
at Object.join (path.js:375:7).....
.........
None of the solutions I find online worked for me.

The error says the serverless command argument path is undefined. On the serverless create documentation page, there is an example listed that says:
serverless create --template-path path/to/my/template/folder --path path/to/my/service --name my-new-service
This will copy the path/to/my/template/folder folder into path/to/my/service and rename the service to my-new-service.
In order to solve your problem, you need to provide a valid template-path pointing to a local Serverless template and provide a 'target path' using --path to which your template will be copied. So you command will probably look like this:
serverless create --template-path '.\Boiler plate' --path /target/for/your/template.yml --name UserRegistration
Note: I haven't adjusted '.\Boiler plate\' in this command. Are you sure it's correct using a backslash \ after . ?

Related

Generating OpenAPI spec for Google Config Connector

I'm trying to use the Kube OpenAPI tool openapi-gen to generate OpenAPI specs for Google's Config Connector.
I'm relatively new to Go, so I'm not sure whether this is a configuration error on my part or if I'm simply using it wrong.
I've cloned the Kube OpenAPI repo, and inside of that directory I've cloned the Config Connector repo, for simplicity.
This is what's happening when I try to generate an OpenAPI spec file.
$ go run cmd/openapi-gen/openapi-gen.go -i ./k8s-config-connector/pkg/apis/serviceusage/v1beta1 -p foo.com/foo -h ./boilerplate/boilerplate.go.txt
E0811 16:45:57.516697 22683 openapi.go:309] Error when generating: TypeMeta, TypeMeta invalid type
2021/08/11 16:45:57 OpenAPI code generation error: Failed executing generator: some packages had errors:
failed to generate default in ./k8s-config-connector/pkg/apis/serviceusage/v1beta1.Service: TypeMeta: not sure how to enforce default for Unsupported
exit status 1
What's going on here?
Here are some troubleshooting steps:
1 - GOROOT variable should be set and point to root of go installation
2- Operator-sdk depended on it being exported as an environment variable. Run the below command
export GOROOT=$(go env GOROOT)
when using the operator-sdk, it is necessary to either (a) set GOROOT in your environment, or (b) use the same GOROOT that was used to build the operator-sdk binary.
Refer to the link for additional information.

How to pass parameters to sam template with override-parameters with optional parameters

I'd like to create a SAM template.yml containing lambda and several sqs's. I'd like to deploy it with parameters but not populate all the sqs's only some depending on the environment I need to deploy it on. How do I create a template with partial parameters populated?
I found how to do it in CloudFormation:
https://aws.amazon.com/blogs/infrastructure-and-automation/conditionally-launch-aws-cloudformation-resources-based-on-user-input/
And here's how to do it in SAM template:
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy.html
For SAM templates, see these docs also for setting parameter_overrides via a samconfig.toml file:
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html
You can specify the location of the config file with the --config-file /path/to/samconfig.toml argument.
Example samconfig.toml file with parameters configured:
version=0.1
[default.global.parameters]
parameter_overrides=[
"TemplateInput1=Value1",
"TemplateInput2=Value2"
]

DevOps : AWS Lambda .zip with Terraform

I have written Terraform to create a Lambda function in AWS.
This includes specifying my python code zipped.
Running from Command Line into my tech box, all goes well.
The terraform apply action sees my zip moved into AWS and used to create the lambda.
Key section of code :
resource "aws_lambda_function" "meta_lambda" {
filename = "get_resources.zip"
source_code_hash = filebase64sha256("get_resources.zip")
.....
Now, to get this into other environments, I have to push my Terraform via Azure DevOps.
However, when I try to build in DevOps, I get the following :
Error: Error in function call on main.tf line 140, in resource
"aws_lambda_function" "meta_lambda": 140: source_code_hash =
filebase64sha256("get_resources.zip") Call to function
"filebase64sha256" failed: no file exists at get_resources.zip.
I have a feeling that I am missing a key concept here as I can see the .zip in the repo - so do not understand how it is not found by the build?
Any hints/clues as to what I am doing wrong, gratefully welcome.
Chaps, I'm afraid that I may have just been over my head here - new to terraform & DevOps !
I had a word with our (more) tech folks and they have sorted this.
The reason I think yours if failing is becuase the Tar Terraform step
needs to use a different command line so it gets the zip file included
into the artifacts. tar -cvpf terraform.tar .terraform .tf tfplan
tar --recursion -cvpf terraform.tar --exclude='/.git' --exclude='.gitignore' .
.. it that means anything to you !
Whatever they did, it works !
As there is a bounty on this, I still going to assign it as I am grateful for the input !
Sorry if this was a it of a newbie error.
You can try building your package with terraform AWS lambda build module. As it has been very useful for the processTerraform Lambda build module
According to the document example, in the source_code_hash argument, filebase64sha256 ("get_resources.zip") needs to be enclosed in double quotes.
You can refer to this document for details.

Created openwhisk action but shows in guest as private java so can't call it

Trying to follow directions, I created an action in the vagrant image (e.g., after vagrant ssh) using this command:
wsk action create ProcessFuzzyMatch /vagrant/ildMicroServices-1.0.jar --main com.xxx.micro.services.ProcessFuzzyMatch
and I could see it was created:
wsk action list
actions
/guest/ProcessFuzzyMatch private java
however guest isn't listed as a package:
wsk package list /whisk.system
packages
/whisk.system/weather shared
/whisk.system/combinators shared
/whisk.system/websocket shared
/whisk.system/watson-translator shared
/whisk.system/samples shared
/whisk.system/watson-speechToText shared
/whisk.system/watson-textToSpeech shared
/whisk.system/slack shared
/whisk.system/github shared
/whisk.system/utils shared
and attempts to call the action via curl fail with authentication errors but this doesn't seem to be related to the request headers. Instead I guess it is related to the private java nature of the action I registered. I believe this because I can't use the wsk command to show the summary information for the action I'd registered:
wsk package get --summary /whisk.system/guest/ProcessFuzzyMatch
error: Unable to get package 'guest/ProcessFuzzyMatch': The requested resource could not be found. (code 364)
Is the proper sequence to first create a package then use that package when registering my action?
Thanks for any advice you can provide.
As you have a local build, guest is your default namespace name. The package is default (aka _) as you didn't specify one. You can find the name of your namespace using:
wsk namespace list
It's labelled private as it's yours and not published to the world.
You can invoke your action with:
wsk action invoke ProcessFuzzyMatch -r
If you wanted to put your action in a namespace, called say "demo", you'd use:
wsk package create demo
wsk action create demo/ProcessFuzzyMatch /vagrant/ildMicroServices-1.0.jar --main com.xxx.micro.services.ProcessFuzzyMatch
You can now invoke your action with:
wsk action invoke demo/ProcessFuzzyMatch -r
Finally running wsk activation poll in a separate terminal window is helpful to see what's going on when you invoke an action.
Have you tried using /guest/default/ProcessFuzzyMatch in your url instead of /guest/ProcessFuzzyMatch
The fully qualified name of the action must include its package name, which is "default" if the action is not in a named package.
In case of authentication errors, you need to pass the auth as header parameters using -H
curl -k -H "Authorization: Basic <encoded value>" https://<host>/api/v1/namespaces/guest/default/ProcessFuzzyMatch
You can also try to invoke action using wsk CLI and see if it is getting invoked or not.
wsk -i action invoke ProcessFuzzyMatch --result=true
You didn't create a package for your action. Actions in the default package which is what you created will not appear in the package listing.
Also you're listing a whisk.system namespace while creating the action in the guest namespace.
So if you want to put the action in the whisk.system package, you'll need to use that API key and create the package first.
wsk package create mypkg -u <whisk.system key>
wsk action create mypkg/ProcessFuzzyMatch ... -u <whisk.system key>
Otherwise you the guest key to get the action
wsk action get ProcessFuzzyMatch --summary
Or equally
wsk action get /guest/ProcessFuzzyMatch --summary
Note that summaries are currently not generated if an action does not have any annotations (see https://github.com/apache/incubator-openwhisk/issues/2270).
This answer turned out as a result of following all the other posts recommendations and trying different approaches. It took a while because I had to port all the file based functions to call Cloudant instead and because of the size of artifacts to be loaded and an issue with their attachments API in Java I had to use a workaround (because the data field returned empty).
I tried using the --web=true to avoid the security issues and that got me very close. However, while I got back a reply with 200 response code, the payload was empty (Content-Length: 0). So, I used the wsk invoke action with -v I was able to see how the call was being made locally within the vagrant VM, and was then able to get it to work from outside the VM.
Basically, these were the steps I followed:
wsk package create ild
to create my own package which becomes a child of /guest as shown with the command:
wsk package list
/guest/ild
Then I created my action based on the jar build using gradle (so it includes all dependent classes other than gson.JsonObject since that is already in the runtime environment).
wsk action create /guest/ild/ProcessFuzzyMatch /vagrant/ildMicroServices-1.0.jar --main com.xxx.ild.micro.services.ProcessFuzzyMatch --web true
Because my service expected a JsonObject containing text and workspaceID I ran the following command in the vagrant VM:
wsk action invoke -v -br ild/ProcessFuzzyMatch -p "text" "borken window" -p "workspaceID" "bc3d43ab-1529-41c8-8571-b7155e53e3ff"
And this showed the correct response. By examining the request headers I could see how the action was being referenced so I could then create a shell script to point to the host 192.168.33.13 from outside the VM.
The working shell scripts is shown below:
#! /bin/bash
curl -s -v -k https://192.168.33.13/api/v1/namespaces/guest/actions/ild/ProcessFuzzyMatch?blocking=true \
-H "Authorization: Basic MjNiYzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOjEyM3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A=" \
-X POST -H "Content-Type: application/json" \
-d '{"text":"borken window","workspaceID":"bc3d43ab-1529-41c8-8571-b7155e53e3ff"}'
The -X POST is not needed as POST is assumed. The Authorization was copied from what I'd seen in the headers from the version run on the localhost (in the VM) but it is the Base64 encoding of the ~/openwhisk/ansible/files/auth.guest content (when in the VM via "vagrant ssh" command). This could also have been passed as is using the -u parameter to curl.
In theory, the authentication should not have been required since the --web=true was used when registering the action, but I found it was needed when calling into the VM from outside. Without the header, it returns this error:
{
"error": "The resource requires authentication, which was not supplied with the request",
"code": 2259
* Connection #0 to host 192.168.33.13 left intact
}
I believe the key to getting the external call to work was providing the proper URI before the package/action name and ensuring the blocking=true parameter was passed:
https://192.168.33.13/api/v1/namespaces/guest/actions/
I will up vote all the other replies as they all helped me figure out what was required.

Custom templates with phpDocumentor 2

I've been trying to get a custom template to work with PHPDocumentor (2) without much luck. The documentation on their site is incomplete and I'm kind of stumped.
What I've done is downloaded a copy of a complete template and reference it in my command, like so:
php phpdoc.php
--template=/path/to/customtemplate/
-d /path/to/php/source/files
-t /path/to/generated/content/
The command runs fine: it generates the documentation correctly but appears to be ignoring the --template option - at least, any changes I make to the template files in the /customtemplate folder are ignored.
Anyone have any idea?
(Thanks in advance!)
Ben
Instead of declaring the template command on the CLI you might try changing your phpdoc.dist.xml configuration file so that it pulls the template name or path from there directly.

Resources