Sketch out an AWS CloudFormation based compilation of the vote50 app

This change adds a .mu/ directory to the vote50 app.  Inside are the "expected"
contents that the Mu compiler should output.  Eventually we will validate against
this that the (currently non-existent) compiler generates the correct thing.

This isn't complete, although I can manually create bits and pieces of the stacks
using CloudFormation.  More files will come; for example, the code packages.

In a nutshell:

    .mu/                                # Shared files agnostic to the cloud target
        aws-native-cf/                  # Files specific to the AWS CloudFormation target
            app.template.yaml           # The CloudFormation stack for the overall app
            services/                   # A directory containing service-specific stacks
                voting.template.yaml    # The CloudFormation stack for the VotingService
        services/                       # Service files agnostic to the cloud target
            voting.proto                # The gRPC definition for VotingService's API
        mu.yaml                         # The Mu package manifest (minimal for now)
This commit is contained in:
joeduffy 2016-10-15 12:18:28 -07:00
parent b1aa61e03d
commit 26968a3314
7 changed files with 185 additions and 0 deletions

View file

@ -0,0 +1,3 @@
This is an example of what the Mu compiler should output. As it comes online, we may decide to delete or keep this.
It's always valid to checkin the built artifacts, e.g. if a developer wants rigorous history, versioning, diffing, etc.

View file

@ -0,0 +1,10 @@
# TODO(joe): parameterize? (e.g., environment "prod" vs "stage" vs ...)
# TODO(joe): we are inferring "names" from variable assignments; should constructors require names?
# TODO(joe): schema for RPCs is currently weakly typed (because this is a JS example).
# TODO(joe): `new Table()` needs to take key parameters.
# TODO(joe): deal with cleaning up S3 resources after deployment?
# TODO(joe): we need to come up with a holistic IAM management scheme.
# TODO(joe): support more sophisticated settings for API gateway: private/auth, CORS, etc.
# TODO(joe): how to export resources for consumption in app.template?
# TODO(joe): should we use descriptions, etc.?

View file

@ -0,0 +1,48 @@
AWSTemplateFormatVersion: 2010-09-09
Parameters:
VotingServiceStack:
Type: String
Resources:
VoteAPI:
Type: AWS::ApiGateway::RestApi
Properties:
Name: voteAPI
VoteAPIVoteAL:
Type: AWS::ApiGateway::Method
Properties:
RestApiID:
Ref: VoteAPI
ResourceID:
Ref:
"Fn::GetAtt":
- VoteAPI
- RootResourceId
HttpMethod: POST
AuthorizationType: NONE
Integration:
Type: AWS
IntegrationHttpMethod: POST
Uri:
"Fn::Join":
- ""
- :
- "arn:aws:apigateway:"
- Ref: "AWS::Region"
- ":lambda:path/2015-03-31/functions/"
- "Fn::GetAtt":
- !ImportValue:
!Sub: "${VotingServiceStack}-VoteAPIFunction"
- Arn
- "/invocations"
IntegrationResponses: TODO(joe)
PassthroughBehavior: NEVER
RequestTemplates: TODO(joe)
RequestParameters: TODO(joe)
MethodResponses: TODO(joe)
Outputs:
ApiId:
Value:
Ref: VoteAPI
# TODO(joe): endpoints for AK, ..., WI, WY.

View file

@ -0,0 +1,10 @@
# upload code (TBD)
# create service stacks
aws cloudformation create-stack \
--stack-name mu-vote50-services-voting \
--template-body file://./services/voting.template.yaml \
--capabilities CAPABILITY_IAM \
--region $AWS_REGION \
--parameters ParameterKey=CodeBucket,ParameterValue=mu-vote50 ParameterKey=CodeObjectKey,ParameterValue=vote50.zip

View file

@ -0,0 +1,97 @@
AWSTemplateFormatVersion: 2010-09-09
Parameters:
CodeBucket:
Type: String
CodeObjectKey:
Type: String
Resources:
VotesTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: Color
AttributeType: S
KeySchema:
- AttributeName: Color
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
VoteCountsTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: Color
AttributeType: S
KeySchema:
- AttributeName: Color
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
VotingServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName:
!Sub: "${AWS::StackName}-VotingServiceRole"
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- arn:aws:logs:*:*:*
- Effect: Allow
Action:
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:Query
- dynamodb:UpdateItem
Resource: "*"
VotesTriggerFunction:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket:
Ref: CodeBucket
S3Key:
Ref: CodeObjectKey
Runtime: nodejs
Handler: app.services.voting.trigger
Role:
!GetAtt:
- VotingServiceRole
- Arn
VoteAPIFunction:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket:
Ref: CodeBucket
S3Key:
Ref: CodeObjectKey
Runtime: nodejs
Handler: app.services.voting.vote
Role:
!GetAtt:
- VotingServiceRole
- Arn
Outputs:
VoteAPIFunction:
Value:
Ref: VoteAPIFunction
Export:
Name:
!Sub: "${AWS::StackName}-VoteAPIFunction"

View file

@ -0,0 +1,2 @@
name: vote50

View file

@ -0,0 +1,15 @@
syntax = "proto3";
package vote50;
service VotingService {
rpc Vote(VoteRequest) returns (VoteResponse) {}
}
message VoteRequest {
string color = 1;
}
message VoteResponse {
}