Add multiple parameters to path parameters AWS SAM - amazon-web-services

I have a dynamodb table that has a primary key of CompanyName and sort Key of CognitoUserID. I have a REST API and created an update method to update a user in my table. The issue I am having is that in my Yaml template I need to provide both the primary and sort key for my path parameters but I am only able to provide one. The code below is of my YAML template
Type: AWS::Serverless::Function
Properties:
CodeUri: cloudPortalFunctions/
Handler: app.updateUserProfile
Layers:
- !Ref updateUserProfileDepLayer
Runtime: nodejs14.x
Architectures:
- x86_64
Events:
updateUserProfile:
Type: Api
Properties:
Path: /updateUserProfile/{cognitoUserID}
Method: PUT
This is my update method in my YAML file
I would like to be able to add CompanyName to the path. Maybe to look like this
Path: /updateUserProfile/{companyName}{cognitoUserID}
I have tried this How can i use multiple path parameters from serverless framework but none of it is accepted in my vs code and the AWS documentation does not help either
Is there a way to do this?

I just needed to delete the stack and deploy it from scratch

Related

AWS-Lambda: Unable to add another event, unhelpful GenerateChangeSet failure message

I am trying to add another path to AWS Lambda that has been generated by code star.
I have tried to add the following events (in different commits) with the same failure behavior.
HelloWorld:
Type: AWS::Serverless::Function
Properties:
Events:
API:
Type:
Properties:
Path: /{proxy+}
Method: ANY
HelloWorld:
Type: AWS::Serverless::Function
Properties:
Events:
Decks_GetEvent:
Type: Api
Properties:
Path: /decks
Method: get
GenerateChangeSet step in code pipeline fails with the following unhelpful message:
Action execution failed
Failed to create change set. Current status: FAILED
When going to 'Details' Link of GenerateChangeSet step. It just takes me to Stack view without any particular stack or execution event selected.
What are the steps to troubleshoot this? Any suggestions on what could be causing this?
If it doesn't want to create a changeset, you presumably have a syntax error in your document. However, since you've not shared the CloudFormation template, that is hard to determine.
If you want to troubleshoot this, you can try to manually create a change set (that might provide more error information), or you can use cfn-lint to do some static code analysis on your CloudFormation template.

AWS Lambda Rest API: A sibling ({id}) of this resource already has a variable path part -- only one is allowed Unable to create resource at path

I'm particular new to Lambda and to AWS in general. I'm trying to setup a simple REST API Service with Lambda. I've used CloudFormat and CodePipeline to have a simple Express app.
I'm trying to figure out why during the deployment phase, during ExecuteChangeSet I have this error:
Errors found during import: Unable to create resource at path '/stations/{stationId}/allowedUsers': A sibling ({id}) of this resource already has a variable path part -- only one is allowed Unable to create resource at path '/stations/{stationId}/allowedUsers/{userId}': A sibling ({id}) of this resource already has a variable path part -- only one is allowed
This is what I have inside the template.yml
Events:
AllowedUsers:
Type: Api
Properties:
Path: /stations/{stationId}/allowedUsers
Method: get
AddAllowedUsers:
Type: Api
Properties:
Path: /stations/{stationId}/allowedUsers
Method: post
DeleteAllowedUsers:
Type: Api
Properties:
Path: /stations/{stationId}/allowedUsers/{userId}
Method: delete
GetAllowedUser:
Type: Api
Properties:
Path: /stations/{stationId}/allowedUsers/{userId}
Method: get
I searched a bit for this error but I'm not sure how to solve it.
For me, the issue was different from what is described in the GitHub issue Bryan mentioned.
I was using two different parameter names. Finishing the refactoring and using a single id name fixed the issue.
Example:
DeleteAllowedUsers:
Type: Api
Properties:
Path: /stations/{stationId}/allowedUsers/{id}
Method: delete
GetAllowedUser:
Type: Api
Properties:
Path: /stations/{stationId}/allowedUsers/{userId}
Method: get
Here is the walk around for this problem. It was posted on github by pettyalex.
link :https://github.com/serverless/serverless/issues/3785
You might encounter this issue when updating a variable path while using serverless ( and serverless.yaml ) to provision the AWS gatewayApi, here is a walk-around:
comment out the endpoint function to remove it completely
uncomment and deploy again

AWS Serverless Error for Provider variables - Trying to populate non string value into a string for variable

I am using Serverless framework.
I have created Cognito user pool in one stack and importing it into second stack.
When I assign the value of the Cognito User pool ID created in the first stack, to the environment variable it works.
But when I try to use it while creating a ARN for Cognito Authorizer, it doesn't work.
I get an error - Trying to populate non string value into a string for variable
Here is the snippet of my serverless.yml file.
service: myservice
plugins:
- serverless-pseudo-parameters
provider:
name: aws
runtime: go1.x
stage: dev
region: us-east-1
cognitoUserPoolId :
Fn::ImportValue: cloudformation-resources-${self:provider.stage}-CognitoUserPool
cognitoAppClientId :
Fn::ImportValue: cloudformation-resources-${self:provider.stage}-CognitoUserPoolClient
custom:
environment:
COGNITO_USER_POOL_ID : ${self:provider.cognitoUserPoolId}
COGNITO_APP_CLIENT_ID: ${self:provider.cognitoAppClientId}
functions:
myfunction:
handler: bin/handlers/myfunction
package:
exclude:
- "**/**"
include:
- ./bin/handlers/myfunction
events:
- http:
path: mypath
method: put
authorizer:
name: cognitoapiauthorizer
arn: arn:aws:cognito-idp:#{AWS::Region}:#{AWS::AccountId}:userpool/${self:provider.cognitoUserPoolId}
cors: true
Any issues related to indentation or the way it is being used in another variable like ARN?
I see you're trying to resolve the error Trying to populate non string value into a string for variable. In my experience, this means that the variable is empty. What happens if you hardcode the cognitoUserPoolId at the end of the ARN? Is the error resolved? I suspect it would be. Moving forward from there, you should take a closer look at how you declare that variable. Your usage of Fn::ImportValue may not working as intended.
Also, I would definitely run your YAML through a validator. There are too many extra blank lines, and extra spaces before the colons e.g. COGNITO_USER_POOL_ID : ${self:provider.cognitoUserPoolId}. These may be causing problems. Keep your YAML formatting tidy.

Use private ips in google dataflow job being created via google provided template

I'm trying to set up a dataflow job via deployment manager using the google provided template Cloud_PubSub_to_Avro.
To do this I had to register dataflow as a type provider, like this:
resources:
- name: 'register-dataflow'
action: 'gcp-types/deploymentmanager-v2beta:deploymentmanager.typeProviders.insert'
properties:
name: 'dataflow'
descriptorUrl: 'https://dataflow.googleapis.com/$discovery/rest?version=v1b3'
options:
inputMappings:
- fieldName: Authorization
location: HEADER
value: >
$.concat("Bearer ", $.googleOauth2AccessToken())
Then I created my job template that looks something like
resources:
- name: "my-topic-to-avro"
type: 'my-project-id/dataflow:dataflow.projects.locations.templates.launch'
properties:
projectId: my-project-id
gcsPath: "gs://dataflow-templates/latest/Cloud_PubSub_to_Avro"
jobName: "my-topic-to-avro"
location: "europe-west1"
parameters:
inputTopic: "projects/my-project-id/topics/my-topic"
outputDirectory: "gs://my-bucket/avro/my-topic/"
avroTempDirectory: "gs://my-bucket/avro/tmp/my-topic/"
Now I'm trying to understand how I can tell my job to not use public ips. From this it looks like I need to set --usePublicIps=false but I can't figure out where to place this parameter, or if this is even possible.
A possible workaround I found here would be to remove the access-config, but again I haven't been able to figure out how to do this, if at all possible.
Is what I'm trying to do possible through provided templates or will I have to use the dataflow API?
Any help appreciated.

Adding parameters to aws lambda events using templates

How do I add a (path) parameter to lambda function events using cloud formation templates?
Strangely using:
DeleteItem:
Type: Api
Properties:
Path: /item/{id}
Method: delete
Request:
Parameters:
Paths:
id: true
works using aws-sam-cli. However when I try to deploy using cloud formation it says that property Request is not defined. I got this request idea from the serverless docs but seems to only work locally. I can't find documentation on how to do this in templates so any help would be greatly appreciated.
The Serverless Framework uses its own syntax, which is different from SAM (although can be compiled down to SAM or raw CloudFormation).
You can find the SAM specification here.
It's not explicit, but all you need to do is use the {path-name} syntax. Adding Request/Parameters is not required (or supported).
For example:
Ratings:
Type: AWS::Serverless::Function
Properties:
Handler: ratings.handler
Runtime: python3.6
Events:
Api:
Type: Api
Properties:
Path: /ratings/{id}
Method: get
Would give you the an event with:
event.pathParameters.id == 'whatever-was-put-in-the-id-position'
(A long example can be found here: https://github.com/1Strategy/redirect/blob/master/redirect.yaml)