So I have this issue that I would love to:
This is something which has to be done in YAML
I have no clue how to set this up... What I've managed to so far, is to create an s3 bucket which worked perfectly, now I just need to attach it as a trigger to the lambda function.
It's pretty easy to set up in the AWS console but I just don't have much experience with YAML. So I have no idea how to set this up correctly, and the file is really sensitive so Its a pain in the ass :-).
Wished end result with yaml:
I have built a small template , tested.
The template are to
YML version
---
AWSTemplateFormatVersion: '2010-09-09'
Description: This template is to create all resources for Config Service Api
Parameters:
LambdaArtifactBucketName:
Type: String
Default: befit-artifact
S3BucketName:
Type: String
Default: befit-test-s3
Resources:
ExampleS3:
Type: AWS::S3::Bucket
DependsOn: ExampleInvokePermission
Properties:
BucketName: !Ref S3BucketName
NotificationConfiguration:
LambdaConfigurations:
- Event: s3:ObjectCreated:Put
Filter:
S3Key:
Rules:
- Name: suffix
Value: txt
Function: !GetAtt [ ExampleLambdaFunction, Arn]
ExampleInvokePermission:
Type: AWS::Lambda::Permission
DependsOn: ExampleLambdaFunction
Properties:
FunctionName:
Fn::GetAtt:
- ExampleLambdaFunction
- Arn
Action: lambda:InvokeFunction
Principal: s3.amazonaws.com
SourceArn:
Fn::Sub: arn:aws:s3:::${S3BucketName}
ExampleLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket:
Ref: LambdaArtifactBucketName
S3Key: emailnotification-1.0.0.jar
FunctionName: example-lambda-function
Handler: com.xxx.Example::handleRequest
Role: arn:aws:iam::057351434671:role/lambda_sqs
Runtime: java8
Timeout: '300'
MemorySize: 512
Outputs:
S3BucketSecureURL:
Value: !Join ['', ['https://', !GetAtt [ExampleS3, DomainName]]]
Description: Name of S3 bucket
Json version
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "This template is to create all resources for Config Service Api",
"Parameters": {
"LambdaArtifactBucketName": {
"Type": "String",
"Default": "befit-artifact"
},
"S3BucketName": {
"Type": "String",
"Default": "befit-test-s3"
}
},
"Resources": {
"ExampleS3": {
"Type": "AWS::S3::Bucket",
"DependsOn": "ExampleInvokePermission",
"Properties": {
"BucketName": null,
"NotificationConfiguration": {
"LambdaConfigurations": [
{
"Event": "s3:ObjectCreated:Put",
"Filter": {
"S3Key": {
"Rules": [
{
"Name": "suffix",
"Value": "txt"
}
]
}
},
"Function": null
}
]
}
}
},
"ExampleInvokePermission": {
"Type": "AWS::Lambda::Permission",
"DependsOn": "ExampleLambdaFunction",
"Properties": {
"FunctionName": {
"Fn::GetAtt": [
"ExampleLambdaFunction",
"Arn"
]
},
"Action": "lambda:InvokeFunction",
"Principal": "s3.amazonaws.com",
"SourceArn": {
"Fn::Sub": "arn:aws:s3:::${S3BucketName}"
}
}
},
"ExampleLambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "LambdaArtifactBucketName"
},
"S3Key": "emailnotification-1.0.0.jar"
},
"FunctionName": "example-lambda-function",
"Handler": "com.xxx.Example::handleRequest",
"Role": "arn:aws:iam::057351434671:role/lambda_sqs",
"Runtime": "java8",
"Timeout": "300",
"MemorySize": 512
}
}
},
"Outputs": {
"S3BucketSecureURL": {
"Value": null,
"Description": "Name of S3 bucket"
}
}
}
After the template ran, the output will be
Thanks,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With