Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python error with cgo lambda #64

Closed
angelabad opened this issue Jul 20, 2017 · 22 comments
Closed

Python error with cgo lambda #64

angelabad opened this issue Jul 20, 2017 · 22 comments

Comments

@angelabad
Copy link

Hello @mweagle, I am trying to switch to sparta cgo, but allways I get the same error in cloudwatch (I attach it)

Error: unknown command "/var/runtime/awslambda/bootstrap.py" for "python3.6"

I attach the provision -n log too, and you can see my go code in this branch:

cloudwatch_error.txt

Thanks in advance

@angelabad
Copy link
Author

provision command output with -n:

INFO[0000] ========================================
INFO[0000] Welcome to UnsplashTelegramBot-Devel GoVersion=go1.8.3 LinkFlags= Option=provision SpartaSHA=4a93bd5 SpartaVersion=0.13.0 UTC="2017-07-20T08:33:41Z"
INFO[0000] ========================================
INFO[0000] Provisioning service BuildID=398f4896d1b9301c2adeae538065dafa83acfb7d CodePipelineTrigger= InPlaceUpdates=false NOOP=true Tags=
INFO[0000] Verifying IAM Lambda execution roles
INFO[0000] IAM roles verified Count=1
INFO[0000] Bypassing S3 upload due to -n/-noop command line argument. Bucket=angelsparta VersioningEnabled=false
INFO[0000] Running go generate
INFO[0000] Building cgo library in Docker Args="[run --rm -v /home/angel/devel/golang:/usr/src/gopath -w /usr/src/gopath/src/github.com/angelabad/unsplash-telegram-bot -e GOPATH=/usr/src/gopath -e GOOS=linux -e GOARCH=amd64 golang:1.8.3 go build -o UnsplashTelegramBot_Devel.lambda.so -tags lambdabinary linux -buildmode=c-shared -tags lambdabinary noop ]" Name=UnsplashTelegramBot_Devel.lambda.so
INFO[0022] Executable binary size KB=18481 MB=18
INFO[0022] Creating code ZIP archive for upload TempName=/home/angel/devel/golang/src/github.com/angelabad/unsplash-telegram-bot/.sparta/UnsplashTelegramBot_Devel-code.zip
INFO[0023] Lambda function deployment package size KB=4929 MB=4
INFO[0023] Bypassing S3 upload due to -n/-noop command line argument Bucket=angelsparta File=UnsplashTelegramBot_Devel-code.zip Key=UnsplashTelegramBot-Devel/UnsplashTelegramBot_Devel-code-96f51ac1de427ef7e9f64f8580cfbeee63a30ba0.zip
INFO[0023] Checking current APIGateway stage status APIName=UnsplashTelegramBot-Devel StageName=prod
INFO[0023] Bypassing APIGateway check to -n/-noop command line argument
INFO[0023] Bypassing Stack creation due to -n/-noop command line argument Bucket=angelsparta TemplateName=UnsplashTelegramBot_Devel-cftemplate.json
INFO[0023] ----------------------------------------
INFO[0023] Summary
INFO[0023] ----------------------------------------
INFO[0023] Verifying IAM roles Duration (s)=0
INFO[0023] Verifying AWS preconditions Duration (s)=0
INFO[0023] Creating code bundle Duration (s)=23
INFO[0023] Uploading code Duration (s)=0
INFO[0023] Ensuring CloudFormation stack Duration (s)=0
INFO[0023] Total elapsed time Duration (s)=23
INFO[0023] ----------------------------------------

@mweagle
Copy link
Owner

mweagle commented Jul 23, 2017

Taking a look

@mweagle
Copy link
Owner

mweagle commented Jul 23, 2017

Hi @angelabad - I'm seeing some odd behavior with the sample app as well. The Lambda function fails to provision, but there is no error cause. Need to investigate further...

@angelabad
Copy link
Author

Ok, thanks for your work!

@mweagle
Copy link
Owner

mweagle commented Jul 29, 2017

I think this was a different manifestation of #63 - working on a release to resolve.

@mweagle
Copy link
Owner

mweagle commented Jul 29, 2017

@angelabad - Can you please regress with https://github.com/mweagle/Sparta/blob/master/CHANGES.md#v0131 and LMK if this resolves your issue? TIA.

@angelabad
Copy link
Author

Hi @mweagle, same error here, I attach cloudwatch error log

Thanks in advance!
error.txt

@mweagle
Copy link
Owner

mweagle commented Jul 30, 2017

🤔 - I'm not able to reproduce this. A few questions:

  • What AWS region are you deploying to?
  • What OS, docker version (docker -v) are you using?
  • Are you able to reproduce with the https://github.com/mweagle/SpartaPython/tree/master/cgo sample application?
    • Are you able to reproduce if you deploy to us-west-2 (this is the region I test against)
  • Can you share with me a provision --level debug log?

Thanks!

@mweagle
Copy link
Owner

mweagle commented Aug 3, 2017

Hi @angelabad - checking in to see if you've been able to make any progress on this issue. TIA.

@angelabad
Copy link
Author

Hi @mweagle, sorry for my delay.

  • What AWS region are you deploying to?

    • us-west-2
  • What OS, docker version (docker -v) are you using?

  • Are you able to reproduce with the https://github.com/mweagle/SpartaPython/tree/master/cgo sample application?

    • No, I uploaded this app and it worked fine, I think the problem is in my code, but viewing documentation I dont know where the error is :-(
  • Are you able to reproduce if you deploy to us-west-2 (this is the region I test against)

    • I use this region
  • Can you share with me a provision --level debug log?

Thanks in advance!

mweagle added a commit that referenced this issue Aug 12, 2017
@mweagle
Copy link
Owner

mweagle commented Aug 12, 2017

Hi @angelabad - I've pushed up https://github.com/mweagle/Sparta/tree/mweagle/0.13.3 that has a bit more error handling to help diagnose. Could you try with that branch and see if there's any more diagnostic information? Thanks!

@angelabad
Copy link
Author

Hi @mweagle, same error here :-(

I attach logs

Its possible the error be in my code? Here is my cgo branch:

Logs:

Cheers,

@mweagle
Copy link
Owner

mweagle commented Aug 12, 2017 via email

@mweagle
Copy link
Owner

mweagle commented Aug 15, 2017

Hi @angelabad - it seems like this code is expecting additional configuration. What command do you use to build? TIA.

@angelabad
Copy link
Author

Sorry, yo need a config.json in directory project, I attach a fake config.json.txt (rename it to config.json), you can use it to see the error in aws.

I build the project wth

$ go build

and provision it with

$ ./unsplash-telegram-bot provision -s bucket

Thanks for your attention

config.json.txt

@mweagle
Copy link
Owner

mweagle commented Aug 27, 2017

Hi @angelabad - I think I've found the issue. When building with cgo, Sparta uses the application's main() function and rewrites that to be the library init() function. You can see this if you build with --noop as in:

go build && ./unsplash-telegram-bot provision -s <BUCKET_NAME> --noop

and look at the ./sparta/main.go source.

In the current configuration, func main() is attempting to parse options that are supplied on the command line. In the Python AWS Lambda execution environment, that panics/os.Exits because those options aren't available.

There are a few ways to manage the build/deploy/execution contexts - can you help me understand what you're trying to accomplish with the command line options?

@angelabad
Copy link
Author

Hi @mweagle , I understand... I attach the generated .sparta/main.go.

I help it helps us.

Thanks in advance!

main.go.txt

@angelabad
Copy link
Author

Hi @mweagle I tested this issue with 0.20.0 and I got the same error :-(

Cheers

@mweagle
Copy link
Owner

mweagle commented Oct 5, 2017

Hi @angelabad - there isn't really a way for Sparta to better handle this situation. In the cgo world, your main function becomes init() and panics during library load due to the parsing error. What type of functionality are you trying to support? There might be another alternative.

@angelabad
Copy link
Author

Hi @mweagle, sorry for my delay. But I dont understand why my main function fails to convert in init() function. So I cant fox the error :-(

Cheers

@mweagle
Copy link
Owner

mweagle commented Nov 15, 2017

Your main function is properly transformed into an init function - the problem is when the .so is loaded during lambda execution. The library is loaded by a Python handler. When the library is loaded, your transformed init function executes:

func init() {

	err := parseConfig()
	if err != nil {
		log.Panic("Error parsing config ", err.Error())
	}

	parseErrors := sparta.ParseOptions(nil)
	if parseErrors != nil {
		os.Exit(2)
	}

	var StackName string
       ....

Since there isn't a configuration file available to load when running in AWS, the parseConfig function returns an error due to missing configuration information, and the library forcibly exits. This causes the Python handler to exit as well, since it can't load the library.

There are a few ways to make configuration information available to your function, including ArchiveHooks, KMS-wrapped values with SpartaVault or just via environment variables. Will one of those work for your use case?

@angelabad
Copy link
Author

Hi @mweagle, I understand it, sorry for the inconvenience.

I will try one of your alternatives.

Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants