Reputation: 470
I have a working production environment with several Lambda deployed from my PC using AWS SAM.
I want to transition my lambda to Cloud9 and debug from there but...
Some of the functions import well and I can run the debugger while others don't even show up after importing. This leads me to believe there might be a config issue that Cloud9 doesn't like.
I'll take a fairly simple lambda called uploaddirect and this is what it looks like:
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: add docs directly from s3
Parameters:
Environment:
Type: String
Default: staging
DocumentMetadataBucketName:
Type: String
DocumentSourceBucketName:
Type: String
DocumentMetadataBucketArn:
Type: String
DocumentSourceBucketArn:
Type: String
Resources:
UploaddirectFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub leopro-uploaddirect-function-${Environment}
Handler: uploaddirect.handler
Runtime: nodejs10.x
Timeout: 300
Role: !GetAtt UploaddirectExecutionRole.Arn
Environment:
Variables:
DOCUMENT_METADATA_BUCKET: !Ref DocumentMetadataBucketName
DOCUMENT_SOURCE_BUCKET: !Ref DocumentSourceBucketName
CodeUri: .
UploaddirectExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub leopro-uploaddirect-exec-role-${Environment}
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
Policies:
-
PolicyName: !Sub leopro-uploaddirect-access-s3-${Environment}
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "s3:GetObject"
- "s3:PutObject"
Resource: 'arn:aws:s3:::*/*'
Statement:
-
Effect: "Allow"
Action:
- "s3:*"
Resource: '*'
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
Action:
- "sts:AssumeRole"
UploaddirectBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub leopro-uploaddirect-dropbox-bucket-${Environment}
NotificationConfiguration:
LambdaConfigurations:
-
Event: 's3:ObjectCreated:*'
Function: !GetAtt UploaddirectFunction.Arn
UploaddirectBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref UploaddirectBucket
PolicyDocument:
Statement:
-
Action:
- "s3:GetObject"
Effect: "Allow"
Resource: !Sub "arn:aws:s3:::leopro-uploaddirect-dropbox-bucket-${Environment}/*"
Principal: "*"
InvokeFromS3Permission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt UploaddirectFunction.Arn
Action: "lambda:InvokeFunction"
Principal: "s3.amazonaws.com"
SourceArn: !Join [ "", [ "arn:aws:s3:::", !Sub "leopro-uploaddirect-dropbox-bucket-${Environment}" ] ]
I tried plenty of things including changing the function name, redeploying, clearing my cache, restarting cloud9, deleting folders ...
Any ideas?
Upvotes: 0
Views: 247
Reputation: 470
The naming conventions of functions can be a problem when importing, specially if there are conditional parameters.
The way I solved it was to create another project with exactly same settings and code (diff compare) and changed the names of the stack, the app, the functions and the policies.
Upvotes: 1