Skip to content

Instantly share code, notes, and snippets.

@cellofellow
Last active June 12, 2019 21:38
Show Gist options
  • Select an option

  • Save cellofellow/5acc263e85ff8899054aeff75b9443ca to your computer and use it in GitHub Desktop.

Select an option

Save cellofellow/5acc263e85ff8899054aeff75b9443ca to your computer and use it in GitHub Desktop.
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
GoogleLocationApiKey:
Description: Google Maps API Key
NoEcho: true
Type: String
Stage:
Default: dev
Description: The State to which to deploy Resources
Type: String
Resources:
ApiLambdaFunc:
Properties:
Code: .
Environment:
Variables:
DEPLOYMENT_STAGE: !Ref 'Stage'
FLASK_APP: google
FLASK_ENV: production
FunctionName: !Sub '${Stage}-GoogleGeoCode-API'
Handler: google.awslambda.handler
MemorySize: 1024
Role: !GetAtt 'LambdaRole.Arn'
Runtime: python3.7
Timeout: 30
TracingConfig:
Mode: Active
VpcConfig:
SecurityGroupIds:
- !ImportValue
Fn::Sub: ${Stage}-RDSSecurityGroup
SubnetIds: !Split
- ','
- !ImportValue
Fn::Sub: ${Stage}-PrivateSubnets
Type: AWS::Lambda::Function
BriteApiContribution:
Properties:
LambdaProxyArn: !GetAtt 'ApiLambdaFunc.Arn'
RestApiId: !ImportValue
Fn::Sub: ${Stage}-BriteAPI
ServiceToken: !ImportValue
Fn::Sub: ${Stage}-ApiContribution-Provider
SwaggerDefinition:
components:
schemas:
GoogleLocationAddress:
properties:
address_city:
type: string
address_country:
type: string
address_county:
type: string
address_line_1:
type: string
address_state:
type: string
address_types:
items:
type: string
type: array
formatted_address:
type: string
latitude:
format: float
type: number
longitude:
format: float
type: number
place_id:
type: string
postal_code:
type: string
type: object
GoogleLocationPong:
example:
pong: true
properties:
pong:
type: boolean
type: object
GoogleLocationRequest:
properties:
address:
description: Full address string
example: '2305 S Blackman Rd #200, Springfield, MO 65809'
type: string
required:
- address
type: object
info:
description: "Google's Geolocation address lookup service\n"
title: Google Location Integration
version: 1.0.0
openapi: 3.0.0
paths:
/integrations/google/location/geocode:
post:
operationId: GoogleLocationGeocode
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GoogleLocationRequest'
required: true
responses:
'200':
content:
application/json:
schema:
items:
$ref: '#/components/schemas/GoogleLocationAddress'
type: array
description: OK
summary: Get geolocation data for an address
/integrations/google/location/geocode/googleping/:
get:
operationId: GoogleLocationGooglePing
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/GoogleLocationPong'
description: OK
'502':
content:
application/json:
schema:
additionalProperties: true
type: object
description: FAIL
summary: Test connection to Google Location Service backend
/integrations/google/location/geocode/ping/:
get:
operationId: GoogleLocationPing
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/GoogleLocationPong'
description: OK
summary: Ping Google Location Service
tags: []
Version: '1.0'
Type: Custom::ApiContribution
GoogleGeoCodeGoogleLocationApiKeyParameter:
Properties:
Description: Google Maps API Key
Name: !Sub '/${Stage}/google/GoogleLocationApiKey'
Type: String
Value: !Ref 'GoogleLocationApiKey'
Type: AWS::SSM::Parameter
LambdaInvokePermission:
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref 'ApiLambdaFunc'
Principal: apigateway.amazonaws.com
Type: AWS::Lambda::Permission
LambdaRole:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
- events.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess
Policies:
- PolicyDocument:
Statement:
- Action:
- ssm:GetParameters
- ssm:GetParameter
Effect: Allow
Resource:
- !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${Stage}/google/*'
PolicyName: AllowGetSSMParams
Type: AWS::IAM::Role
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment