github.com/mweagle/Sparta@v1.15.0/docs/reference/apigateway/index.xml (about) 1 <?xml version="1.0" encoding="utf-8" standalone="yes"?> 2 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 3 <channel> 4 <title>Sparta - AWS Lambda Microservices</title> 5 <link>/reference/apigateway/</link> 6 <description>Recent content on Sparta - AWS Lambda Microservices</description> 7 <generator>Hugo -- gohugo.io</generator> 8 <language>en-US</language> 9 <lastBuildDate>Wed, 09 Mar 2016 19:56:50 +0100</lastBuildDate> 10 11 <atom:link href="/reference/apigateway/index.xml" rel="self" type="application/rss+xml" /> 12 13 14 <item> 15 <title>Echo</title> 16 <link>/reference/apigateway/echo_event/</link> 17 <pubDate>Wed, 09 Mar 2016 19:56:50 +0100</pubDate> 18 19 <guid>/reference/apigateway/echo_event/</guid> 20 <description>To start, we&rsquo;ll create a HTTPS accessible lambda function that simply echoes back the contents of incoming API Gateway Lambda event. The source for this is the SpartaHTML. 21 For reference, the helloWorld function is below. 22 import ( awsLambdaEvents &#34;github.com/aws/aws-lambda-go/events&#34; spartaAPIGateway &#34;github.com/mweagle/Sparta/aws/apigateway&#34; ) func helloWorld(ctx context.Context, gatewayEvent spartaAWSEvents.APIGatewayRequest) (*spartaAPIGateway.Response, error) { logger, loggerOk := ctx.Value(sparta.ContextKeyLogger).(*logrus.Logger) if loggerOk { logger.Info(&#34;Hello world structured log message&#34;) } // Return a message, together with the incoming input.</description> 23 </item> 24 25 <item> 26 <title>Request Parameters</title> 27 <link>/reference/apigateway/request_params/</link> 28 <pubDate>Wed, 09 Mar 2016 19:56:50 +0100</pubDate> 29 30 <guid>/reference/apigateway/request_params/</guid> 31 <description>Request Parameters This example demonstrates how to accept client request params supplied as HTTP query params and return an expiring S3 URL to access content. The source for this is the s3ItemInfo function defined as part of the SpartaApplication. 32 Lambda Definition Our function will accept two params: 33 bucketName : The S3 bucket name storing the asset keyName : The S3 item key Those params will be passed as part of the URL query string.</description> 34 </item> 35 36 <item> 37 <title>Request Context</title> 38 <link>/reference/apigateway/context/</link> 39 <pubDate>Wed, 09 Mar 2016 19:56:50 +0100</pubDate> 40 41 <guid>/reference/apigateway/context/</guid> 42 <description>This example demonstrates how to use the Context struct provided as part of the APIGatewayRequest. The SpartaGeoIP service will return Geo information based on the inbound request&rsquo;s IP address. 43 Lambda Definition Our function will examine the inbound request, lookup the user&rsquo;s IP address in the GeoLite2 Database and return any information to the client. 44 As this function is only expected to be invoked from the API Gateway, we&rsquo;ll unmarshall the inbound event:</description> 45 </item> 46 47 <item> 48 <title>CORS</title> 49 <link>/reference/apigateway/cors/</link> 50 <pubDate>Wed, 09 Mar 2016 19:56:50 +0100</pubDate> 51 52 <guid>/reference/apigateway/cors/</guid> 53 <description>Cross Origin Resource Sharing defines a protocol by which resources on different domains may establish whether cross site operations are permissible. 54 Sparta makes CORS support a single CORSEnabled field of the API struct: 55 // Register the function with the API Gateway apiStage := sparta.NewStage(&#34;v1&#34;) apiGateway := sparta.NewAPIGateway(&#34;SpartaHTML&#34;, apiStage) // Enable CORS s.t. the S3 site can access the resources apiGateway.CORSEnabled = true Setting the boolean to true will add the necessary OPTIONS and mock responses to all resources exposed by your API.</description> 56 </item> 57 58 <item> 59 <title>Slack SlashCommand</title> 60 <link>/reference/apigateway/slack/</link> 61 <pubDate>Wed, 09 Mar 2016 19:56:50 +0100</pubDate> 62 63 <guid>/reference/apigateway/slack/</guid> 64 <description>In this example, we&rsquo;ll walk through creating a Slack Slash Command service. The source for this is the SpartaSlackbot repo. 65 Our initial command handler won&rsquo;t be very sophisticated, but will show the steps necessary to provision and configure a Sparta AWS Gateway-enabled Lambda function. 66 Define the Lambda Function This lambda handler is a bit more complicated than the other examples, primarily because of the Slack Integration requirements. The full source is:</description> 67 </item> 68 69 <item> 70 <title>S3 Sites with CORS</title> 71 <link>/reference/apigateway/s3site/</link> 72 <pubDate>Wed, 09 Mar 2016 19:56:50 +0100</pubDate> 73 74 <guid>/reference/apigateway/s3site/</guid> 75 <description>Sparta supports provisioning an S3-backed static website as part of provisioning. We&rsquo;ll walk through provisioning a minimal Bootstrap website that accesses API Gateway lambda functions provisioned by a single service in this example. 76 The source for this is the SpartaHTML example application. 77 Lambda Definition We&rsquo;ll start by creating a very simple lambda function: 78 import ( spartaAPIGateway &#34;github.com/mweagle/Sparta/aws/apigateway&#34; spartaAWSEvents &#34;github.com/mweagle/Sparta/aws/events&#34; ) type helloWorldResponse struct { Message string Request spartaAWSEvents.APIGatewayRequest } //////////////////////////////////////////////////////////////////////////////// // Hello world event handler func helloWorld(ctx context.</description> 79 </item> 80 81 </channel> 82 </rss>