Skip to content

Instantly share code, notes, and snippets.

@benbridts
Last active October 19, 2023 08:52
Show Gist options
  • Save benbridts/b9d251fef3b341ccd0b9e5d5502640ea to your computer and use it in GitHub Desktop.
Save benbridts/b9d251fef3b341ccd0b9e5d5502640ea to your computer and use it in GitHub Desktop.
AWS Lambda Function with a generated name, using a CloudFormation-managed LogGroup
Resources:
Role:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal: {Service: lambda.amazonaws.com}
Function:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: "#todo"
Handler: "index.handler"
Role: !GetAtt Role.Arn
Runtime: "python3.8"
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${Function}"
LogPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource: !GetAtt LogGroup.Arn
PolicyName: !Sub "${Function}-logs"
Roles: [!Ref Role]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment