Question: # Lambda Function # TODO 6 : Create a Lambda function using the Lambda deployment package stored in S 3 . # - Set up

# Lambda Function
# TODO 6: Create a Lambda function using the Lambda deployment package stored in S3.
# - Set up the Lambda function in PrivateSubnet1 to restrict internet access. (Properties : VpcConfig -> SubnetIds)
# - Use the default Security group of the VPC.(Properties : VpcConfig -> SecurityGroupIds)
# - Attach the "LabRole" IAM role to grant necessary permissions. (Properties : Role)
# - Add environment variables: db_user, host, and password to connect to the RDS instance. (Properties : Variables)
# - Attach the Lambda Layer for MySQL packages to enable database interaction within the function. (Properties : Layers)
# - Lambda Handler is the lambda file name combined with function name. (Properties : Handler)
# - Lambda code from S3 Bucket. (Properties : Code)
# - Keep Runtime environment as python3.9.(Properties : Runtime)
Keeping the formatting below I am running into Invalid template property or properties [BooksUpdater, BooksHandler, BooksBucket, LambdaLayer, LambdaInvokePermission] this error the portion of the code is here below
# todo 6
BooksHandler:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub '${StageName}-BooksHandler'
Runtime: python3.9
Handler: lambda.lambda_handler
Role: !Sub 'arn:aws:iam::605635394551:role/LabRole'
Code:
S3Bucket: !Ref S3PackageBucket
S3Key: !Ref LambdaFunctionFileName
VpcConfig:
SubnetIds:
-!Ref PrivateSubnet1
SecurityGroupIds:
-!Ref MyRDSSecurityGroup
Environment:
Variables:
db_user: !Ref DBUserName
host: !GetAtt MyRDSInstance.Endpoint.Address
password: !Ref DBPassword
Layers:
-!Ref LambdaLayer
BooksBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub '${StageName}-${BooksBucketName}'
OwnershipControls:
Rules:
- ObjectOwnership: ObjectWriter
PublicAccessBlockConfiguration:
BlockPublicAcls: false
BlockPublicPolicy: false
IgnorePublicAcls: false
RestrictPublicBuckets: false
NotificationConfiguration:
EventBridgeConfiguration:
EventBridgeEnabled: true
BooksUpdater:
Type: AWS::Events::Rule
Properties:
Name: !Sub '${StageName}-BooksUpdater'
EventPattern:
source:
- aws.s3
detail-type:
- "Object Created"
detail:
bucket:
name:
-!Sub '${StageName}-${BooksBucketName}'
object:
key:
- suffix: ".json"
State: ENABLED
Targets:
- Arn: !GetAtt BooksHandler.Arn
Id: "BooksHandlerTarget"
LambdaInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref BooksHandler
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt BooksUpdater.Arn
LambdaLayer:
Type: AWS::Lambda::LayerVersion
Properties:
CompatibleRuntimes:
- python3.9
Content:
S3Bucket: !Ref S3PackageBucket
S3Key: !Ref LambdaLayerFileName
Description: "Layer for MySQL Packages"
LayerName: !Sub '${StageName}-My-Sql-Layer'
Outputs:
VPCId:
Description: "VPC ID"
Value: !Ref MyVPC
PublicSubnetId:
Description: "Public Subnet ID"
Value: !Ref PublicSubnet
PrivateSubnet1Id:
Description: "Private Subnet 1 ID"
Value: !Ref PrivateSubnet1
PrivateSubnet2Id:
Description: "Private Subnet 2 ID"
Value: !Ref PrivateSubnet2
RDSInstanceEndpoint:
Description: "RDS Instance Endpoint"
Value: !GetAtt MyRDSInstance.Endpoint.Address
RDSInstancePort:
Description: "RDS Instance Port"
Value: !GetAtt MyRDSInstance.Endpoint.Port
FrontEndInstancePublicIp:
Description: Public IP of the Frontend EC2 instance
Value: !GetAtt FrontEndEC2Instance.PublicIp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!