Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added changes for MOD9 #51

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
124 changes: 124 additions & 0 deletions 09-lambda/9-1-2.yaml
@@ -0,0 +1,124 @@
AWSTemplateFormatVersion: "2010-09-09"

Parameters:
LambdaRoleName:
Type: String
Default: HelloLambdaRole
LambdaFunctionName:
Type: String
Default: SimpleHelloFunction
apiGatewayName:
Type: String
Default: my-api
apiGatewayStageName:
Type: String
AllowedPattern: "[a-z0-9]+"
Default: call
apiGatewayHTTPMethod:
Type: String
Default: POST

Resources:
HelloLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Ref LambdaRoleName
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole

HelloLambdaFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: HelloLambdaFunction
Role: !GetAtt HelloLambdaRole.Arn
Runtime: python3.7
Handler: index.my_handler
Code:
ZipFile: |
import json

def my_handler(event, context):
return {
'statusCode': 200,
'body': json.dumps('Hello AWS!')
}

ApiGatewayRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: ''
Effect: 'Allow'
Principal:
Service:
- 'apigateway.amazonaws.com'
Action:
- 'sts:AssumeRole'
Path: '/'
Policies:
- PolicyName: apilambdaaccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: lambda:InvokeFunction
Resource: !GetAtt HelloLambdaFunction.Arn

ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: !Ref apiGatewayName

ApiGatewayResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt ApiGatewayRestApi.RootResourceId
PathPart: 'lambda'
RestApiId: !Ref ApiGatewayRestApi

ApiGatewayMethod:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: POST
MethodResponses:
- StatusCode: "200"
AuthorizationType: AWS_IAM
Integration:
Type: AWS_PROXY
Credentials: !GetAtt ApiGatewayRole.Arn
IntegrationHttpMethod: POST
IntegrationResponses:
- StatusCode: "200"
Uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloLambdaFunction.Arn}/invocations'
OperationName: 'lambda'
ResourceId: !Ref ApiGatewayResource
RestApiId: !Ref ApiGatewayRestApi

ApiGatewayModel:
Type: AWS::ApiGateway::Model
Properties:
ContentType: 'application/json'
RestApiId: !Ref ApiGatewayRestApi
Schema: {}

ApiGatewayDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn: ApiGatewayMethod
Properties:
Description: Lambda API Deployment
RestApiId: !Ref ApiGatewayRestApi

ApiGatewayStage:
Type: AWS::ApiGateway::Stage
Properties:
DeploymentId: !Ref ApiGatewayDeployment
Description: Lambda API Stage v0
RestApiId: !Ref ApiGatewayRestApi
StageName: 'v0'

116 changes: 116 additions & 0 deletions 09-lambda/9-1-3.yaml
@@ -0,0 +1,116 @@
AWSTemplateFormatVersion: "2010-09-09"

Parameters:
LambdaRoleName:
Type: String
Default: HelloLambdaRole
LambdaFunctionName:
Type: String
Default: SimpleHelloFunction
apiGatewayName:
Type: String
Default: my-api
apiGatewayStageName:
Type: String
AllowedPattern: "[a-z0-9]+"
Default: call
apiGatewayHTTPMethod:
Type: String
Default: POST

Resources:
HelloLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Ref LambdaRoleName
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole

HelloLambdaFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: HelloLambdaFunction
Role: !GetAtt HelloLambdaRole.Arn
Runtime: python3.7
Handler: lambda_one.my_handler
Code: lambda_one.py

ApiGatewayRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: ''
Effect: 'Allow'
Principal:
Service:
- 'apigateway.amazonaws.com'
Action:
- 'sts:AssumeRole'
Path: '/'
Policies:
- PolicyName: apilambdaaccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: lambda:InvokeFunction
Resource: !GetAtt HelloLambdaFunction.Arn

ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: !Ref apiGatewayName

ApiGatewayResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt ApiGatewayRestApi.RootResourceId
PathPart: 'lambda'
RestApiId: !Ref ApiGatewayRestApi

ApiGatewayMethod:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: POST
MethodResponses:
- StatusCode: "200"
AuthorizationType: AWS_IAM
Integration:
Type: AWS_PROXY
Credentials: !GetAtt ApiGatewayRole.Arn
IntegrationHttpMethod: POST
IntegrationResponses:
- StatusCode: "200"
Uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloLambdaFunction.Arn}/invocations'
OperationName: 'lambda'
ResourceId: !Ref ApiGatewayResource
RestApiId: !Ref ApiGatewayRestApi

ApiGatewayModel:
Type: AWS::ApiGateway::Model
Properties:
ContentType: 'application/json'
RestApiId: !Ref ApiGatewayRestApi
Schema: {}

ApiGatewayDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn: ApiGatewayMethod
Properties:
Description: Lambda API Deployment
RestApiId: !Ref ApiGatewayRestApi

ApiGatewayStage:
Type: AWS::ApiGateway::Stage
Properties:
DeploymentId: !Ref ApiGatewayDeployment
Description: Lambda API Stage v0
RestApiId: !Ref ApiGatewayRestApi
StageName: 'v0'

135 changes: 135 additions & 0 deletions 09-lambda/9-2-1.yaml
@@ -0,0 +1,135 @@
AWSTemplateFormatVersion: '2010-09-09'

Parameters:
LambdaRoleName:
Type: String
Default: HelloLambdaRole
LambdaFunctionName:
Type: String
Default: SimpleHelloFunction
apiGatewayName:
Type: String
Default: my-api
apiGatewayStageName:
Type: String
AllowedPattern: "[a-z0-9]+"
Default: call
apiGatewayHTTPMethod:
Type: String
Default: POST

Resources:
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Handler: lambda.lambda_handler
Code: function/
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: python3.9

LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: FidelisLambdaExecutionRole
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: LambdaPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
Resource: !GetAtt DynamoTable.Arn
Effect: Allow

DynamoTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: FidelisMod9
AttributeDefinitions:
- AttributeName: Key1
AttributeType: S
KeySchema:
- AttributeName: Key1
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5

ApiGatewayRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: ''
Effect: 'Allow'
Principal:
Service:
- 'apigateway.amazonaws.com'
Action:
- 'sts:AssumeRole'
Path: '/'
Policies:
- PolicyName: apigw-lambda-access
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: lambda:InvokeFunction
Resource: !GetAtt LambdaFunction.Arn

ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: !Ref apiGatewayName

ApiGatewayMethod:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: ANY
Integration:
Type: AWS
Credentials: !GetAtt ApiGatewayRole.Arn
IntegrationHttpMethod: POST
IntegrationResponses:
- StatusCode: "200"
Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyLambda.Arn}/invocations"

OperationName: hello
ResourceId: !GetAtt ApiGatewayRestApi.RootResourceId
RestApiId: !Ref ApiGatewayRestApi
MethodResponses:
- StatusCode: "200"
AuthorizationType: AWS_IAM

ApiGatewayDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn: ApiGatewayMethod
Properties:
Description: Lambda API Deployment
RestApiId: !Ref ApiGatewayRestApi

Type: AWS::Lambda::Permission
Properties:
Action: lambda:invokeFunction
FunctionName: !Ref LambdaFunction
Principal: apigateway.amazonaws.com
SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiGatewayRestApi}"

Outputs:
RestApiId:
Value: !Ref ApiGatewayRestApi
Export:
Name: FidelisMod9RestApiId
ResourceId:
Value: !GetAtt ApiGatewayRestApi.RootResourceId
Export:
Name: FidelisModule9ApiResourceId