move resources to files

This commit is contained in:
0xngmi
2022-06-30 14:17:28 +01:00
parent c4b3f0d0f8
commit 7148f393e5
3 changed files with 42 additions and 40 deletions

View File

@@ -15,7 +15,7 @@ jobs:
node-version: '16'
- run: npm ci
- name: Deploy infrastructure stack
run: npm run deploy:prod
run: npm run deploy:dev
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

View File

@@ -0,0 +1,38 @@
Resources:
# DynamoDB
DynamoTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain # Make sure the tables can't be deleted by CloudFormation/Serverless
Properties:
TableName: ${self:custom.tableName}
AttributeDefinitions:
- AttributeName: PK
AttributeType: S
- AttributeName: SK
AttributeType: N
KeySchema:
- AttributeName: PK
KeyType: HASH
- AttributeName: SK
KeyType: RANGE
# Set the capacity to auto-scale
BillingMode: PAY_PER_REQUEST
# CORS for api gateway errors
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
GatewayResponseDefault5XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId:
Ref: 'ApiGatewayRestApi'

View File

@@ -10,7 +10,7 @@ provider:
memorySize: 130
region: eu-central-1
endpointType: REGIONAL # Set to regional because the api gateway will be behind a cloudfront distribution
stage: prod # Default to prod if no stage is specified
stage: dev # Default to dev if no stage is specified
tracing: # Enable X-Ray tracing (debugging)
apiGateway: true
lambda: true
@@ -147,44 +147,8 @@ functions:
handler: src/triggerFetchCoingeckoData.default
resources:
Resources:
# DynamoDB
DynamoTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain # Make sure the tables can't be deleted by CloudFormation/Serverless
Properties:
TableName: ${self:custom.tableName}
AttributeDefinitions:
- AttributeName: PK
AttributeType: S
- AttributeName: SK
AttributeType: N
KeySchema:
- AttributeName: PK
KeyType: HASH
- AttributeName: SK
KeyType: RANGE
# Set the capacity to auto-scale
BillingMode: PAY_PER_REQUEST
# CORS for api gateway errors
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
GatewayResponseDefault5XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId:
Ref: 'ApiGatewayRestApi'
# DynamoDB and api gateway errors
- ${file(resources/table-and-api.yml)}
# Cloudfront API distribution
- ${file(resources/api-cloudfront-distribution.yml)}