-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
129 lines (106 loc) · 3.41 KB
/
template.yaml
File metadata and controls
129 lines (106 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
AWSTemplateFormatVersion: "2010-09-09"
Description:
this is a banking application built using AWS Lambda function, API Gateway and S3 bucket
Resources:
BankingSystemS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: surya-banking-s3-bucket
# https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html
IAMrole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Description: This is the IAMrole for lambda function
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonS3FullAccess
RoleName: Allow-S3-Role
LambdaFunction:
DependsOn:
- IAMrole
Type: AWS::Lambda::Function
Properties:
Architectures:
- x86_64
Code:
ZipFile: |
import json
import boto3
client = boto3.client("s3")
def lambda_handler(event, context):
response = client.get_object(
Bucket="surya-banking-s3-bucket",
Key="sample.json"
)
#convert from streaming data to byte
data_byte = response['Body'].read()
# convert from bytes to strings
data_string = data_byte.decode("UTF-8")
# convert from json string to dictionary
data_dict = json.loads(data_string)
return {
'statusCode': 200,
# 'body': data_dict
'body': json.dumps(data_dict),
'headers': {'Content-Type': 'application/json'},
}
Description: This is the Lambada funtion
Handler: index.lambda_handler
Role: !GetAtt IAMrole.Arn
Runtime: python3.12
Timeout: 30
bankingRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: Banking System API
bankingStatusResource:
Type: 'AWS::ApiGateway::Resource'
DependsOn:
- bankingRestApi
Properties:
RestApiId: !Ref bankingRestApi
ParentId: !GetAtt bankingRestApi.RootResourceId
PathPart: bankingStatusResource
getBankingStatusMethod:
Type: 'AWS::ApiGateway::Method'
DependsOn:
- bankingStatusResource
Properties:
RestApiId: !Ref bankingRestApi
ResourceId: !GetAtt bankingRestApi.RootResourceId
HttpMethod: GET
MethodResponses:
- StatusCode: '200'
AuthorizationType: NONE
Integration:
Type: AWS
IntegrationResponses:
- StatusCode: '200'
IntegrationHttpMethod: POST
Uri: !Sub
- arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations
- lambdaArn: !GetAtt LambdaFunction.Arn
bankingAPIDeployment:
Type: 'AWS::ApiGateway::Deployment'
DependsOn:
- getBankingStatusMethod
Properties:
RestApiId: !Ref bankingRestApi
Description: Banking system API deployment
StageName: Dev
lambdaFunctionInvokePermisson:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref LambdaFunction
Action: lambda:InvokeFunction
Principal: 'apigateway.amazonaws.com'
SourceAccount: "107520159244"