Skip to content

Commit aac2869

Browse files
committed
Template and workflow to create cloudformation stack
1 parent 807e9e7 commit aac2869

File tree

2 files changed

+56
-45
lines changed

2 files changed

+56
-45
lines changed

.github/workflows/workflow.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ jobs:
3232
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3333

3434
deploy-serverless-infra:
35-
# needs: build-validation-lambda-ecr
35+
needs: build-validation-lambda-ecr
3636
runs-on: ubuntu-latest
3737
env:
3838
aws-region: ca-central-1
39+
commit-sha: ${{ github.sha }}
3940
steps:
4041
- name: Checkout Repository
4142
uses: actions/checkout@v4
@@ -50,7 +51,8 @@ jobs:
5051
- name: Deploy to AWS CloudFormation
5152
uses: aws-actions/aws-cloudformation-github-deploy@v1
5253
with:
53-
name: fraud-detection-serverless
54+
name: fraud-detection
5455
template: template.yaml
55-
parameter-overrides: "Environment=dev,Region=${{ env.aws-region }}"
56+
parameter-overrides: "Environment=dev,Region=${{ env.aws-region }},ECRRepositoryTag=${{ env.commit-sha }}"
5657
capabilities: "CAPABILITY_IAM,CAPABILITY_AUTO_EXPAND"
58+
disable-rollback: true # handle it manually and rollbacks are weird

template.yaml

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,66 @@
11
AWSTemplateFormatVersion: '2010-09-09'
2-
Transform: AWS::Serverless-2016-10-31
3-
Description: AWS SAM template for serverless application with nested stacks
42

53
Parameters:
64
Environment:
75
Type: String
8-
Description: Environment on which we are working
6+
Description: deployment environment
97
Region:
108
Type: String
11-
Description: Region in which we are setting up
9+
Description: AWS region
10+
ECRRepositoryTag:
11+
Type: String
12+
Description: ECR repository URI
13+
1214

1315
Resources:
14-
KinesisStreamStack:
15-
Type: AWS::CloudFormation::Stack
16-
Properties:
17-
TemplateURL: resources/kinesis-stream-stack.yaml
18-
Parameters:
19-
Environment: !Ref Environment
20-
Region: !Ref Region
21-
22-
S3Stack:
23-
Type: AWS::CloudFormation::Stack
16+
KinesisStream:
17+
Type: AWS::Kinesis::Stream
2418
Properties:
25-
TemplateURL: resources/s3-stack.yaml
26-
Parameters:
27-
Environment: !Ref Environment
28-
Region: !Ref Region
29-
30-
LambdaStack:
31-
Type: AWS::CloudFormation::Stack
32-
Properties:
33-
TemplateURL: resources/lambda-stack.yaml
34-
Parameters:
35-
Environment: !Ref Environment
36-
Region: !Ref Region
37-
KinesisStreamArn: !GetAtt KinesisStreamStack.Outputs.KinesisStreamArn
19+
Name: !Sub "${AWS::AccountId}-kinesis-stream"
20+
ShardCount: 1
3821

39-
IAMStack:
40-
Type: AWS::CloudFormation::Stack
22+
LambdaExecutionRole:
23+
Type: AWS::IAM::Role
4124
Properties:
42-
TemplateURL: resources/iam-stack.yaml
43-
Parameters:
44-
KinesisStreamArn: !GetAtt KinesisStreamStack.Outputs.KinesisStreamArn
25+
AssumeRolePolicyDocument:
26+
Version: '2012-10-17'
27+
Statement:
28+
- Effect: Allow
29+
Principal:
30+
Service: lambda.amazonaws.com
31+
Action: sts:AssumeRole
32+
Policies:
33+
- PolicyName: execution-role-policy
34+
PolicyDocument:
35+
Version: '2012-10-17'
36+
Statement:
37+
- Effect: Allow
38+
Action:
39+
- logs:CreateLogGroup
40+
- logs:CreateLogStream
41+
- logs:PutLogEvents
42+
Resource: arn:aws:logs:*:*:*
43+
- Effect: Allow
44+
Action:
45+
- s3:PutObject
46+
Resource: !Sub "arn:aws:s3:::${Region}-${Environment}-fraud-detection-data/processed/*"
4547

46-
# Outputs:
47-
# KinesisStreamName:
48-
# Value: !GetAtt KinesisStream.Outputs.KinesisStreamName
49-
# Description: Name of the Kinesis stream
48+
LambdaFunction:
49+
Type: AWS::Lambda::Function
50+
Properties:
51+
Role: !GetAtt LambdaExecutionRole.Arn
52+
Code:
53+
ImageUri: !Sub "294331937131.dkr.ecr.ca-central-1.amazonaws.com/fraud-detection/validation-lambda:${ECRRepositoryTag}"
54+
PackageType: Image
5055

51-
# ValidationLambdaArn:
52-
# Value: !GetAtt LambdaStack.Outputs.ValidationLambdaArn
53-
# Description: ARN of the validation Lambda function
56+
LambdaPermission:
57+
Type: AWS::Lambda::Permission
58+
Properties:
59+
FunctionName: !Ref LambdaFunction
60+
Action: lambda:InvokeFunction
61+
Principal: kinesis.amazonaws.com
5462

55-
# RawDataLambdaArn:
56-
# Value: !GetAtt LambdaStack.Outputs.RawDataLambdaArn
57-
# Description: ARN of the raw data Lambda function
63+
Outputs:
64+
KinesisStreamName:
65+
Value: !Ref KinesisStream
66+
Description: Name of the Kinesis stream created

0 commit comments

Comments
 (0)