-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3-lambda-api.yaml
More file actions
74 lines (65 loc) · 2.13 KB
/
s3-lambda-api.yaml
File metadata and controls
74 lines (65 loc) · 2.13 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
---
AWSTemplateFormatVersion: "2010-09-09"
Description: Depository app using S3, Lambda, and API Gateway
Resources:
DepositoryS3Bucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: depositorybalance24
DepositoryLambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- "sts:AssumeRole"
Description: IAM Role for Lambda to access S3
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonS3FullAccess
RoleName: DepositoryLambdaExecutionRole
DepositoryLambdaFunction:
DependsOn: DepositoryLambdaExecutionRole
Type: AWS::Lambda::Function
Properties:
Runtime: nodejs16.x
Role: !GetAtt DepositoryLambdaExecutionRole.Arn
Handler: index.handler
Code:
ZipFile: |
const AWS = require("aws-sdk");
const s3 = new AWS.S3();
exports.handler = async (event) => {
// const { bucketName, objKey } = event;
const bucketName = "depositorybalance24";
const objKey = "depositoryBalance.json";
const params = {
Bucket: bucketName,
Key: objKey,
};
try {
const s3Object = await s3.getObject(params).promise();
console.log(s3Object.Body.toString());
return s3Object.Body.toString();
} catch (err) {
console.log(err);
throw err;
}
};
Description: Lambda function to read a S3 depository file
Timeout: 60
DepositoryRESTAPI:
Type: AWS::ApiGateway::RestApi
Properties:
Name: DepositoryStatusAPI
Description: Depository Status API
DepositoryStatusResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt DepositoryRESTAPI.RootResourceId
PathPart: depository-status
RestApiId: !Ref DepositoryRESTAPI