mrserverless / serverless-golang

AWS Lambda Go functions using Serverless Framework and Python shim
Other
302 stars 21 forks source link

Custom headers from golang #2

Closed iNDicat0r closed 7 years ago

iNDicat0r commented 7 years ago

Hi

How can i set a custom header within the golang runtime?

Regards

cristim commented 7 years ago

It's not yet supported by this example, I will make a pull request that adds support for it.

iNDicat0r commented 7 years ago

Awesome, will be waiting to see it!

cristim commented 7 years ago

I'm working on it at https://github.com/cristim/serverless-golang/tree/aws-lambda-go-shim, still not ready yet, the header is somehow lost, likely filtered by the API Gateway

iNDicat0r commented 7 years ago

My understanding is that the lambda response to the API gateway should contain the header value. In nodejs its set using the context object, however if i understood correctly the go binary gets the event object as stdin and does return the final value of the object as the stdout.

This sounds like the context should be set within the python environment..

cristim commented 7 years ago

@fsenart replied this and said it should work:

You have to send headers before writing the first ever byte in body so exchange the two lines and it should be ok

mrserverless commented 7 years ago

I've merged PR #3 for now and will look at making both lambda-go-shim and lambda-go-net available in the same project in the future.

cristim commented 7 years ago

I think this can be closed, extending the example to a multi-function configuration should be tracked in a new issue.

mrserverless commented 7 years ago

Thanks @cristim. Will close this for now if everyone is happy. Would like provide an example for custom header using go-shim context but will do this as separate ticket. #4 perhaps.

cristim commented 7 years ago

@fsenart, are you aware of any issues with the context objects?

fsenart commented 7 years ago

@cristim no! @yunspace can you please explain me what is the problem you encounter with the context?

mrserverless commented 7 years ago

hi @fsenart sorry for the confusion, the issue is to provide an example of setting custom header using context rather than context not working. My bad, I have re-phrased.

mrserverless commented 7 years ago

FYI custom headers can also be set via go lambda events instead of go lambda net: https://github.com/yunspace/serverless-golang/blob/master/aws/event/event_handler.go#L16