Documentation ¶
Index ¶
- Constants
- func GGStart(lh LambdaHandler)
- func GGStartWithOpts(option RuntimeOption, lh LambdaHandler, payload bool)
- func Log(level LogLevel, format string, args ...interface{})
- func Start(handler interface{})
- func StartWithOpts(option RuntimeOption, handler interface{}, payload bool)
- type APIRequest
- type ErrorResponseWriter
- type GreenGrassCode
- type LambdaContextSlim
- type LambdaHandler
- type LambdaInvokeType
- type LambdaInvokerAPI
- type LogLevel
- type QueueAPI
- type QueueFullPolicyOption
- type RequestReader
- type RequestStatus
- type ResponseWriter
- type RuntimeOption
- type Secret
- type SecretAPI
- type SecretsManager
- type ShadowAPI
Constants ¶
const ( // InvokeEvent specified that the invoke is asynchronously InvokeEvent = 0 // InvokeRequestResponse specifies that the invoke is synchronously (default) InvokeRequestResponse = 1 // InvokeReservedMax is reserved InvokeReservedMax = 2 // InvokeReservedPad is reserved InvokeReservedPad = 0x7FFFFFFF )
const ( // QueueFullPolicyOptionBestEffort sets publishing at best effort. QueueFullPolicyOptionBestEffort = 0 // QueueFullPolicyOptionAllOrError specifies that GGC will either deliver // messages to all targets and return request status GG_REQUEST_SUCCESS or // deliver to no targets and return a request status GG_REQUEST_AGAIN QueueFullPolicyOptionAllOrError = 1 // QueueFullPolicyOptionReservedMax max in enum QueueFullPolicyOptionReservedMax = 2 // QueueFullPolicyOptionReservedPad is reserved. QueueFullPolicyOptionReservedPad = 0x7FFFFFFF )
const ( // RequestStatusSuccess is when function call returns expected payload type RequestStatusSuccess = 0 // RequestStatusHandled is when function call is successfull, however // lambda response with an error RequestStatusHandled = 1 // RequestStatusUnhandled is when function call is unsuccessfull, // lambda exits abnormally RequestStatusUnhandled = 2 // RequestStatusUnknown is when system encounters unknown error. // Check logs for more details RequestStatusUnknown = 3 // RequestStatusRequestAgain is when function call is throttled, try again RequestStatusRequestAgain = 4 // RequestStatusReservedMax is last valid const for this type RequestStatusReservedMax = 5 // RequestStatusReservedPad is padding RequestStatusReservedPad = 0x7FFFFFFF )
const ( // LogLevelReservedNotSet is not used. LogLevelReservedNotSet = 0 //LogLevelDebug specifies debug output LogLevelDebug = 1 //LogLevelInfo specifies info output LogLevelInfo = 2 // LogLevelWarn specifies warn output LogLevelWarn = 3 //LogLevelError will error output LogLevelError = 4 // LogLevelFatal is fatal. System will exist LogLevelFatal = 5 //LogLevelReservedMax is last enum LogLevelReservedMax = 6 //LogLevelReservedPad for padding LogLevelReservedPad = 0x7FFFFFFF )
Variables ¶
This section is empty.
Functions ¶
func GGStart ¶
func GGStart(lh LambdaHandler)
GGStart will start a single threaded runtime and do callback onto the registered `LambdaHandler` with full payload.
Since single-threaded this function will freeze the current thread. If you want more control over the runtime and how decoding of `LambdaContextSlim` is done use `StartWithOpts` instead.
func GGStartWithOpts ¶
func GGStartWithOpts(option RuntimeOption, lh LambdaHandler, payload bool)
GGStartWithOpts will start the runtime and register the lambda function with options.
When the _payload_ parameter is set to `false` the `LambdaContextSlim.Payload` will be empty. In this case the `LambdaHandler` need to read request data itself using the `RequestReader` (using `NewRequestReader()` to create one).
func Start ¶
func Start(handler interface{})
Start takes a handler function. See lambda github project for valid signatures https://github.com/aws/aws-lambda-go/blob/f24acb29a08c3a45eb95e6cd4ae56fbfabf4f4a5/lambda/entry.go#L39
This will start the dispatcher on same thread and will freeze
func StartWithOpts ¶
func StartWithOpts(option RuntimeOption, handler interface{}, payload bool)
StartWithOpts starts the lambda runtime with the specified option and registers the lambda callback.
If payload is set to false, the data sent to the lambda may be retrievable by `NewRequestReader()`. This is good for lambdas that do not want any payload or if the payload is large and it is possible to process this in parts. Hence, memory requirements is much lower.
Documentation on lambda function layout: https://github.com/aws/aws-lambda-go/blob/f24acb29a08c3a45eb95e6cd4ae56fbfabf4f4a5/lambda/entry.go#L39
Types ¶
type APIRequest ¶
type APIRequest struct {
// contains filtered or unexported fields
}
APIRequest is a wrapper to hold a pointer for the request duration. This is used for all GreenGrass API invocations such as device shadow, secrets manager, publish.
func (*APIRequest) ClearError ¶
func (ar *APIRequest) ClearError() *APIRequest
ClearError clears any error state
func (*APIRequest) Error ¶
func (ar *APIRequest) Error() error
Error returns the last error occurred.
type ErrorResponseWriter ¶
type ErrorResponseWriter struct { }
ErrorResponseWriter writes a error response failure
func NewErrorResponseWriter ¶
func NewErrorResponseWriter() *ErrorResponseWriter
NewErrorResponseWriter creates a new error response writer.
type GreenGrassCode ¶
type GreenGrassCode int
GreenGrassCode is the error codes that the runtime returns
const ( // GreenGrassCodeSuccess returned when success. GreenGrassCodeSuccess GreenGrassCode = 0 // GreenGrassCodeOutOfMemory is returned when process is out of memory GreenGrassCodeOutOfMemory GreenGrassCode = 1 // GreenGrassCodeInvalidParameter is returned when input parameter is invalid GreenGrassCodeInvalidParameter GreenGrassCode = 2 // GreenGrassCodeInvalidState is returned when SDK is in an invalid state GreenGrassCodeInvalidState GreenGrassCode = 3 // GreenGrassCodeInternalFailure is returned when SDK encounters internal failure GreenGrassCodeInternalFailure GreenGrassCode = 4 // GreenGrassCode is returned when process gets signal to terminate GreenGrassCodeTerminate GreenGrassCode = 5 GreenGrassCodeReservedMax GreenGrassCode = 6 GreenGrassCodeReservedPad GreenGrassCode = 0x7FFFFFFF )
*
- @brief Greengrass SDK error enum *
- Enumeration of return values from the gg_* functions within the SDK.
type LambdaContextSlim ¶
LambdaContextSlim slim version of the lambda context
If the `LambdaHandler` is registered as payload set to `false` the _Payload_ field will not be populated and the `LambdaHandler` need to process the payload itself.
type LambdaHandler ¶
type LambdaHandler func(lc *LambdaContextSlim)
LambdaHandler is the handler function that processes incoming requests.
Register the LambdaHandler using either `Start` or `StartWithOpts`
.Example Single Threaded Registration [source,go] .... sdkc.Start(func(lc *sdkc.LambdaContextSlim) { // <1>
fmt.Printf("%s, %s\n", lc.ClientContext, lc.FunctionARN) // <2> fmt.Println("Payload: ", string(lc.Payload)) // <3>
}) .... <1>
type LambdaInvokeType ¶ added in v0.0.6
type LambdaInvokeType int
LambdaInvokeType specifies if the invoke is request / response or event based
type LambdaInvokerAPI ¶ added in v0.0.6
type LambdaInvokerAPI struct { APIRequest // contains filtered or unexported fields }
LambdaInvokerAPI is to invoke a lambda and possibly handle the result.
func NewLambdaInvokerAPI ¶ added in v0.0.6
func NewLambdaInvokerAPI() *LambdaInvokerAPI
NewLambdaInvokerAPI creates a new instance of the API to invoke GGC lambdas.
func (*LambdaInvokerAPI) GetLastResponse ¶ added in v0.0.6
func (li *LambdaInvokerAPI) GetLastResponse() string
GetLastResponse returns the last success response from an API call.
func (*LambdaInvokerAPI) Invoke ¶ added in v0.0.6
func (li *LambdaInvokerAPI) Invoke( functionARN, clientContext, functionVersion string, invokeType LambdaInvokeType, payload []byte) *LambdaInvokerAPI
Invoke invokes the specified lambda either request/response or event style.
The _functionARN_ is the full lambda ARN to be invoked and the _clientContext_ is a base64-encoded null-terminated json string.
.Example clientContext [source,json] ....
{"custom": {"value": "key"} } <1>
.... <1> This translates to _clientContext_ of "eyAiY3VzdG9tIjp7ICJ2YWx1ZSI6ICJrZXkiIH19"
The _invokeType_ specifies if this is a fire and forget (event) or if it is a request / response. The _functionVersion_ is a string representing which version e.g. "2"
type QueueAPI ¶ added in v0.0.6
type QueueAPI struct {
APIRequest
}
QueueAPI handles publishing to MQTT through the local API
func NewQueueAPI ¶ added in v0.0.6
func NewQueueAPI() *QueueAPI
NewQueueAPI creates a new MQTT client
func (*QueueAPI) Publish ¶ added in v0.0.6
func (q *QueueAPI) Publish(topic string, option QueueFullPolicyOption, payload []byte)
Publish will publish a payload on provided topic.
func (*QueueAPI) PublishObject ¶ added in v0.0.6
func (q *QueueAPI) PublishObject( topic string, policy QueueFullPolicyOption, object interface{}) *QueueAPI
PublishObject will publish the object, marshalled as _JSON_, onto specified topic.
type QueueFullPolicyOption ¶
type QueueFullPolicyOption int
QueueFullPolicyOption specifies what to do when queue is full.
type RequestReader ¶
type RequestReader struct{}
RequestReader reads the lambda request data either iteratively (low memory footprint) or in full. It implements the `io.Reader` interface
func NewRequestReader ¶
func NewRequestReader() *RequestReader
NewRequestReader creates a new request reader.
.Example Usage [source,go] .... r := NewRequestReader() b := make([]byte, 256) for {
n, err := r.Read(b) if n > 0 { // process the b[:n] } if err == io.EOF { break } if err != nil { panic(err) } }
....
Or use the `ReadAll` from _ioutil_ package.
.Example ReadAll [source,go] ....
if buf, err := ioutil.ReadAll(NewRequestReader()); err == nil { // the complete request payload is in buf }
....
func (*RequestReader) Read ¶
func (r *RequestReader) Read(b []byte) (n int, err error)
Read implements the `io.Reader` interface method to read from the lambda request buffer.
When the read from buffer is done a `io.EOF` is returned.
NOTE: Even if `io.EOF` is returned, some data may exist in buffer to be handeled.
type ResponseWriter ¶
type ResponseWriter struct { }
ResponseWriter is writes a success response payload
func NewResponseWriter ¶
func NewResponseWriter() *ResponseWriter
NewResponseWriter creates a new response writer.
type RuntimeOption ¶
type RuntimeOption uint
RuntimeOption specifies how the runtime shall behave or initialized
const ( // RuntimeOptionSingleThread will start the runtime and register the lambda function and // process all request on the caller thread. RuntimeOptionSingleThread RuntimeOption = 0 // RuntimeOptionSeparateThread will start the runtime and register the lambda function in // a new thread. When the caller thread / main thread exits this runtime thread also exits. RuntimeOptionSeparateThread RuntimeOption = 1 )
type Secret ¶ added in v0.0.6
type Secret struct { // ARN is the ARN of the secret. ARN string // Name is the friendly name of the secret. Name string // VersionID is the unique identifier of this version of the secret. VersionID string `json:"VersionId"` // SecretBinary is the decrypted part of the protected secret information that was originally provided as // binary data in the form of a byte array. This parameter is not used if the secret is created by the Secrets Manager console. // // If you store custom information in this field of the secret, then you must code your Lambda rotation function to parse and // interpret whatever you store in the _SecretString_ or _SecretBinary_ fields. SecretBinary []byte // SecretString is the decrypted part of the protected secret information that was originally provided as a string. // // If you create this secret by using the Secrets Manager console then only the “SecretString“ // parameter contains data. Secrets Manager stores the information as a JSON structure of // key/value pairs that the Lambda rotation function knows how to parse. // // If you store custom information in the secret by using the CreateSecret , UpdateSecret , or // PutSecretValue API operations instead of the Secrets Manager console, or by using the // *Other secret type* in the console, then you must code your Lambda rotation function to // parse and interpret those values. SecretString string // VersionStages is a list of all of the staging labels currently attached to this version of the secret. VersionStages []string // Creates is the date and time that this version of the secret was created. CreatedDate *time.Time }
Secret represents a single secret obtained from the green grass secrets manager.
type SecretAPI ¶ added in v0.0.6
type SecretAPI struct { APIRequest // contains filtered or unexported fields }
SecretAPI encapsulates local secret manager communication.
func NewSecretAPI ¶ added in v0.0.6
func NewSecretAPI() *SecretAPI
NewSecretAPI creates a new instance of the local api communication towards the secrets manager.
func (*SecretAPI) GetLastResponse ¶ added in v0.0.6
GetLastResponse returns the last success response from an API call.
func (*SecretAPI) GetSecret ¶ added in v0.0.6
GetSecret calls the secrets manager lambda to obtain the requested secret value.
The _secretID_ specifies the secret containing the version that you want to retrieve. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret.
_VersionID_ Specifies the unique identifier of the version of the secret that you want to retrieve. If you specify this parameter then don't specify _VersionStage_. If you don't specify either a _VersionStage_ or _SecretVersionId_ then the default is to perform the operation on the version with the _VersionStage_ value of _AWSCURRENT_. This value is typically a UUID-type value with 32 hexadecimal digits.
The _VersionStage_ Specifies the secret version that you want to retrieve by the staging label attached to the version. Staging labels are used to keep track of different versions during the rotation process. If you use this parameter then don't specify _SecretVersionId_. If you don't specify either a _VersionStage_ or _SecretVersionId_ , then the default is to perform the operation on the version with the _VersionStage_ value of _AWSCURRENT_.
type SecretsManager ¶ added in v0.0.6
type SecretsManager interface { // GetSecret calls the secrets manager lambda to obtain the requested secret value. // // The _secretID_ specifies the secret containing the version that you want to retrieve. You can specify either the // Amazon Resource Name (ARN) or the friendly name of the secret. // // _VersionID_ Specifies the unique identifier of the version of the secret that you want to retrieve. If you // specify this parameter then don't specify _VersionStage_. If you don't specify either a _VersionStage_ or // _SecretVersionId_ then the default is to perform the operation on the version with the _VersionStage_ value of _AWSCURRENT_. // This value is typically a UUID-type value with 32 hexadecimal digits. // // The _VersionStage_ Specifies the secret version that you want to retrieve by the staging label attached to the version. // Staging labels are used to keep track of different versions during the rotation process. If you use this parameter then // don't specify _SecretVersionId_. If you don't specify either a _VersionStage_ or _SecretVersionId_ , then the default // is to perform the operation on the version with the _VersionStage_ value of _AWSCURRENT_. GetSecret(secretID, versionID, versionStage string) (*Secret, error) }
SecretsManager is a interface to interact with the green grass secrets manager.
type ShadowAPI ¶
type ShadowAPI struct { APIRequest // contains filtered or unexported fields }
ShadowAPI encapsulates communication with the device shadow API.
func (*ShadowAPI) GetLastResponse ¶
GetLastResponse returns the last success response from an API call.