Create AWS::Pinpoint::PushTemplate using CF template - aws-lambda

Hi I want to create AWS::Pinpoint::PushTemplate using cloudformation template and I am following this link: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-pinpoint-pushtemplate.html.
Type: AWS::Pinpoint::PushTemplate
Properties:
Default:
Action: OPEN_APP
Body: FirstName - {{firstName}}, LastName - {{lastName}}
Title: Title
DefaultSubstitutions:
firstName: default
lastName: default
Tags:
project: project
tashi: "Pinpoint Template"
TemplateName: template_name
I am getting type validation error for`DefaultSubstitutions: Property validation failure: [Value of property {/DefaultSubstitutions} does not match type {String}]

According to docs DefaultSubstitutions is a String.
However, in your case, you set it up as map:
DefaultSubstitutions:
firstName: default
lastName: default
Maybe have to try using it as json string:
DefaultSubstitutions: "{\"firstName"\:\"default\", \"lastName"\:\"default\"}"

Related

Problem with setting default argument in Typo3 routeEnhancer

I have a Typo3 page that works with two URL parameters, "manuscript" and "type" (e.g. localhost/my-page?manuscript=samplemanuscript&type=description). "manuscript" is a mandatory parameter, while "type" is optional.
I use Route Enhancers to get rid of cHash in the URL. So I have created a yaml file to configure it.
This configuration works fine without "defaults" section with both parameters in place, but when I add the defaults section to make "type" parameter optional, the URL localhost/my-page/samplemanuscript works fine, but localhost/my-page/samplemanuscript/description shows me the 404 error. Any ideas what's wrong with it?
I use Typo3 v10.4
routeEnhancers:
ManuscriptHierarchy:
type: Simple
limitToPages: [13]
routePath: '/{manuscript}/{type}'
defaults:
type: ''
aspects:
manuscript:
type: StaticValueMapper
map:
samplemanuscript: samplemanuscript
samplemanuscript2: samplemanuscript2
type:
type: StaticValueMapper
map:
transcription: transcription
description: description
P.S.
For debugging purposes, is there any appropriate way to check the final resolved URL (when I visit localhost/my-page/samplemanuscript/description)?
The solution looks strange to me but it works by adding requirements:
routeEnhancers:
ManuscriptHierarchy:
type: Simple
limitToPages: [13]
routePath: '/{manuscript}/{type}'
defaults:
type: ''
requirements:
manuscript: '^(?:samplemanuscript|samplemanuscript2)$'
type: '^(?:description|transcription)$'
aspects:
manuscript:
type: StaticValueMapper
map:
samplemanuscript: samplemanuscript
samplemanuscript2: samplemanuscript2
type:
type: StaticValueMapper
map:
transcription: transcription
description: description

#AO\JsonContent in parameter of get request

In swagger's documentation using OpenApi specification, you can wrap schema in parameter to content with application/json:
parameters:
- in: query
name: filter
# Wrap 'schema' into 'content.<media-type>'
content:
application/json: # <---- media type indicates how to serialize / deserialize the parameter content
schema:
type: object
properties:
type:
type: string
color:
type: string
to send objects like this filter={"type":"t-shirt","color":"blue"}.
How to do it in swagger-php?
The swagger-editor and swagger-ui have added support for http://swagger.io/docs/specification/describing-parameters
The swagger-php library has added support too, it will be part of the 3.0.4 release.

How to Define Enum as Query Params in OpenAPI Spec

I want to define an enum value in the query string parameter of a function in an OpenAPI specification.
Here is an example of how I specify the parameter in my OpenAPI specification (yaml):
openapi: 3.0.0
info:
description: Vends sodas
version: 1.0.0
title: VendingMachineService
paths:
/soda/{bill}:
get:
summary: Provides a soda for a provided amount of money
description: Provides a soda for a provided amount of money
operationId: getSoda
parameters:
- name: bill
in: path
description: Money (e.g. one, two, five)
required: true
schema:
$ref: "#/components/schemas/Bill"
responses:
"200":
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/Result"
"404":
description: Templates for Source not found
servers:
- url: http://localhost:8080/
components:
schemas:
Bill:
type: string
enum:
- one
- two
- five
Result:
type: string
The key part of the OpenAPI spec is that I define the enum in a schema object at the bottom, type string, and refer to it in the parameters section of the function, also defining it as part of the path /{bill}
I then use openapi-generator to generate the spring server:
openapi-generator generate -i ~/vending-machine.yaml -g spring -o ~/output
I then spin up the server (importing the project into Intellij and running in a spring-boot configuration) and go to localhost:8080/ to open the Swagger UI. I try to exercise the api and get the following error:
{ "timestamp": "2019-03-29T15:43:14.737Z", "status": 400,
"error": "Bad Request", "message": "Failed to convert value of type
'java.lang.String' to required type 'org.openapitools.model.Bill';
nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to
convert from type [java.lang.String] to type
[#javax.validation.constraints.NotNull
#io.swagger.annotations.ApiParam #javax.validation.Valid
#org.springframework.web.bind.annotation.RequestParam
org.openapitools.model.Bill] for value 'null'; nested exception is
java.lang.IllegalArgumentException: No enum constant
org.openapitools.model.Bill.null", "path": "/soda/%7Bbill%7D" }
(501 Not Implemented expected)
What is the proper way to define the query params & enum in the OpenAPI spec to use enum values?

CloudFormation Transform::Include parameters

I want to use AWS macro Transform::Include with some dynamic parameters for my file.
Resources:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
TestMacroVariable:
Default: 2
Type: Number
Location: !Sub "s3://${InstallBucketName}/test.yaml"
test.yaml:
DataAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
LaunchConfigurationName:
Ref: DataLaunchConfiguration
MinSize: '1'
MaxSize: '100'
DesiredCapacity:
Ref: TestMacroVariable
...
After calling: aws cloudformation describe-stack-events --stack-name $stack
I get:
"ResourceStatusReason": "The value of parameter TestMacroVariable
under transform Include must resolve to a string, number, boolean or a
list of any of these.. Rollback requested by user."
When I try to do it this way:
Resources:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
TestMacroVariable: 2
Location: !Sub "s3://${InstallBucketName}/test.yaml"
I get:
"ResourceStatusReason": "Template format error: Unresolved resource
dependencies [TestMacroVariable] in the Resources block of the
template"
Error is the same when I don't provide TestMacroVariable at all.
Tried with different types: String, Number, Boolean, List - none of them work.
As i know you cannot have anything other than Location key in the Parameters section of the AWS::Include. Check here AWS DOC
As an alternative, you can pass in the whole S3 path as a parameter and reference it in Location:
Parameters:
MyS3Path:
Type: String
Default: 's3://my-cf-templates/my-include.yaml'
...
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location: !Ref MyS3Path
Building on what #BatteryAcid Said you can refer the parameters in your Cloudformation template directly from your file using Sub function:
In your CF template :
Parameters:
TableName:
Type: String
Description: Table Name of the Dynamo DB Users table
Default: 'Users'
In the file you are including:
"Resource": [
{
"Fn::Sub": [
"arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}",
{
"tableName": {
"Ref": "TableName"
}
}
]
}
Alternatively doesn't have to be a parameter but any resource from your template :
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${QueryTelemtryFunction.Arn}/invocations

How to reuse example from another definition in swagger?

I have a definition of a report object. I have another definition of reports object that has an array of report objects (via a $ref).
In the report definition, I have an example defined, which works fine in swagger UI.
In the reports definition, I want it to use the example from the report definition.
How can I do this? I've tried several things using $ref, the closest I got was what I have in the following YAML...
definitions:
report:
type: object
properties:
ID:
type: number
format: int
description: "DB record ID of the report."
readOnly: true
ErrorContent:
type: string
description: "The actual problem or error infomation for this report. This can be exception stack, etc."
readOnly: true
UserComments:
type: string
description: "Any user comments collected by the app and submitted with the report."
readOnly: true
ReportedBy:
type: string
description: "The person using the app when it triggered the error this report is for."
readOnly: true
ReportedDateTime:
type: string
description: "The date/time the report was submitted."
readOnly: true
required:
- ID
- ErrorContent
- ErrorType
- UserComments
- ReportedBy
- ReportedDateTime
example:
ID: 11367
ErrorContent: "Operation is not valid due to the current state of the object."
ErrorType: "Exception"
UserComments: "Was clicking this and that and then Boom!"
ReportedBy: "domain\\name"
ReportedDateTime: "2016-01-19 14:07:00"
reports:
properties:
message:
type: string
reports:
type: array
items:
$ref: '#/definitions/report'
example:
message: "success"
reports:
- $ref: '#/definitions/report'
However, in Swagger UI, the above results in...
{
"message": "success",
"reports": [
{
"$ref": "#/definitions/report"
}
]
}
One interesting note, in Swagger UI, when I look at the model view, it does have all of report even with descriptions.
This behavior is correct--the examples section cannot be referenced with a JSON pointer. See the OAI Specification for what is currently supported.
If you feel this is a common use case, please open an issue on the spec repository.

Resources