Skip to content

Instantly share code, notes, and snippets.

@antoinedelia
Last active August 26, 2022 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoinedelia/8653ce46b89dce666249871613471210 to your computer and use it in GitHub Desktop.
Save antoinedelia/8653ce46b89dce666249871613471210 to your computer and use it in GitHub Desktop.
Template for a basic serverless file
service: service-name
provider:
name: aws
stage: ${opt:stage, 'prod'}
runtime: ${opt:runtime, 'python3.8'}
region: ${opt:region, 'eu-west-1'}
deploymentBucket:
name: deployment_bucket_name
iamRoleStatements:
- Effect: 'Allow'
Action: '*'
Resource: '*'
- Effect: "Allow"
Action:
- "s3:GetObject"
- "s3:GetObjectVersion"
Resource:
- "arn:aws:s3:::${file(env.yml):${self:provider.stage}.netbox_data_bucket_name}/*"
- "arn:aws:s3:::${file(env.yml):${self:provider.stage}.infoblox_data_bucket_name}/${file(env.yml):${self:provider.stage}.infoblox_data_bucket_key}"
- Effect: "Allow"
Action:
- "ssm:GetParameter"
Resource:
- "arn:aws:ssm:#{AWS::Region}:#{AWS::AccountId}:parameter${file(env.yml):${self:provider.stage}.vault_token_path}"
- Effect: "Allow"
Action: "kms:Decrypt"
Resource: "arn:aws:kms:#{AWS::Region}:#{AWS::AccountId}:key/*"
environment:
LOG_LEVEL: ${file(env.yml):${self:provider.stage}.log_level}
custom:
variable_name: variable_value
package:
individually: true
excludeDevDependencies: false
exclude:
- node_modules/**
- serverless_deployment/**
- assets/**
- tests/**
functions:
lambda_function:
handler: src/lambda_function.lambda_handler
name: ${self:service.name}-${self:provider.stage}-lambda_function
description: This does something
timeout: 900
environment:
env_var_name: ${self:custom.variable_name}
stepFunctions:
stateMachines:
NetboxExportStateMachine:
name: ${file(env.yml):${self:provider.stage}.state_machine_name}
events:
- schedule: cron(0 9 ? * SAT *)
definition:
Comment: "Netbox export"
StartAt: InitState
States:
InitState:
Type: Parallel
Branches:
- StartAt: NetboxExport
States:
NetboxExport:
Type: Task
Resource:
Fn::GetAtt: [export, Arn]
End: True
Catch:
- ErrorEquals: ["States.ALL"]
Next: NotifyFailure
Next: Success
Success:
Type: Succeed
NotifyFailure:
Type: Task
Parameters:
State: Failure
Input.$: $
Resource:
Fn::GetAtt: [pager, Arn]
Next: Failure
Failure:
Type: Fail
plugins:
- serverless-step-functions
- serverless-pseudo-parameters
- serverless-python-requirements
resources:
Outputs:
NetboxExportStateMachine:
Description: The ARN of the Netbox Export state machine
Value:
Ref: NetboxExportStateMachine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment