AWSTemplateFormatVersion: '2010-09-09'
Description: 'AWS Lambda Function'
Resources:
LambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: 'LambdaRole'
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Principal:
Service:
- 'lambda.amazonaws.com'
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: 'LambdaPolicyLogs'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: '*'
- PolicyName: 'LambdaPolicyXRay'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Action:
- 'xray:PutTraceSegments'
- 'xray:PutTelemetryRecords'
Resource: '*'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: 'LambdaFunction'
Handler: 'index.handler'
Role: !GetAtt LambdaRole.Arn
Code:
ZipFile: |
import json
def handler(event, context):
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
Runtime: 'python3.11'
Timeout: 30
MemorySize: 1024
Layers:
- 'arn:aws:lambda:us-west-2:901920570463:layer:aws-otel-python-amd64-ver-1-24-0:1'
TracingConfig:
Mode: 'Active'
Environment:
Variables:
AWS_LAMBDA_EXEC_WRAPPER: '/opt/otel-instrument'
Outputs:
LambdaFunctionArn:
Value: !GetAtt LambdaFunction.Arn
Description: 'Lambda function ARN'
Export:
Name:
Fn::Sub: '${AWS::StackName}-LambdaFunctionArn'