Last active
February 24, 2022 13:13
-
-
Save HenrikFricke/02d71be02b41358adb9d98a31b0fe6fb to your computer and use it in GitHub Desktop.
CloudFormation Hello World Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Resources: | |
HelloLambdaRole: | |
Type: AWS::IAM::Role | |
Properties: | |
RoleName: HelloLambdaRole | |
AssumeRolePolicyDocument: | |
Statement: | |
- Effect: Allow | |
Principal: | |
Service: lambda.amazonaws.com | |
Action: sts:AssumeRole | |
ManagedPolicyArns: | |
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole | |
HelloLambdaFunction: | |
Type: AWS::Lambda::Function | |
Properties: | |
FunctionName: HelloLambdaFunction | |
Role: !GetAtt HelloLambdaRole.Arn | |
Runtime: nodejs14.x | |
Handler: index.handler | |
Code: | |
ZipFile: | | |
exports.handler = async (event) => { | |
const response = { | |
statusCode: 200, | |
body: JSON.stringify('Hello from Lambda!'), | |
}; | |
return response; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Resources: | |
HelloLambdaRole: | |
Type: AWS::IAM::Role | |
Properties: | |
RoleName: HelloLambdaRole | |
AssumeRolePolicyDocument: | |
Statement: | |
- Effect: Allow | |
Principal: | |
Service: lambda.amazonaws.com | |
Action: sts:AssumeRole | |
ManagedPolicyArns: | |
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole | |
HelloLambdaFunction: | |
Type: AWS::Lambda::Function | |
Properties: | |
FunctionName: HelloLambdaFunction | |
Role: !GetAtt HelloLambdaRole.Arn | |
Runtime: nodejs14.x | |
Handler: index.handler | |
Code: | |
ZipFile: | | |
exports.handler = async (event) => { | |
const response = { | |
statusCode: 200, | |
body: JSON.stringify('Hello from Lambda!'), | |
}; | |
return response; | |
}; | |
HttpApi: | |
Type: AWS::ApiGatewayV2::Api | |
Properties: | |
Name: HelloWorldApi | |
ProtocolType: HTTP | |
Target: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${HelloLambdaFunction}/invocations | |
LambdaPermission: | |
Type: "AWS::Lambda::Permission" | |
Properties: | |
Action: lambda:InvokeFunction | |
FunctionName: !GetAtt HelloLambdaFunction.Arn | |
Principal: apigateway.amazonaws.com | |
SourceArn: !Sub 'arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${HttpApi}/*/$default' | |
Outputs: | |
ApiEndpoint: | |
Value: !Sub ${HttpApi.ApiEndpoint} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment